2007-06-15 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Fri, 15 Jun 2007 19:28:36 +0000 (19:28 +0000)
committerHavoc Pennington <hp@redhat.com>
Fri, 15 Jun 2007 19:28:36 +0000 (19:28 +0000)
* dbus/dbus-sysdeps.c (_dbus_set_errno_to_zero)
(_dbus_get_is_errno_nonzero, _dbus_get_is_errno_eintr)
(_dbus_strerror_from_errno): family of functions to abstract
errno, though these are somewhat bogus (really we should make our
socket wrappers not use errno probably - the issue is that any
usage of errno that isn't socket-related probably is not
cross-platform, so should either be in a unix-only file that can
use errno directly, or is a bug - these general errno wrappers
hide issues of this nature in non-socket code, while
socket-specific API changes would not since sockets are allowed
cross-platform)

14 files changed:
ChangeLog
bus/activation.c
bus/config-loader-libxml.c
bus/dir-watch-dnotify.c
bus/dir-watch-kqueue.c
bus/main.c
bus/selinux.c
dbus/dbus-server-socket.c
dbus/dbus-spawn.c
dbus/dbus-sysdeps-pthread.c
dbus/dbus-sysdeps-unix.c
dbus/dbus-sysdeps.c
dbus/dbus-sysdeps.h
dbus/dbus-transport-socket.c

index 44b539f..d80ed40 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-06-15  Havoc Pennington  <hp@redhat.com>
+
+       * dbus/dbus-sysdeps.c (_dbus_set_errno_to_zero)
+       (_dbus_get_is_errno_nonzero, _dbus_get_is_errno_eintr)
+       (_dbus_strerror_from_errno): family of functions to abstract
+       errno, though these are somewhat bogus (really we should make our
+       socket wrappers not use errno probably - the issue is that any
+       usage of errno that isn't socket-related probably is not
+       cross-platform, so should either be in a unix-only file that can
+       use errno directly, or is a bug - these general errno wrappers
+       hide issues of this nature in non-socket code, while
+       socket-specific API changes would not since sockets are allowed
+       cross-platform)
+
 2007-06-14  Havoc Pennington  <hp@redhat.com>
 
        * bus/dispatch.c (check_get_connection_unix_process_id): mop up
index 2e9dadb..2d463c3 100644 (file)
@@ -34,7 +34,9 @@
 #include <dbus/dbus-spawn.h>
 #include <dbus/dbus-timeout.h>
 #include <dbus/dbus-sysdeps.h>
+#ifdef HAVE_ERRNO_H
 #include <errno.h>
+#endif
 
 #define DBUS_SERVICE_SECTION "D-BUS Service"
 #define DBUS_SERVICE_NAME "Name"
index d9892d1..3aa472b 100644 (file)
@@ -27,7 +27,9 @@
 #include <libxml/parser.h>
 #include <libxml/globals.h>
 #include <libxml/xmlmemory.h>
+#ifdef HAVE_ERRNO_H
 #include <errno.h>
+#endif
 #include <string.h>
 
 /* About the error handling: 
index 988ef38..72d2ad4 100644 (file)
@@ -27,6 +27,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
 
 #include <dbus/dbus-internals.h>
 #include "dir-watch.h"
index 52f0010..171b7a8 100644 (file)
 #include <signal.h>
 #include <fcntl.h>
 #include <unistd.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
 #include "bus.h"
 #include <dbus/dbus-watch.h>
 
index 421bd8b..f33ac2a 100644 (file)
 #include "driver.h"
 #include <dbus/dbus-internals.h>
 #include <dbus/dbus-watch.h>
-#ifdef DBUS_WIN
-#include <dbus/dbus-sysdeps-win.h>
-#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
+#ifdef HAVE_ERRNO_H
 #include <errno.h>
+#endif
 #include "selinux.h"
 
 static BusContext *context;
index a37e367..34fc3cc 100644 (file)
@@ -31,7 +31,9 @@
 #ifdef HAVE_SELINUX
 #include <sys/types.h>
 #include <unistd.h>
+#ifdef HAVE_ERRNO_H
 #include <errno.h>
+#endif
 #include <pthread.h>
 #include <syslog.h>
 #include <selinux/selinux.h>
index e6fd7d5..3897f0d 100644 (file)
@@ -169,11 +169,11 @@ socket_handle_watch (DBusWatch    *watch,
         {
           /* EINTR handled for us */
           
