diff options
author | Havoc Pennington <hp@redhat.com> | 2007-06-15 19:28:36 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2007-06-15 19:28:36 +0000 |
commit | 43b944a0a6ea48e8a8b06ae3e638299f591cde8d (patch) | |
tree | 0b7dc627144289e0a7cbb08546e1aee9fc07cdf3 /dbus | |
parent | 283b1c6fc775c15773ebdddd423f79ad1612233d (diff) |
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)
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-server-socket.c | 4 | ||||
-rw-r--r-- | dbus/dbus-spawn.c | 4 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-pthread.c | 4 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 17 | ||||
-rw-r--r-- | dbus/dbus-sysdeps.c | 49 | ||||
-rw-r--r-- | dbus/dbus-sysdeps.h | 11 | ||||
-rw-r--r-- | dbus/dbus-transport-socket.c | 28 |
7 files changed, 93 insertions, 24 deletions
diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index e6fd7d58..3897f0db 100644 --- a/dbus/dbus-server-socket.c +++ b/dbus/dbus-server-socket.c @@ -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); } diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index c3be333c..74358185 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -31,8 +31,10 @@ #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 diff --git a/dbus/dbus-sysdeps-pthread.c b/dbus/dbus-sysdeps-pthread.c index 55d3ea28..36bfd7ed 100644 --- a/dbus/dbus-sysdeps-pthread.c +++ b/dbus/dbus-sysdeps-pthread.c @@ -29,6 +29,10 @@ #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 */ diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 6ba3da0d..1e4cf8dd 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -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 */ diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 7f779600..c310b281 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -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 */ diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 3e2b8ceb..49524e3b 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -33,10 +33,6 @@ * 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); diff --git a/dbus/dbus-transport-socket.c b/dbus/dbus-transport-socket.c index 3f8c94d5..31a41e1f 100644 --- a/dbus/dbus-transport-socket.c +++ b/dbus/dbus-transport-socket.c @@ -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 ()); } } |