+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
#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"
#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:
#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"
#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>
#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;
#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>
{
/* 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);
}
#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
#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 */
#include "dbus-userdb.h"
#include "dbus-list.h"
#include "dbus-credentials.h"
+
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
/**
* 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.
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 */
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 */
* 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
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);
{
/* 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);
}
{
/* 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);
}
}
{
/* 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;
}
{
/* 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;
}
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)
else
{
_dbus_verbose ("Error from _dbus_poll(): %s\n",
- _dbus_strerror (errno));
+ _dbus_strerror_from_errno ());
}
}