-          if (errno == EAGAIN || errno == EWOULDBLOCK)
+          if (_dbus_get_is_errno_eagain_or_ewouldblock ())
             _dbus_verbose ("No client available to accept after all\n");
           else
             _dbus_verbose ("Failed to accept a client connection: %s\n",
-                           _dbus_strerror (errno));
+                           _dbus_strerror_from_errno ());
 
           SERVER_UNLOCK (server);
         }
index c3be333..7435818 100644 (file)
 #include <fcntl.h>
 #include <signal.h>
 #include <sys/wait.h>
-#include <errno.h>
 #include <stdlib.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
 
 /**
  * @addtogroup DBusInternalsUtils
index 55d3ea2..36bfd7e 100644 (file)
 #include <pthread.h>
 #include <string.h>
 
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
 typedef struct {
   pthread_mutex_t lock; /**< lock protecting count field */
   volatile int count;   /**< count of how many times lock holder has recursively locked */
index 6ba3da0..1e4cf8d 100644 (file)
@@ -32,6 +32,7 @@
 #include "dbus-userdb.h"
 #include "dbus-list.h"
 #include "dbus-credentials.h"
+
 #include <sys/types.h>
 #include <stdlib.h>
 #include <string.h>
@@ -2327,7 +2328,8 @@ _dbus_exit (int code)
 
 /**
  * A wrapper around strerror() because some platforms
- * may be lame and not have strerror().
+ * may be lame and not have strerror(). Also, never
+ * returns NULL.
  *
  * @param error_number errno.
  * @returns error description.
@@ -2993,4 +2995,17 @@ _dbus_append_keyring_directory_for_credentials (DBusString      *directory,
   return FALSE;
 }
 
+
+/**
+ * See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently
+ * for Winsock so is abstracted)
+ *
+ * @returns #TRUE if errno == EAGAIN or errno == EWOULDBLOCK
+ */
+dbus_bool_t
+_dbus_get_is_errno_eagain_or_ewouldblock (void)
+{
+  return errno == EAGAIN || errno == EWOULDBLOCK;
+}
+
 /* tests in dbus-sysdeps-util.c */
index 7f77960..c310b28 100644 (file)
@@ -967,6 +967,55 @@ _dbus_error_from_errno (int error_number)
   return DBUS_ERROR_FAILED;
 }
 
+/**
+ * Assign 0 to the global errno variable
+ */
+void
+_dbus_set_errno_to_zero (void)
+{
+  errno = 0;
+}
+
+/**
+ * See if errno is set
+ * @returns #TRUE if errno is not 0
+ */
+dbus_bool_t
+_dbus_get_is_errno_nonzero (void)
+{
+  return errno != 0;
+}
+
+/**
+ * See if errno is ENOMEM
+ * @returns #TRUE if errno == ENOMEM
+ */
+dbus_bool_t
+_dbus_get_is_errno_enomem (void)
+{
+  return errno == ENOMEM;
+}
+
+/**
+ * See if errno is EINTR
+ * @returns #TRUE if errno == EINTR
+ */
+dbus_bool_t
+_dbus_get_is_errno_eintr (void)
+{
+  return errno == EINTR;
+}
+
+/**
+ * Get error message from errno
+ * @returns _dbus_strerror(errno)
+ */
+const char*
+_dbus_strerror_from_errno (void)
+{
+  return _dbus_strerror (errno);
+}
+
 /** @} end of sysdeps */
 
 /* tests in dbus-sysdeps-util.c */
index 3e2b8ce..49524e3 100644 (file)
  * stuff straight out of string.h, so have this here for now.
  */
 #include <string.h>
