mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-05 06:28:00 +02:00
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)
This commit is contained in:
parent
283b1c6fc7
commit
43b944a0a6
14 changed files with 122 additions and 27 deletions
14
ChangeLog
14
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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@
|
|||
#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>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,14 +24,13 @@
|
|||
#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;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue