diff options
Diffstat (limited to 'dbus/dbus-sysdeps-unix.c')
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 385 |
1 files changed, 193 insertions, 192 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index e60e6144..1b834beb 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1,11 +1,11 @@ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* dbus-sysdeps-unix.c Wrappers around UNIX system/libc features (internal to D-Bus implementation) - * + * * Copyright (C) 2002, 2003, 2006 Red Hat, Inc. * Copyright (C) 2003 CodeFactory AB * * Licensed under the Academic Free License version 2.1 - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -15,7 +15,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -161,7 +161,7 @@ _dbus_open_unix_socket (int *fd, * @param error return location for an error * @returns #FALSE if error is set */ -dbus_bool_t +dbus_bool_t _dbus_close_socket (int fd, DBusError *error) { @@ -474,7 +474,7 @@ _dbus_pipe_write (DBusPipe *pipe, DBusError *error) { int written; - + written = _dbus_write (pipe->fd_or_handle, buffer, start, len); if (written < 0) { @@ -510,7 +510,7 @@ _dbus_pipe_close (DBusPipe *pipe, /** * Like _dbus_write_two() but only works on sockets and is thus * available on Windows. - * + * * @param fd the file descriptor * @param buffer1 first buffer * @param start1 first byte to write in first buffer @@ -588,7 +588,7 @@ _dbus_write_socket_two (int fd, * * Unlike _dbus_read_socket(), _dbus_read() is not available * on Windows. - * + * * @param fd the file descriptor to read from * @param buffer the buffer to append data to * @param count the amount of data to read @@ -604,7 +604,7 @@ _dbus_read (int fd, char *data; _dbus_assert (count >= 0); - + start = _dbus_string_get_length (buffer); if (!_dbus_string_lengthen (buffer, count)) @@ -616,7 +616,7 @@ _dbus_read (int fd, data = _dbus_string_get_data_len (buffer, start, count); again: - + bytes_read = read (fd, data, count); if (bytes_read < 0) @@ -639,7 +639,7 @@ _dbus_read (int fd, if (bytes_read > 0) _dbus_verbose_bytes_of_string (buffer, start, bytes_read); #endif - + return bytes_read; } } @@ -647,7 +647,7 @@ _dbus_read (int fd, /** * Thin wrapper around the write() system call that writes a part of a * DBusString and handles EINTR for you. - * + * * @param fd the file descriptor to write * @param buffer the buffer to write data from * @param start the first byte in the buffer to write @@ -662,9 +662,9 @@ _dbus_write (int fd, { const char *data; int bytes_written; - + data = _dbus_string_get_const_data_len (buffer, start, len); - + again: bytes_written = write (fd, data, len); @@ -676,7 +676,7 @@ _dbus_write (int fd, if (bytes_written > 0) _dbus_verbose_bytes_of_string (buffer, start, bytes_written); #endif - + return bytes_written; } @@ -714,7 +714,7 @@ _dbus_write_two (int fd, _dbus_assert (start2 >= 0); _dbus_assert (len1 >= 0); _dbus_assert (len2 >= 0); - + #ifdef HAVE_WRITEV { struct iovec vectors[2]; @@ -732,40 +732,40 @@ _dbus_write_two (int fd, start2 = 0; len2 = 0; } - + vectors[0].iov_base = (char*) data1; vectors[0].iov_len = len1; vectors[1].iov_base = (char*) data2; vectors[1].iov_len = len2; again: - + bytes_written = writev (fd, vectors, data2 ? 2 : 1); if (bytes_written < 0 && errno == EINTR) goto again; - + return bytes_written; } #else /* HAVE_WRITEV */ { int ret1; - + ret1 = _dbus_write (fd, buffer1, start1, len1); if (ret1 == len1 && buffer2 != NULL) { ret2 = _dbus_write (fd, buffer2, start2, len2); if (ret2 < 0) ret2 = 0; /* we can't report an error as the first write was OK */ - + return ret1 + ret2; } else return ret1; } -#endif /* !HAVE_WRITEV */ +#endif /* !HAVE_WRITEV */ } #define _DBUS_MAX_SUN_PATH_LENGTH 99 @@ -787,7 +787,7 @@ _dbus_write_two (int fd, * Creates a socket and connects it to the UNIX domain socket at the * given path. The connection fd is returned, and is set up as * nonblocking. - * + * * Uses abstract sockets instead of filesystem-linked sockets if * requested (it's possible only on Linux; see "man 7 unix" on Linux). * On non-Linux abstract socket usage always fails. @@ -806,14 +806,14 @@ _dbus_connect_unix_socket (const char *path, { int fd; size_t path_len; - struct sockaddr_un addr; + struct sockaddr_un addr; _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_verbose ("connecting to unix socket %s abstract=%d\n", path, abstract); - - + + if (!_dbus_open_unix_socket (&fd, error)) { _DBUS_ASSERT_ERROR_IS_SET(error); @@ -838,7 +838,7 @@ _dbus_connect_unix_socket (const char *path, _dbus_close (fd, NULL); return -1; } - + strncpy (&addr.sun_path[1], path, path_len); /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */ #else /* HAVE_ABSTRACT_SOCKETS */ @@ -860,9 +860,9 @@ _dbus_connect_unix_socket (const char *path, strncpy (addr.sun_path, path, path_len); } - + if (connect (fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0) - { + { dbus_set_error (error, _dbus_error_from_errno (errno), "Failed to connect to socket %s: %s", @@ -870,14 +870,14 @@ _dbus_connect_unix_socket (const char *path, _dbus_close (fd, NULL); fd = -1; - + return -1; } if (!_dbus_set_fd_nonblocking (fd, error)) { _DBUS_ASSERT_ERROR_IS_SET (error); - + _dbus_close (fd, NULL); fd = -1; @@ -902,10 +902,10 @@ _dbus_set_local_creds (int fd, dbus_bool_t on) dbus_bool_t retval = TRUE; #if defined(HAVE_CMSGCRED) - /* NOOP just to make sure only one codepath is used + /* NOOP just to make sure only one codepath is used * and to prefer CMSGCRED */ -#elif defined(LOCAL_CREDS) +#elif defined(LOCAL_CREDS) int val = on ? 1 : 0; if (setsockopt (fd, 0, LOCAL_CREDS, &val, sizeof (val)) < 0) { @@ -950,7 +950,7 @@ _dbus_listen_unix_socket (const char *path, _dbus_verbose ("listening on unix socket %s abstract=%d\n", path, abstract); - + if (!_dbus_open_unix_socket (&listen_fd, error)) { _DBUS_ASSERT_ERROR_IS_SET(error); @@ -961,7 +961,7 @@ _dbus_listen_unix_socket (const char *path, _DBUS_ZERO (addr); addr.sun_family = AF_UNIX; path_len = strlen (path); - + if (abstract) { #ifdef HAVE_ABSTRACT_SOCKETS @@ -978,7 +978,7 @@ _dbus_listen_unix_socket (const char *path, _dbus_close (listen_fd, NULL); return -1; } - + strncpy (&addr.sun_path[1], path, path_len); /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */ #else /* HAVE_ABSTRACT_SOCKETS */ @@ -1015,10 +1015,10 @@ _dbus_listen_unix_socket (const char *path, _dbus_close (listen_fd, NULL); return -1; } - + strncpy (addr.sun_path, path, path_len); } - + if (bind (listen_fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0) { dbus_set_error (error, _dbus_error_from_errno (errno), @@ -1052,19 +1052,19 @@ _dbus_listen_unix_socket (const char *path, _dbus_close (listen_fd, NULL); return -1; } - + /* Try opening up the permissions, but if we can't, just go ahead * and continue, maybe it will be good enough. */ if (!abstract && chmod (path, 0777) < 0) _dbus_warn ("Could not set mode 0777 on socket %s\n", path); - + return listen_fd; } /** - * Creates a socket and connects to a socket at the given host + * Creates a socket and connects to a socket at the given host * and port. The connection fd is returned, and is set up as * nonblocking. * @@ -1372,7 +1372,7 @@ write_credentials_byte (int server_fd, { int bytes_written; char buf[1] = { '\0' }; -#if defined(HAVE_CMSGCRED) +#if defined(HAVE_CMSGCRED) union { struct cmsghdr hdr; char cred[CMSG_SPACE (sizeof (struct cmsgcred))]; @@ -1395,10 +1395,10 @@ write_credentials_byte (int server_fd, #endif _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + again: -#if defined(HAVE_CMSGCRED) +#if defined(HAVE_CMSGCRED) bytes_written = sendmsg (server_fd, &msg, 0); #else bytes_written = write (server_fd, buf, 1); @@ -1438,7 +1438,7 @@ write_credentials_byte (int server_fd, * we got valid credentials. On some systems, such as Linux, * reading/writing the byte isn't actually required, but we do it * anyway just to avoid multiple codepaths. - * + * * Fails if no byte is available, so you must select() first. * * The point of the byte is that on some systems we have to @@ -1460,8 +1460,8 @@ _dbus_read_credentials_socket (int client_fd, dbus_uid_t uid_read; dbus_pid_t pid_read; int bytes_read; - -#ifdef HAVE_CMSGCRED + +#ifdef HAVE_CMSGCRED union { struct cmsghdr hdr; char cred[CMSG_SPACE (sizeof (struct cmsgcred))]; @@ -1478,7 +1478,7 @@ _dbus_read_credentials_socket (int client_fd, pid_read = DBUS_PID_UNSET; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + /* The POSIX spec certainly doesn't promise this, but * we need these assertions to fail as soon as we're wrong about * it so we can do the porting fixups @@ -1520,7 +1520,7 @@ _dbus_read_credentials_socket (int client_fd, * normally only call read_credentials if the socket was ready * for reading */ - + dbus_set_error (error, _dbus_error_from_errno (errno), "Failed to read credentials byte: %s", _dbus_strerror (errno)); @@ -1556,9 +1556,9 @@ _dbus_read_credentials_socket (int client_fd, { #ifdef SO_PEERCRED - struct ucred cr; + struct ucred cr; int cr_len = sizeof (cr); - + if (getsockopt (client_fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) == 0 && cr_len == sizeof (cr)) { @@ -1608,9 +1608,9 @@ _dbus_read_credentials_socket (int client_fd, { _dbus_verbose ("Failed to adt_start_session(): %s\n", _dbus_strerror (errno)); } - else + else { - if (adt_set_from_ucred (adth, ucred, ADT_NEW)) + if (adt_set_from_ucred (adth, ucred, ADT_NEW)) { _dbus_verbose ("Failed to adt_set_from_ucred(): %s\n", _dbus_strerror (errno)); } @@ -1666,7 +1666,7 @@ _dbus_read_credentials_socket (int client_fd, return FALSE; } } - + return TRUE; } @@ -1692,7 +1692,7 @@ _dbus_send_credentials_socket (int server_fd, DBusError *error) { _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + if (write_credentials_byte (server_fd, error)) return TRUE; else @@ -1752,8 +1752,8 @@ _dbus_accept (int listen_fd) } /** - * Checks to make sure the given directory is - * private to the user + * Checks to make sure the given directory is + * private to the user * * @param dir the name of the directory * @param error error return @@ -1764,19 +1764,19 @@ _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error) { const char *directory; struct stat sb; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + directory = _dbus_string_get_const_data (dir); - + if (stat (directory, &sb) < 0) { dbus_set_error (error, _dbus_error_from_errno (errno), "%s", _dbus_strerror (errno)); - + return FALSE; } - + if ((S_IROTH & sb.st_mode) || (S_IWOTH & sb.st_mode) || (S_IRGRP & sb.st_mode) || (S_IWGRP & sb.st_mode)) { @@ -1784,7 +1784,7 @@ _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error) "%s directory is not private to the user", directory); return FALSE; } - + return TRUE; } @@ -1795,12 +1795,12 @@ fill_user_info_from_passwd (struct passwd *p, { _dbus_assert (p->pw_name != NULL); _dbus_assert (p->pw_dir != NULL); - + info->uid = p->pw_uid; info->primary_gid = p->pw_gid; info->username = _dbus_strdup (p->pw_name); info->homedir = _dbus_strdup (p->pw_dir); - + if (info->username == NULL || info->homedir == NULL) { @@ -1818,7 +1818,7 @@ fill_user_info (DBusUserInfo *info, DBusError *error) { const char *username_c; - + /* exactly one of username/uid provided */ _dbus_assert (username != NULL || uid != DBUS_UID_UNSET); _dbus_assert (username == NULL || uid == DBUS_UID_UNSET); @@ -1829,7 +1829,7 @@ fill_user_info (DBusUserInfo *info, info->n_group_ids = 0; info->username = NULL; info->homedir = NULL; - + if (username != NULL) username_c = _dbus_string_get_const_data (username); else @@ -1839,7 +1839,7 @@ fill_user_info (DBusUserInfo *info, * are always symmetrical, if not we have to add more configure * checks */ - + #if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R) { struct passwd *p; @@ -1943,7 +1943,7 @@ fill_user_info (DBusUserInfo *info, /* Fill this in so we can use it to get groups */ username_c = info->username; - + #ifdef HAVE_GETGROUPLIST { gid_t *buf; @@ -1959,7 +1959,7 @@ fill_user_info (DBusUserInfo *info, dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); goto failed; } - + if (getgrouplist (username_c, info->primary_gid, buf, &buf_count) < 0) @@ -1976,10 +1976,10 @@ fill_user_info (DBusUserInfo *info, for the "id" command, and it turns out that they use an undocumented library function getgrouplist_2 (!) which is not declared in any header in /usr/include (!!). That did not seem - like the way to go here. + like the way to go here. */ - if (buf_count == initial_buf_count) - { + if (buf_count == initial_buf_count) + { buf_count *= 16; /* Retry with an arbitrarily scaled-up array */ } new = dbus_realloc (buf, buf_count * sizeof (buf[0])); @@ -1989,7 +1989,7 @@ fill_user_info (DBusUserInfo *info, dbus_free (buf); goto failed; } - + buf = new; errno = 0; @@ -1999,7 +1999,7 @@ fill_user_info (DBusUserInfo *info, { _dbus_warn ("It appears that username \"%s\" is in more than %d groups.\nProceeding with just the first %d groups.", username_c, buf_count, buf_count); - } + } else { dbus_set_error (error, @@ -2021,12 +2021,12 @@ fill_user_info (DBusUserInfo *info, dbus_free (buf); goto failed; } - + for (i = 0; i < buf_count; ++i) info->group_ids[i] = buf[i]; info->n_group_ids = buf_count; - + dbus_free (buf); } #else /* HAVE_GETGROUPLIST */ @@ -2046,9 +2046,9 @@ fill_user_info (DBusUserInfo *info, #endif /* HAVE_GETGROUPLIST */ _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + return TRUE; - + failed: _DBUS_ASSERT_ERROR_IS_SET (error); return FALSE; @@ -2121,7 +2121,7 @@ _dbus_credentials_add_from_current_process (DBusCredentials *credentials) * is required, that is done in dbus-auth.c. The username here * need not be anything human-readable, it can be the machine-readable * form i.e. a user id. - * + * * @param str the string to append to * @returns #FALSE on no memory */ @@ -2163,7 +2163,7 @@ _dbus_geteuid (void) /** * The only reason this is separate from _dbus_getpid() is to allow it * on Windows for logging but not for other purposes. - * + * * @returns process ID to put in log messages */ unsigned long @@ -2185,7 +2185,7 @@ _dbus_parse_uid (const DBusString *uid_str, { int end; long val; - + if (_dbus_string_get_length (uid_str) == 0) { _dbus_verbose ("UID string was zero length\n"); @@ -2200,7 +2200,7 @@ _dbus_parse_uid (const DBusString *uid_str, _dbus_verbose ("could not parse string as a UID\n"); return FALSE; } - + if (end != _dbus_string_get_length (uid_str)) { _dbus_verbose ("string contained trailing stuff after UID\n"); @@ -2250,7 +2250,7 @@ _dbus_atomic_dec (DBusAtomic *atomic) return __sync_sub_and_fetch(&atomic->value, 1)+1; #else dbus_int32_t res; - + _DBUS_LOCK (atomic); res = atomic->value; atomic->value -= 1; @@ -2303,7 +2303,7 @@ _dbus_poll (DBusPollFD *fds, _DBUS_STRUCT_OFFSET (struct pollfd, revents)) { return poll ((struct pollfd*) fds, - n_fds, + n_fds, timeout_milliseconds); } else @@ -2321,7 +2321,7 @@ _dbus_poll (DBusPollFD *fds, int i; struct timeval tv; int ready; - + FD_ZERO (&read_set); FD_ZERO (&write_set); FD_ZERO (&err_set); @@ -2340,7 +2340,7 @@ _dbus_poll (DBusPollFD *fds, max_fd = MAX (max_fd, fdp->fd); } - + tv.tv_sec = timeout_milliseconds / 1000; tv.tv_usec = (timeout_milliseconds % 1000) * 1000; @@ -2397,12 +2397,14 @@ _dbus_get_current_time (long *tv_sec, * * @param str the string to append to * @param filename filename to load + * @param mtime if not NULL the modification time will be stored here * @param error place to set an error * @returns #FALSE if error was set */ dbus_bool_t _dbus_file_get_contents (DBusString *str, const DBusString *filename, + unsigned long *mtime, DBusError *error) { int fd; @@ -2412,9 +2414,9 @@ _dbus_file_get_contents (DBusString *str, const char *filename_c; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + filename_c = _dbus_string_get_const_data (filename); - + /* O_BINARY useful on Cygwin */ fd = open (filename_c, O_RDONLY | O_BINARY); if (fd < 0) @@ -2427,7 +2429,7 @@ _dbus_file_get_contents (DBusString *str, } _dbus_verbose ("file fd %d opened\n", fd); - + if (fstat (fd, &sb) < 0) { dbus_set_error (error, _dbus_error_from_errno (errno), @@ -2437,9 +2439,9 @@ _dbus_file_get_contents (DBusString *str, _dbus_verbose ("fstat() failed: %s", _dbus_strerror (errno)); - + _dbus_close (fd, NULL); - + return FALSE; } @@ -2451,7 +2453,7 @@ _dbus_file_get_contents (DBusString *str, _dbus_close (fd, NULL); return FALSE; } - + total = 0; orig_len = _dbus_string_get_length (str); if (sb.st_size > 0 && S_ISREG (sb.st_mode)) @@ -2471,7 +2473,7 @@ _dbus_file_get_contents (DBusString *str, _dbus_verbose ("read() failed: %s", _dbus_strerror (errno)); - + _dbus_close (fd, NULL); _dbus_string_set_length (str, orig_len); return FALSE; @@ -2479,9 +2481,6 @@ _dbus_file_get_contents (DBusString *str, else total += bytes_read; } - - _dbus_close (fd, NULL); - return TRUE; } else if (sb.st_size != 0) { @@ -2492,11 +2491,13 @@ _dbus_file_get_contents (DBusString *str, _dbus_close (fd, NULL); return FALSE; } - else - { - _dbus_close (fd, NULL); - return TRUE; - } + + + if (mtime) + *mtime = (unsigned long) sb.st_mtime; + + _dbus_close (fd, NULL); + return TRUE; } /** @@ -2523,11 +2524,11 @@ _dbus_string_save_to_file (const DBusString *str, dbus_bool_t retval; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + fd = -1; retval = FALSE; need_unlink = FALSE; - + if (!_dbus_string_init (&tmp_filename)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); @@ -2540,7 +2541,7 @@ _dbus_string_save_to_file (const DBusString *str, _dbus_string_free (&tmp_filename); return FALSE; } - + if (!_dbus_string_append (&tmp_filename, ".")) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); @@ -2555,7 +2556,7 @@ _dbus_string_save_to_file (const DBusString *str, _dbus_string_free (&tmp_filename); return FALSE; } - + filename_c = _dbus_string_get_const_data (filename); tmp_filename_c = _dbus_string_get_const_data (&tmp_filename); @@ -2570,9 +2571,9 @@ _dbus_string_save_to_file (const DBusString *str, } _dbus_verbose ("tmp file fd %d opened\n", fd); - + need_unlink = TRUE; - + total = 0; bytes_to_write = _dbus_string_get_length (str); @@ -2588,7 +2589,7 @@ _dbus_string_save_to_file (const DBusString *str, dbus_set_error (error, _dbus_error_from_errno (errno), "Could not write to %s: %s", tmp_filename_c, _dbus_strerror (errno)); - + goto out; } @@ -2614,7 +2615,7 @@ _dbus_string_save_to_file (const DBusString *str, } fd = -1; - + if (rename (tmp_filename_c, filename_c) < 0) { dbus_set_error (error, _dbus_error_from_errno (errno), @@ -2626,9 +2627,9 @@ _dbus_string_save_to_file (const DBusString *str, } need_unlink = FALSE; - + retval = TRUE; - + out: /* close first, then unlink, to prevent ".nfs34234235" garbage * files @@ -2636,7 +2637,7 @@ _dbus_string_save_to_file (const DBusString *str, if (fd >= 0) _dbus_close (fd, NULL); - + if (need_unlink && unlink (tmp_filename_c) < 0) _dbus_verbose ("Failed to unlink temp file %s: %s\n", tmp_filename_c, _dbus_strerror (errno)); @@ -2645,7 +2646,7 @@ _dbus_string_save_to_file (const DBusString *str, if (!retval) _DBUS_ASSERT_ERROR_IS_SET (error); - + return retval; } @@ -2690,9 +2691,9 @@ _dbus_create_file_exclusively (const DBusString *filename, const char *filename_c; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + filename_c = _dbus_string_get_const_data (filename); - + fd = open (filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT, 0600); if (fd < 0) @@ -2706,7 +2707,7 @@ _dbus_create_file_exclusively (const DBusString *filename, } _dbus_verbose ("exclusive file fd %d opened\n", fd); - + if (!_dbus_close (fd, NULL)) { dbus_set_error (error, @@ -2716,7 +2717,7 @@ _dbus_create_file_exclusively (const DBusString *filename, _dbus_strerror (errno)); return FALSE; } - + return TRUE; } @@ -2725,7 +2726,7 @@ _dbus_create_file_exclusively (const DBusString *filename, * * @param filename the filename * @param error error location - * + * * @returns #TRUE if unlink() succeeded */ dbus_bool_t @@ -2735,7 +2736,7 @@ _dbus_delete_file (const DBusString *filename, const char *filename_c; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + filename_c = _dbus_string_get_const_data (filename); if (unlink (filename_c) < 0) @@ -2764,14 +2765,14 @@ _dbus_create_directory (const DBusString *filename, const char *filename_c; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + filename_c = _dbus_string_get_const_data (filename); if (mkdir (filename_c, 0700) < 0) { if (errno == EEXIST) return TRUE; - + dbus_set_error (error, DBUS_ERROR_FAILED, "Failed to create directory %s: %s\n", filename_c, _dbus_strerror (errno)); @@ -2801,7 +2802,7 @@ _dbus_concat_dir_and_file (DBusString *dir, if (_dbus_string_get_length (dir) == 0 || _dbus_string_get_length (next_component) == 0) return TRUE; - + dir_ends_in_slash = '/' == _dbus_string_get_byte (dir, _dbus_string_get_length (dir) - 1); @@ -2863,7 +2864,7 @@ _dbus_generate_pseudorandom_bytes (DBusString *str, { int old_len; char *p; - + old_len = _dbus_string_get_length (str); if (!_dbus_string_lengthen (str, n_bytes)) @@ -2896,7 +2897,7 @@ _dbus_generate_random_bytes (DBusString *str, * a DBusError. So we always fall back to pseudorandom * if the I/O fails. */ - + old_len = _dbus_string_get_length (str); fd = -1; @@ -2906,7 +2907,7 @@ _dbus_generate_random_bytes (DBusString *str, return _dbus_generate_pseudorandom_bytes (str, n_bytes); _dbus_verbose ("/dev/urandom fd %d opened\n", fd); - + if (_dbus_read (fd, str, n_bytes) != n_bytes) { _dbus_close (fd, NULL); @@ -2916,9 +2917,9 @@ _dbus_generate_random_bytes (DBusString *str, _dbus_verbose ("Read %d bytes from /dev/urandom\n", n_bytes); - + _dbus_close (fd, NULL); - + return TRUE; } @@ -2945,7 +2946,7 @@ const char* _dbus_strerror (int error_number) { const char *msg; - + msg = strerror (error_number); if (msg == NULL) msg = "unknown"; @@ -2973,14 +2974,14 @@ void _dbus_fd_set_close_on_exec (int fd) { int val; - + val = fcntl (fd, F_GETFD, 0); - + if (val < 0) return; val |= FD_CLOEXEC; - + fcntl (fd, F_SETFD, val); } @@ -2996,7 +2997,7 @@ _dbus_close (int fd, DBusError *error) { _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + again: if (close (fd) < 0) { @@ -3067,7 +3068,7 @@ _dbus_set_fd_nonblocking (int fd, int val; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + val = fcntl (fd, F_GETFL, 0); if (val < 0) { @@ -3100,17 +3101,17 @@ _dbus_set_fd_nonblocking (int fd, */ void _dbus_print_backtrace (void) -{ +{ #if defined (HAVE_BACKTRACE) && defined (DBUS_BUILT_R_DYNAMIC) void *bt[500]; int bt_size; int i; char **syms; - + bt_size = backtrace (bt, 500); syms = backtrace_symbols (bt, bt_size); - + i = 0; while (i < bt_size) { @@ -3138,7 +3139,7 @@ _dbus_print_backtrace (void) * principle it could be in dbus-sysdeps-util.c, except that * dbus-sysdeps-util.c isn't in libdbus when tests are enabled and the * debug-pipe server is used. - * + * * @param fd1 return location for one end * @param fd2 return location for the other end * @param blocking #TRUE if pipe should be blocking @@ -3190,20 +3191,20 @@ _dbus_full_duplex_pipe (int *fd1, { dbus_set_error (error, _dbus_error_from_errno (errno), "Could not set full-duplex pipe nonblocking"); - + _dbus_close (fds[0], NULL); _dbus_close (fds[1], NULL); - + return FALSE; } - + *fd1 = fds[0]; *fd2 = fds[1]; _dbus_verbose ("full-duplex pipe %d <-> %d\n", *fd1, *fd2); - - return TRUE; + + return TRUE; #else _dbus_warn ("_dbus_full_duplex_pipe() not implemented on this OS\n"); dbus_set_error (error, DBUS_ERROR_FAILED, @@ -3229,7 +3230,7 @@ _dbus_printf_string_upper_bound (const char *format, } /** - * Gets the temporary files directory by inspecting the environment variables + * Gets the temporary files directory by inspecting the environment variables * TMPDIR, TMP, and TEMP in that order. If none of those are set "/tmp" is returned * * @returns location of temp directory @@ -3260,9 +3261,9 @@ _dbus_get_tmpdir(void) if (tmpdir == NULL) tmpdir = "/tmp"; } - + _dbus_assert(tmpdir != NULL); - + return tmpdir; } @@ -3302,7 +3303,7 @@ _read_subprocess_line_argv (const char *progpath, dbus_bool_t retval; sigset_t new_set, old_set; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); retval = FALSE; @@ -3313,9 +3314,9 @@ _read_subprocess_line_argv (const char *progpath, sigemptyset (&new_set); sigaddset (&new_set, SIGCHLD); sigprocmask (SIG_BLOCK, &new_set, &old_set); - + orig_len = _dbus_string_get_length (result); - + #define READ_END 0 #define WRITE_END 1 if (pipe (result_pipe) < 0) @@ -3360,7 +3361,7 @@ _read_subprocess_line_argv (const char *progpath, _exit (1); _dbus_verbose ("/dev/null fd %d opened\n", fd); - + /* set-up stdXXX */ close (result_pipe[READ_END]); close (errors_pipe[READ_END]); @@ -3415,7 +3416,7 @@ _read_subprocess_line_argv (const char *progpath, errors_pipe[WRITE_END] = -1; ret = 0; - do + do { ret = _dbus_read (result_pipe[READ_END], result, 1024); } @@ -3455,7 +3456,7 @@ _read_subprocess_line_argv (const char *progpath, } retval = TRUE; - + out: sigprocmask (SIG_SETMASK, &old_set, NULL); @@ -3473,7 +3474,7 @@ _read_subprocess_line_argv (const char *progpath, if (errors_pipe[1] != -1) close (errors_pipe[1]); - return retval; + return retval; } /** @@ -3495,7 +3496,7 @@ _dbus_get_autolaunch_address (DBusString *address, int i; DBusString uuid; dbus_bool_t retval; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); retval = FALSE; @@ -3504,13 +3505,13 @@ _dbus_get_autolaunch_address (DBusString *address, _DBUS_SET_OOM (error); return FALSE; } - + if (!_dbus_get_local_machine_uuid_encoded (&uuid)) { _DBUS_SET_OOM (error); goto out; } - + i = 0; argv[i] = "dbus-launch"; ++i; @@ -3569,14 +3570,14 @@ _dbus_read_local_machine_uuid (DBusGUID *machine_id, /** * Determines the address of the session bus by querying a - * platform-specific method. + * platform-specific method. * * The first parameter will be a boolean specifying whether * or not a dynamic session lookup is supported on this platform. - * + * * If supported is TRUE and the return value is #TRUE, the * address will be appended to @p address. - * If a failure happens, returns #FALSE and sets an error in + * If a failure happens, returns #FALSE and sets an error in * @p error. * * If supported is FALSE, ignore the return value. @@ -3593,15 +3594,15 @@ _dbus_lookup_session_address (dbus_bool_t *supported, { /* On non-Mac Unix platforms, if the session address isn't already * set in DBUS_SESSION_BUS_ADDRESS environment variable, we punt and - * fall back to the autolaunch: global default; see + * fall back to the autolaunch: global default; see * init_session_address in dbus/dbus-bus.c. */ *supported = FALSE; return TRUE; } /** - * Returns the standard directories for a session bus to look for service - * activation files + * Returns the standard directories for a session bus to look for service + * activation files * * On UNIX this should be the standard xdg freedesktop.org data directories: * @@ -3613,10 +3614,10 @@ _dbus_lookup_session_address (dbus_bool_t *supported, * DBUS_DATADIR * * @param dirs the directory list we are returning - * @returns #FALSE on OOM + * @returns #FALSE on OOM */ -dbus_bool_t +dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs) { const char *xdg_data_home; @@ -3643,11 +3644,11 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) goto oom; } - /* + /* * add configured datadir to defaults * this may be the same as an xdg dir - * however the config parser should take - * care of duplicates + * however the config parser should take + * care of duplicates */ if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR":")) goto oom; @@ -3664,7 +3665,7 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) if (!_dbus_homedir_from_current_process (&homedir)) goto oom; - + if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir))) goto oom; @@ -3673,12 +3674,12 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) goto oom; } - if (!_dbus_split_paths_and_append (&servicedir_path, - DBUS_UNIX_STANDARD_SESSION_SERVICEDIR, + if (!_dbus_split_paths_and_append (&servicedir_path, + DBUS_UNIX_STANDARD_SESSION_SERVICEDIR, dirs)) goto oom; - _dbus_string_free (&servicedir_path); + _dbus_string_free (&servicedir_path); return TRUE; oom: @@ -3688,8 +3689,8 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) /** - * Returns the standard directories for a system bus to look for service - * activation files + * Returns the standard directories for a system bus to look for service + * activation files * * On UNIX this should be the standard xdg freedesktop.org data directories: * @@ -3702,10 +3703,10 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) * On Windows there is no system bus and this function can return nothing. * * @param dirs the directory list we are returning - * @returns #FALSE on OOM + * @returns #FALSE on OOM */ -dbus_bool_t +dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs) { const char *xdg_data_dirs; @@ -3730,21 +3731,21 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs) goto oom; } - /* + /* * add configured datadir to defaults * this may be the same as an xdg dir - * however the config parser should take - * care of duplicates + * however the config parser should take + * care of duplicates */ if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR":")) goto oom; - if (!_dbus_split_paths_and_append (&servicedir_path, - DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR, + if (!_dbus_split_paths_and_append (&servicedir_path, + DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR, dirs)) goto oom; - _dbus_string_free (&servicedir_path); + _dbus_string_free (&servicedir_path); return TRUE; oom: @@ -3756,7 +3757,7 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs) * Append the absolute path of the system.conf file * (there is no system bus on Windows so this can just * return FALSE and print a warning or something) - * + * * @param str the string to append to * @returns #FALSE if no memory */ @@ -3768,7 +3769,7 @@ _dbus_append_system_config_file (DBusString *str) /** * Append the absolute path of the session.conf file. - * + * * @param str the string to append to * @returns #FALSE if no memory */ @@ -3783,7 +3784,7 @@ _dbus_append_session_config_file (DBusString *str) * caches should be nuked. Of course any caches that need explicit reload * are probably broken, but c'est la vie. * - * + * */ void _dbus_flush_caches (void) @@ -3798,10 +3799,10 @@ _dbus_flush_caches (void) * * On UNIX the directory is ~/.dbus-keyrings while on Windows it should probably * be something else, since the dotfile convention is not normal on Windows. - * + * * @param directory string to append directory to * @param credentials credentials the directory should be for - * + * * @returns #FALSE on no memory */ dbus_bool_t @@ -3811,10 +3812,10 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, DBusString homedir; DBusString dotdir; dbus_uid_t uid; - + _dbus_assert (credentials != NULL); _dbus_assert (!_dbus_credentials_are_anonymous (credentials)); - + if (!_dbus_string_init (&homedir)) return FALSE; @@ -3823,11 +3824,11 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, if (!_dbus_homedir_from_uid (uid, &homedir)) goto failed; - + #ifdef DBUS_BUILD_TESTS { const char *override; - + override = _dbus_getenv ("DBUS_TEST_HOMEDIR"); if (override != NULL && *override != '\0') { @@ -3854,7 +3855,7 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, if (!_dbus_concat_dir_and_file (&homedir, &dotdir)) goto failed; - + if (!_dbus_string_copy (&homedir, 0, directory, _dbus_string_get_length (directory))) { goto failed; @@ -3862,8 +3863,8 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, _dbus_string_free (&homedir); return TRUE; - - failed: + + failed: _dbus_string_free (&homedir); return FALSE; } |