-
-/* and it would just be annoying to abstract this */
-#include <errno.h>
-
 #include <stdarg.h>
 
 DBUS_BEGIN_DECLS
@@ -315,6 +311,13 @@ dbus_bool_t _dbus_generate_random_ascii        (DBusString *str,
 
 const char* _dbus_error_from_errno (int error_number);
 
+void        _dbus_set_errno_to_zero                  (void);
+dbus_bool_t _dbus_get_is_errno_nonzero               (void);
+dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (void);
+dbus_bool_t _dbus_get_is_errno_enomem                (void);
+dbus_bool_t _dbus_get_is_errno_eintr                 (void);
+const char* _dbus_strerror_from_errno                (void);
+
 void _dbus_disable_sigpipe (void);
 
 
index 3f8c94d..31a41e1 100644 (file)
@@ -267,17 +267,16 @@ read_data_into_auth (DBusTransport *transport,
     {
       /* EINTR already handled for us */
 
-      if (errno == ENOMEM)
+      if (_dbus_get_is_errno_enomem ())
         {
           *oom = TRUE;
         }
-      else if (errno == EAGAIN ||
-               errno == EWOULDBLOCK)
+      else if (_dbus_get_is_errno_eagain_or_ewouldblock ())
         ; /* do nothing, just return FALSE below */
       else
         {
           _dbus_verbose ("Error reading from remote app: %s\n",
-                         _dbus_strerror (errno));
+                         _dbus_strerror_from_errno ());
           do_io_error (transport);
         }
 
@@ -319,13 +318,12 @@ write_data_from_auth (DBusTransport *transport)
     {
       /* EINTR already handled for us */
       
-      if (errno == EAGAIN ||
-          errno == EWOULDBLOCK)
+      if (_dbus_get_is_errno_eagain_or_ewouldblock ())
         ;
       else
         {
           _dbus_verbose ("Error writing to remote app: %s\n",
-                         _dbus_strerror (errno));
+                         _dbus_strerror_from_errno ());
           do_io_error (transport);
         }
     }
@@ -613,13 +611,12 @@ do_writing (DBusTransport *transport)
         {
           /* EINTR already handled for us */
           
-          if (errno == EAGAIN ||
-              errno == EWOULDBLOCK)
+          if (_dbus_get_is_errno_eagain_or_ewouldblock ())
             goto out;
           else
             {
               _dbus_verbose ("Error writing to remote app: %s\n",
-                             _dbus_strerror (errno));
+                             _dbus_strerror_from_errno ());
               do_io_error (transport);
               goto out;
             }
@@ -749,19 +746,18 @@ do_reading (DBusTransport *transport)
     {
       /* EINTR already handled for us */
 
-      if (errno == ENOMEM)
+      if (_dbus_get_is_errno_enomem ())
         {
           _dbus_verbose ("Out of memory in read()/do_reading()\n");
           oom = TRUE;
           goto out;
         }
-      else if (errno == EAGAIN ||
-               errno == EWOULDBLOCK)
+      else if (_dbus_get_is_errno_eagain_or_ewouldblock ())
         goto out;
       else
         {
           _dbus_verbose ("Error reading from remote app: %s\n",
-                         _dbus_strerror (errno));
+                         _dbus_strerror_from_errno ());
           do_io_error (transport);
           goto out;
         }
@@ -1038,7 +1034,7 @@ socket_do_iteration (DBusTransport *transport,
     again:
       poll_res = _dbus_poll (&poll_fd, 1, poll_timeout);
 
-      if (poll_res < 0 && errno == EINTR)
+      if (poll_res < 0 && _dbus_get_is_errno_eintr ())
        goto again;
 
       if (flags & DBUS_ITERATION_BLOCK)
@@ -1081,7 +1077,7 @@ socket_do_iteration (DBusTransport *transport,
       else
         {
           _dbus_verbose ("Error from _dbus_poll(): %s\n",
-                         _dbus_strerror (errno));
+                         _dbus_strerror_from_errno ());
         }
     }