"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "dbus/dbus-sysdeps-unix.c" between
dbus-1.13.12.tar.xz and dbus-1.13.14.tar.xz

About: D-Bus is an inter-process communication (IPC) system, allowing multiple, concurrently-running applications to communicate with one another. D-Bus supplies both a system daemon and a per-user-login-session daemon. Development version.

dbus-sysdeps-unix.c  (dbus-1.13.12.tar.xz):dbus-sysdeps-unix.c  (dbus-1.13.14.tar.xz)
skipping to change at line 71 skipping to change at line 71
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
#include <syslog.h> #include <syslog.h>
#endif #endif
#ifdef HAVE_WRITEV #ifdef HAVE_WRITEV
#include <sys/uio.h> #include <sys/uio.h>
#endif #endif
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#ifdef HAVE_BACKTRACE #ifdef HAVE_BACKTRACE
#include <execinfo.h> #include <execinfo.h>
#endif #endif
#ifdef HAVE_GETPEERUCRED #ifdef HAVE_GETPEERUCRED
#include <ucred.h> #include <ucred.h>
#endif #endif
#ifdef HAVE_ALLOCA_H #ifdef HAVE_ALLOCA_H
#include <alloca.h> #include <alloca.h>
#endif #endif
#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
#endif
#ifdef HAVE_ADT #ifdef HAVE_ADT
#include <bsm/adt.h> #include <bsm/adt.h>
#endif #endif
#ifdef HAVE_SYSTEMD #ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h> #include <systemd/sd-daemon.h>
#endif #endif
#if !DBUS_USE_SYNC #if !DBUS_USE_SYNC
skipping to change at line 1413 skipping to change at line 1413
const char *port, const char *port,
const char *family, const char *family,
const char *noncefile, const char *noncefile,
DBusError *error) DBusError *error)
{ {
int saved_errno = 0; int saved_errno = 0;
DBusList *connect_errors = NULL; DBusList *connect_errors = NULL;
DBusSocket fd = DBUS_SOCKET_INIT; DBusSocket fd = DBUS_SOCKET_INIT;
int res; int res;
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *ai, *tmp; struct addrinfo *ai = NULL;
const struct addrinfo *tmp;
DBusError *connect_error; DBusError *connect_error;
_DBUS_ASSERT_ERROR_IS_CLEAR(error); _DBUS_ASSERT_ERROR_IS_CLEAR(error);
_DBUS_ZERO (hints); _DBUS_ZERO (hints);
if (!family) if (!family)
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
else if (!strcmp(family, "ipv4")) else if (!strcmp(family, "ipv4"))
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
skipping to change at line 1452 skipping to change at line 1453
host, port, gai_strerror(res), res); host, port, gai_strerror(res), res);
_dbus_socket_invalidate (&fd); _dbus_socket_invalidate (&fd);
goto out; goto out;
} }
tmp = ai; tmp = ai;
while (tmp) while (tmp)
{ {
if (!_dbus_open_socket (&fd.fd, tmp->ai_family, SOCK_STREAM, 0, error)) if (!_dbus_open_socket (&fd.fd, tmp->ai_family, SOCK_STREAM, 0, error))
{ {
freeaddrinfo(ai);
_DBUS_ASSERT_ERROR_IS_SET(error); _DBUS_ASSERT_ERROR_IS_SET(error);
_dbus_socket_invalidate (&fd); _dbus_socket_invalidate (&fd);
goto out; goto out;
} }
_DBUS_ASSERT_ERROR_IS_CLEAR(error); _DBUS_ASSERT_ERROR_IS_CLEAR(error);
if (connect (fd.fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0) if (connect (fd.fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0)
{ {
saved_errno = errno; saved_errno = errno;
_dbus_close (fd.fd, NULL); _dbus_close (fd.fd, NULL);
skipping to change at line 1493 skipping to change at line 1493
_DBUS_SET_OOM (error); _DBUS_SET_OOM (error);
goto out; goto out;
} }
tmp = tmp->ai_next; tmp = tmp->ai_next;
continue; continue;
} }
break; break;
} }
freeaddrinfo(ai);
if (!_dbus_socket_is_valid (fd)) if (!_dbus_socket_is_valid (fd))
{ {
_dbus_combine_tcp_errors (&connect_errors, "Failed to connect", _dbus_combine_tcp_errors (&connect_errors, "Failed to connect",
host, port, error); host, port, error);
goto out; goto out;
} }
if (noncefile != NULL) if (noncefile != NULL)
{ {
skipping to change at line 1525 skipping to change at line 1524
} }
if (!_dbus_set_fd_nonblocking (fd.fd, error)) if (!_dbus_set_fd_nonblocking (fd.fd, error))
{ {
_dbus_close (fd.fd, NULL); _dbus_close (fd.fd, NULL);
_dbus_socket_invalidate (&fd); _dbus_socket_invalidate (&fd);
goto out; goto out;
} }
out: out:
if (ai != NULL)
freeaddrinfo (ai);
while ((connect_error = _dbus_list_pop_first (&connect_errors))) while ((connect_error = _dbus_list_pop_first (&connect_errors)))
{ {
dbus_error_free (connect_error); dbus_error_free (connect_error);
dbus_free (connect_error); dbus_free (connect_error);
} }
return fd; return fd;
} }
/** /**
skipping to change at line 2656 skipping to change at line 2658
if (username != NULL) if (username != NULL)
username_c = _dbus_string_get_const_data (username); username_c = _dbus_string_get_const_data (username);
else else
username_c = NULL; username_c = NULL;
/* For now assuming that the getpwnam() and getpwuid() flavors /* For now assuming that the getpwnam() and getpwuid() flavors
* are always symmetrical, if not we have to add more configure * are always symmetrical, if not we have to add more configure
* checks * checks
*/ */
#if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R) #ifdef HAVE_GETPWNAM_R
{ {
struct passwd *p; struct passwd *p;
int result; int result;
size_t buflen; size_t buflen;
char *buf; char *buf;
struct passwd p_str; struct passwd p_str;
/* retrieve maximum needed size for buf */ /* retrieve maximum needed size for buf */
buflen = sysconf (_SC_GETPW_R_SIZE_MAX); buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
skipping to change at line 2685 skipping to change at line 2687
while (1) while (1)
{ {
buf = dbus_malloc (buflen); buf = dbus_malloc (buflen);
if (buf == NULL) if (buf == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return FALSE; return FALSE;
} }
p = NULL; p = NULL;
#ifdef HAVE_POSIX_GETPWNAM_R
if (uid != DBUS_UID_UNSET) if (uid != DBUS_UID_UNSET)
result = getpwuid_r (uid, &p_str, buf, buflen, result = getpwuid_r (uid, &p_str, buf, buflen,
&p); &p);
else else
result = getpwnam_r (username_c, &p_str, buf, buflen, result = getpwnam_r (username_c, &p_str, buf, buflen,
&p); &p);
#else
if (uid != DBUS_UID_UNSET)
p = getpwuid_r (uid, &p_str, buf, buflen);
else
p = getpwnam_r (username_c, &p_str, buf, buflen);
result = 0;
#endif /* !HAVE_POSIX_GETPWNAM_R */
//Try a bigger buffer if ERANGE was returned //Try a bigger buffer if ERANGE was returned
if (result == ERANGE && buflen < 512 * 1024) if (result == ERANGE && buflen < 512 * 1024)
{ {
dbus_free (buf); dbus_free (buf);
buflen *= 2; buflen *= 2;
} }
else else
{ {
break; break;
} }
skipping to change at line 2734 skipping to change at line 2728
_dbus_verbose ("User %s unknown\n", username_c ? username_c : "???"); _dbus_verbose ("User %s unknown\n", username_c ? username_c : "???");
dbus_free (buf); dbus_free (buf);
return FALSE; return FALSE;
} }
} }
#else /* ! HAVE_GETPWNAM_R */ #else /* ! HAVE_GETPWNAM_R */
{ {
/* I guess we're screwed on thread safety here */ /* I guess we're screwed on thread safety here */
struct passwd *p; struct passwd *p;
#warning getpwnam_r() not available, please report this to the dbus maintainers
with details of your OS
if (uid != DBUS_UID_UNSET) if (uid != DBUS_UID_UNSET)
p = getpwuid (uid); p = getpwuid (uid);
else else
p = getpwnam (username_c); p = getpwnam (username_c);
if (p != NULL) if (p != NULL)
{ {
if (!fill_user_info_from_passwd (p, info, error)) if (!fill_user_info_from_passwd (p, info, error))
{ {
return FALSE; return FALSE;
skipping to change at line 3074 skipping to change at line 3070
pthread_mutex_lock (&atomic_mutex); pthread_mutex_lock (&atomic_mutex);
res = atomic->value; res = atomic->value;
pthread_mutex_unlock (&atomic_mutex); pthread_mutex_unlock (&atomic_mutex);
return res; return res;
#endif #endif
} }
/** /**
* Atomically set the value of an integer to 0.
*
* @param atomic pointer to the integer to set
*/
void
_dbus_atomic_set_zero (DBusAtomic *atomic)
{
#if DBUS_USE_SYNC
/* Atomic version of "*atomic &= 0; return *atomic" */
__sync_and_and_fetch (&atomic->value, 0);
#else
pthread_mutex_lock (&atomic_mutex);
atomic->value = 0;
pthread_mutex_unlock (&atomic_mutex);
#endif
}
/**
* Atomically set the value of an integer to something nonzero.
*
* @param atomic pointer to the integer to set
*/
void
_dbus_atomic_set_nonzero (DBusAtomic *atomic)
{
#if DBUS_USE_SYNC
/* Atomic version of "*atomic |= 1; return *atomic" */
__sync_or_and_fetch (&atomic->value, 1);
#else
pthread_mutex_lock (&atomic_mutex);
atomic->value = 1;
pthread_mutex_unlock (&atomic_mutex);
#endif
}
/**
* Wrapper for poll(). * Wrapper for poll().
* *
* @param fds the file descriptors to poll * @param fds the file descriptors to poll
* @param n_fds number of descriptors in the array * @param n_fds number of descriptors in the array
* @param timeout_milliseconds timeout or -1 for infinite * @param timeout_milliseconds timeout or -1 for infinite
* @returns numbers of fds with revents, or <0 on error * @returns numbers of fds with revents, or <0 on error
*/ */
int int
_dbus_poll (DBusPollFD *fds, _dbus_poll (DBusPollFD *fds,
int n_fds, int n_fds,
skipping to change at line 3355 skipping to change at line 3387
* @param str the string * @param str the string
* @param n_bytes the number of random bytes to append to string * @param n_bytes the number of random bytes to append to string
* @param error location to store reason for failure * @param error location to store reason for failure
* @returns #TRUE on success, #FALSE on error * @returns #TRUE on success, #FALSE on error
*/ */
dbus_bool_t dbus_bool_t
_dbus_generate_random_bytes (DBusString *str, _dbus_generate_random_bytes (DBusString *str,
int n_bytes, int n_bytes,
DBusError *error) DBusError *error)
{ {
int old_len; int old_len = _dbus_string_get_length (str);
int fd; int fd;
int result; int result;
#ifdef HAVE_GETRANDOM
char *buffer;
if (!_dbus_string_lengthen (str, n_bytes))
{
_DBUS_SET_OOM (error);
return FALSE;
}
buffer = _dbus_string_get_data_len (str, old_len, n_bytes);
result = getrandom (buffer, n_bytes, GRND_NONBLOCK);
old_len = _dbus_string_get_length (str); if (result == n_bytes)
fd = -1; return TRUE;
_dbus_string_set_length (str, old_len);
#endif
/* note, urandom on linux will fall back to pseudorandom */ /* note, urandom on linux will fall back to pseudorandom */
fd = open ("/dev/urandom", O_RDONLY); fd = open ("/dev/urandom", O_RDONLY);
if (fd < 0) if (fd < 0)
{ {
dbus_set_error (error, _dbus_error_from_errno (errno), dbus_set_error (error, _dbus_error_from_errno (errno),
"Could not open /dev/urandom: %s", "Could not open /dev/urandom: %s",
_dbus_strerror (errno)); _dbus_strerror (errno));
return FALSE; return FALSE;
 End of changes. 14 change blocks. 
18 lines changed or deleted 65 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)