Internal system-dependent API
[D-Bus secret internal implementation details]

Internal system-dependent API available on UNIX and Windows. More...

Data Structures

struct  DBusCredentials
 Struct representing socket credentials. More...
struct  DBusUserInfo
 Information about a UNIX user. More...
struct  DBusGroupInfo
 Information about a UNIX group. More...
struct  DBusAtomic
 An atomic integer safe to increment or decrement from multiple threads. More...
struct  DBusPollFD
 A portable struct pollfd wrapper. More...
struct  DBusStat
 Portable struct with stat() results. More...

Defines

#define _DBUS_GNUC_PRINTF(format_idx, arg_idx)
 used to tell gcc about printf format strings
#define _DBUS_GNUC_NORETURN
 used to tell gcc about functions that never return, such as _dbus_abort()
#define DBUS_PID_UNSET   ((dbus_pid_t) -1)
 an invalid PID used to represent an uninitialized dbus_pid_t field
#define DBUS_UID_UNSET   ((dbus_uid_t) -1)
 an invalid UID used to represent an uninitialized dbus_uid_t field
#define DBUS_GID_UNSET   ((dbus_gid_t) -1)
 an invalid GID used to represent an uninitialized dbus_gid_t field
#define DBUS_PID_FORMAT   "%lu"
 an appropriate printf format for dbus_pid_t
#define DBUS_UID_FORMAT   "%lu"
 an appropriate printf format for dbus_uid_t
#define DBUS_GID_FORMAT   "%lu"
 an appropriate printf format for dbus_gid_t
#define _DBUS_POLLIN   0x0001
 There is data to read.
#define _DBUS_POLLPRI   0x0002
 There is urgent data to read.
#define _DBUS_POLLOUT   0x0004
 Writing now will not block.
#define _DBUS_POLLERR   0x0008
 Error condition.
#define _DBUS_POLLHUP   0x0010
 Hung up.
#define _DBUS_POLLNVAL   0x0020
 Invalid request: fd not open.
#define _DBUS_BYTE_OF_PRIMITIVE(p, i)   (((const char*)&(p))[(i)])
 Casts a primitive C type to a byte array and then indexes a particular byte of the array.
#define _DBUS_DOUBLES_BITWISE_EQUAL(a, b)
 On x86 there is an 80-bit FPU, and if you do "a == b" it may have a or b in an 80-bit register, thus failing to compare the two 64-bit doubles for bitwise equality.

Typedefs

typedef unsigned long dbus_pid_t
 A process ID.
typedef unsigned long dbus_uid_t
 A user ID.
typedef unsigned long dbus_gid_t
 A group ID.
typedef DBusUserInfo DBusUserInfo
 Information about a UNIX user.
typedef DBusGroupInfo DBusGroupInfo
 Information about a UNIX group.
typedef DBusAtomic DBusAtomic
 Opaque type representing an atomically-modifiable integer that can be used from multiple threads.
typedef DBusDirIter DBusDirIter
 Opaque type for reading a directory listing.
typedef void(*) DBusSignalHandler (int sig)
 A UNIX signal handler.
typedef DBusGUID DBusGUID
 Type representing a universally unique ID.

Functions

void _dbus_abort (void)
 Aborts the program with SIGABRT (dumping core).
dbus_bool_t _dbus_setenv (const char *varname, const char *value)
 Wrapper for setenv().
const char * _dbus_getenv (const char *varname)
 Wrapper for getenv().
dbus_bool_t _dbus_open_tcp_socket (int *fd, DBusError *error)
 Socket interface.
dbus_bool_t _dbus_close_socket (int fd, DBusError *error)
 Closes a socket.
int _dbus_read_socket (int fd, DBusString *buffer, int count)
 Like _dbus_read(), but only works on sockets so is available on Windows.
int _dbus_write_socket (int fd, const DBusString *buffer, int start, int len)
 Like _dbus_write(), but only supports sockets and is thus available on Windows.
int _dbus_write_socket_two (int fd, const DBusString *buffer1, int start1, int len1, const DBusString *buffer2, int start2, int len2)
 Like _dbus_write_two() but only works on sockets and is thus available on Windows.
int _dbus_connect_tcp_socket (const char *host, dbus_uint32_t port, DBusError *error)
 Creates a socket and connects to a socket at the given host and port.
int _dbus_listen_tcp_socket (const char *host, dbus_uint32_t port, DBusError *error)
 Creates a socket and binds it to the given path, then listens on the socket.
int _dbus_accept (int listen_fd)
 Accepts a connection on a listening socket.
dbus_bool_t _dbus_read_credentials_unix_socket (int client_fd, DBusCredentials *credentials, DBusError *error)
 Reads a single byte which must be nul (an error occurs otherwise), and reads unix credentials if available.
dbus_bool_t _dbus_send_credentials_unix_socket (int server_fd, DBusError *error)
 Sends a single nul byte with our UNIX credentials as ancillary data.
void _dbus_credentials_clear (DBusCredentials *credentials)
 Sets fields in DBusCredentials to DBUS_PID_UNSET, DBUS_UID_UNSET, DBUS_GID_UNSET.
void _dbus_credentials_from_current_process (DBusCredentials *credentials)
 Gets the credentials of the current process.
dbus_bool_t _dbus_credentials_match (const DBusCredentials *expected_credentials, const DBusCredentials *provided_credentials)
 Checks whether the provided_credentials are allowed to log in as the expected_credentials.
dbus_bool_t _dbus_user_info_fill (DBusUserInfo *info, const DBusString *username, DBusError *error)
 Gets user info for the given username.
dbus_bool_t _dbus_user_info_fill_uid (DBusUserInfo *info, dbus_uid_t uid, DBusError *error)
 Gets user info for the given user ID.
void _dbus_user_info_free (DBusUserInfo *info)
 Frees the members of info (but not info itself).
dbus_bool_t _dbus_group_info_fill (DBusGroupInfo *info, const DBusString *groupname, DBusError *error)
 Initializes the given DBusGroupInfo struct with information about the given group name.
dbus_bool_t _dbus_group_info_fill_gid (DBusGroupInfo *info, dbus_gid_t gid, DBusError *error)
 Initializes the given DBusGroupInfo struct with information about the given group ID.
void _dbus_group_info_free (DBusGroupInfo *info)
 Frees the members of info (but not info itself).
unsigned long _dbus_getpid (void)
 Gets our process ID.
dbus_uid_t _dbus_getuid (void)
 Gets our UID.
dbus_gid_t _dbus_getgid (void)
dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic)
 Atomically increments an integer.
dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic)
 Atomically decrement an integer.
int _dbus_poll (DBusPollFD *fds, int n_fds, int timeout_milliseconds)
 Wrapper for poll().
void _dbus_sleep_milliseconds (int milliseconds)
 Sleeps the given number of milliseconds.
void _dbus_get_current_time (long *tv_sec, long *tv_usec)
 Get current time, as in gettimeofday().
dbus_bool_t _dbus_file_exists (const char *file)
 File/directory interface.
dbus_bool_t _dbus_file_get_contents (DBusString *str, const DBusString *filename, DBusError *error)
 Appends the contents of the given file to the string, returning error code.
dbus_bool_t _dbus_string_save_to_file (const DBusString *str, const DBusString *filename, DBusError *error)
 Writes a string out to a file.
dbus_bool_t _dbus_make_file_world_readable (const DBusString *filename, DBusError *error)
 Makes the file readable by every user in the system.
dbus_bool_t _dbus_create_file_exclusively (const DBusString *filename, DBusError *error)
 Creates the given file, failing if the file already exists.
dbus_bool_t _dbus_delete_file (const DBusString *filename, DBusError *error)
 Deletes the given file.
dbus_bool_t _dbus_create_directory (const DBusString *filename, DBusError *error)
 Creates a directory; succeeds if the directory is created or already existed.
dbus_bool_t _dbus_delete_directory (const DBusString *filename, DBusError *error)
 Removes a directory; Directory must be empty.
dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir, const DBusString *next_component)
 Appends the given filename to the given directory.
dbus_bool_t _dbus_string_get_dirname (const DBusString *filename, DBusString *dirname)
 Get the directory name from a complete filename.
dbus_bool_t _dbus_path_is_absolute (const DBusString *filename)
 Checks whether the filename is an absolute path.
dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs)
 Returns the standard directories for a session bus to look for service activation files.
DBusDirIter_dbus_directory_open (const DBusString *filename, DBusError *error)
 Open a directory to iterate over.
dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter, DBusString *filename, DBusError *error)
 Get next file in the directory.
void _dbus_directory_close (DBusDirIter *iter)
 Closes a directory iteration.
dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error)
 Checks to make sure the given directory is private to the user.
void _dbus_fd_set_close_on_exec (int fd)
 Sets the file descriptor to be close on exec.
const char * _dbus_get_tmpdir (void)
 Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order.
void _dbus_generate_pseudorandom_bytes_buffer (char *buffer, int n_bytes)
 Random numbers.
void _dbus_generate_random_bytes_buffer (char *buffer, int n_bytes)
 Fills n_bytes of the given buffer with random bytes.
dbus_bool_t _dbus_generate_random_bytes (DBusString *str, int n_bytes)
 Generates the given number of random bytes, using the best mechanism we can come up with.
dbus_bool_t _dbus_generate_random_ascii (DBusString *str, int n_bytes)
 Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII subset.
const char * _dbus_error_from_errno (int error_number)
 Converts a UNIX or Windows errno into a DBusError name.
void _dbus_disable_sigpipe (void)
 signal (SIGPIPE, SIG_IGN);
void _dbus_exit (int code) _DBUS_GNUC_NORETURN
 Exit the process, returning the given value.
int _dbus_printf_string_upper_bound (const char *format, va_list args)
 Measure the length of the given format string and arguments, not including the terminating nul.
dbus_bool_t _dbus_stat (const DBusString *filename, DBusStat *statbuf, DBusError *error)
 stat() wrapper.
dbus_bool_t _dbus_full_duplex_pipe (int *fd1, int *fd2, dbus_bool_t blocking, DBusError *error)
 Creates a full-duplex pipe (as in socketpair()).
void _dbus_print_backtrace (void)
 On GNU libc systems, print a crude backtrace to stderr.
dbus_bool_t _dbus_become_daemon (const DBusString *pidfile, int print_pid_fd, DBusError *error)
 Does the chdir, fork, setsid, etc.
dbus_bool_t _dbus_write_pid_file (const DBusString *filename, unsigned long pid, DBusError *error)
 Creates a file containing the process ID.
dbus_bool_t _dbus_change_identity (unsigned long uid, unsigned long gid, DBusError *error)
 Changes the user and group the bus is running as.
void _dbus_set_signal_handler (int sig, DBusSignalHandler handler)
 Installs a UNIX signal handler.
dbus_bool_t _dbus_user_at_console (const char *username, DBusError *error)
 Checks if user is at the console.
dbus_bool_t _dbus_parse_uid (const DBusString *uid_str, dbus_uid_t *uid)
 Gets a UID from a UID string.
dbus_bool_t _dbus_get_autolaunch_address (DBusString *address, DBusError *error)
 Determines the address of the session bus by querying a platform-specific method.
dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id, dbus_bool_t create_if_not_found, DBusError *error)
 Reads the uuid of the machine we're running on from the dbus configuration.
dbus_bool_t _dbus_threads_init_platform_specific (void)
 Initialize threads as in dbus_threads_init_default(), appropriately for the platform.

Detailed Description

Internal system-dependent API available on UNIX and Windows.

The system-dependent API has a dual purpose. First, it encapsulates all usage of operating system APIs for ease of auditing and to avoid cluttering the rest of the code with bizarre OS quirks and headers. Second, it abstracts different operating system APIs for portability.


Define Documentation

#define _DBUS_DOUBLES_BITWISE_EQUAL ( a,
 ) 

Value:

On x86 there is an 80-bit FPU, and if you do "a == b" it may have a or b in an 80-bit register, thus failing to compare the two 64-bit doubles for bitwise equality.

So this macro compares the two doubles bitwise.

Definition at line 414 of file dbus-sysdeps.h.


Typedef Documentation

typedef union DBusGUID DBusGUID

Type representing a universally unique ID.

Todo:
rename to UUID instead of GUID

Definition at line 433 of file dbus-sysdeps.h.


Function Documentation

int _dbus_accept ( int  listen_fd  ) 

Accepts a connection on a listening socket.

Handles EINTR for you.

Parameters:
listen_fd the listen file descriptor
Returns:
the connection fd of the client, or -1 on error

Definition at line 1101 of file dbus-sysdeps-unix.c.

dbus_int32_t _dbus_atomic_dec ( DBusAtomic atomic  ) 

Atomically decrement an integer.

Parameters:
atomic pointer to the integer to decrement
Returns:
the value before decrementing
Todo:
implement arch-specific faster atomic ops

Definition at line 697 of file dbus-sysdeps.c.

References _DBUS_LOCK, _DBUS_UNLOCK, and DBusAtomic::value.

Referenced by _dbus_connection_unref_unlocked(), _dbus_server_unref_unlocked(), dbus_connection_unref(), dbus_free(), dbus_message_unref(), dbus_pending_call_unref(), and dbus_server_unref().

dbus_int32_t _dbus_atomic_inc ( DBusAtomic atomic  ) 

Atomically increments an integer.

Parameters:
atomic pointer to the integer to increment
Returns:
the value before incrementing
Todo:
implement arch-specific faster atomic ops

Definition at line 674 of file dbus-sysdeps.c.

References _DBUS_LOCK, _DBUS_UNLOCK, and DBusAtomic::value.

Referenced by _dbus_connection_ref_unlocked(), _dbus_server_ref_unlocked(), dbus_connection_ref(), dbus_malloc(), dbus_malloc0(), dbus_message_ref(), dbus_pending_call_ref(), dbus_realloc(), and dbus_server_ref().

dbus_bool_t _dbus_become_daemon ( const DBusString pidfile,
int  print_pid_fd,
DBusError error 
)

Does the chdir, fork, setsid, etc.

to become a daemon process.

Parameters:
pidfile NULL, or pidfile to create
print_pid_fd file descriptor to print daemon's pid to, or -1 for none
error return location for errors
Returns:
FALSE on failure

Definition at line 70 of file dbus-sysdeps-util-unix.c.

References _dbus_assert_not_reached, _dbus_error_from_errno(), _dbus_getenv(), _dbus_string_append(), _dbus_string_append_int(), _dbus_string_free(), _dbus_string_init(), _dbus_write_pid_file(), _dbus_write_socket(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

dbus_bool_t _dbus_change_identity ( dbus_uid_t  uid,
dbus_gid_t  gid,
DBusError error 
)

Changes the user and group the bus is running as.

Parameters:
uid the new user ID
gid the new group ID
error return location for errors
Returns:
FALSE on failure

Definition at line 254 of file dbus-sysdeps-util-unix.c.

References _dbus_error_from_errno(), dbus_set_error(), FALSE, NULL, and TRUE.

dbus_bool_t _dbus_check_dir_is_private_to_user ( DBusString dir,
DBusError error 
)

Checks to make sure the given directory is private to the user.

Parameters:
dir the name of the directory
error error return
Returns:
FALSE on failure

Definition at line 1130 of file dbus-sysdeps-unix.c.

References _dbus_error_from_errno(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, and TRUE.

dbus_bool_t _dbus_close_socket ( int  fd,
DBusError error 
)

Closes a socket.

Should not be used on non-socket file descriptors or handles.

Parameters:
fd the socket
error return location for an error
Returns:
FALSE if error is set

Definition at line 130 of file dbus-sysdeps-unix.c.

References _dbus_close().

Referenced by _dbus_babysitter_unref(), _dbus_server_new_for_domain_socket(), _dbus_server_new_for_tcp_socket(), _dbus_transport_new_for_domain_socket(), and _dbus_transport_new_for_tcp_socket().

dbus_bool_t _dbus_concat_dir_and_file ( DBusString dir,
const DBusString next_component 
)

Appends the given filename to the given directory.

Todo:
it might be cute to collapse multiple '/' such as "foo//" concat "//bar"
Parameters:
dir the directory name
next_component the filename
Returns:
TRUE on success

Definition at line 1949 of file dbus-sysdeps-unix.c.

References _dbus_string_append_byte(), _dbus_string_copy(), _dbus_string_shorten(), FALSE, and TRUE.

Referenced by _dbus_get_standard_session_servicedirs(), _dbus_keyring_new_homedir(), and _dbus_server_listen_platform_specific().

int _dbus_connect_tcp_socket ( const char *  host,
dbus_uint32_t  port,
DBusError error 
)

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.

Parameters:
host the host name to connect to
port the prot to connect to
error return location for error code
Returns:
connection file descriptor or -1 on error

Definition at line 691 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), _dbus_open_tcp_socket(), _DBUS_ZERO, dbus_set_error(), and NULL.

Referenced by _dbus_transport_new_for_tcp_socket().

dbus_bool_t _dbus_create_directory ( const DBusString filename,
DBusError error 
)

Creates a directory; succeeds if the directory is created or already existed.

Parameters:
filename directory filename
error initialized error object
Returns:
TRUE on success

Definition at line 1915 of file dbus-sysdeps-unix.c.

References DBUS_ERROR_FAILED, dbus_set_error(), FALSE, and TRUE.

Referenced by _dbus_keyring_new_homedir().

dbus_bool_t _dbus_create_file_exclusively ( const DBusString filename,
DBusError error 
)

Creates the given file, failing if the file already exists.

Parameters:
filename the filename
error error location
Returns:
TRUE if we created the file and it didn't exist

Definition at line 1842 of file dbus-sysdeps-unix.c.

References _dbus_close(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

void _dbus_credentials_clear ( DBusCredentials credentials  ) 

Sets fields in DBusCredentials to DBUS_PID_UNSET, DBUS_UID_UNSET, DBUS_GID_UNSET.

Parameters:
credentials the credentials object to fill in

Definition at line 616 of file dbus-sysdeps.c.

References DBUS_GID_UNSET, DBUS_PID_UNSET, DBUS_UID_UNSET, DBusCredentials::gid, DBusCredentials::pid, and DBusCredentials::uid.

Referenced by _dbus_auth_get_identity(), and _dbus_read_credentials_unix_socket().

void _dbus_credentials_from_current_process ( DBusCredentials credentials  ) 

Gets the credentials of the current process.

Parameters:
credentials credentials to fill in.

Definition at line 1397 of file dbus-sysdeps-unix.c.

References _dbus_assert, DBusCredentials::gid, DBusCredentials::pid, and DBusCredentials::uid.

Referenced by _dbus_transport_get_is_authenticated().

dbus_bool_t _dbus_credentials_match ( const DBusCredentials expected_credentials,
const DBusCredentials provided_credentials 
)

Checks whether the provided_credentials are allowed to log in as the expected_credentials.

Parameters:
expected_credentials credentials we're trying to log in as
provided_credentials credentials we have
Returns:
TRUE if we can log in

Definition at line 632 of file dbus-sysdeps.c.

References DBUS_UID_UNSET, FALSE, TRUE, and DBusCredentials::uid.

Referenced by _dbus_transport_get_is_authenticated().

dbus_bool_t _dbus_delete_directory ( const DBusString filename,
DBusError error 
)

Removes a directory; Directory must be empty.

Parameters:
filename directory filename
error initialized error object
Returns:
TRUE on success

Definition at line 325 of file dbus-sysdeps-util-unix.c.

References DBUS_ERROR_FAILED, dbus_set_error(), FALSE, and TRUE.

dbus_bool_t _dbus_delete_file ( const DBusString filename,
DBusError error 
)

Deletes the given file.

Parameters:
filename the filename
error error location
Returns:
TRUE if unlink() succeeded

Definition at line 1886 of file dbus-sysdeps-unix.c.

References DBUS_ERROR_FAILED, dbus_set_error(), FALSE, and TRUE.

dbus_bool_t _dbus_directory_get_next_file ( DBusDirIter iter,
DBusString filename,
DBusError error 
)

Get next file in the directory.

Will not return "." or ".." on UNIX. If an error occurs, the contents of "filename" are undefined. The error is never set if the function succeeds.

Parameters:
iter the iterator
filename string to be set to the next file in the dir
error return location for error
Returns:
TRUE if filename was filled in with a new filename

Definition at line 561 of file dbus-sysdeps-util-unix.c.

References _dbus_error_from_errno(), _dbus_string_append(), _dbus_string_set_length(), DBusDirIter::d, DBUS_ERROR_FAILED, DBUS_ERROR_NO_MEMORY, dbus_free(), dbus_malloc(), dbus_set_error(), FALSE, and TRUE.

DBusDirIter* _dbus_directory_open ( const DBusString filename,
DBusError error 
)

Open a directory to iterate over.

Parameters:
filename the directory name
error exception return object or NULL
Returns:
new iterator, or NULL on error

Definition at line 471 of file dbus-sysdeps-util-unix.c.

References _dbus_error_from_errno(), DBusDirIter::d, DBUS_ERROR_NO_MEMORY, dbus_new0, dbus_set_error(), and NULL.

const char* _dbus_error_from_errno ( int  error_number  ) 

Converts a UNIX or Windows errno into a DBusError name.

Todo:
should cover more errnos, specifically those from open().
Parameters:
error_number the errno.
Returns:
an error name

Definition at line 859 of file dbus-sysdeps.c.

References DBUS_ERROR_ACCESS_DENIED, DBUS_ERROR_ADDRESS_IN_USE, DBUS_ERROR_FAILED, DBUS_ERROR_FILE_EXISTS, DBUS_ERROR_FILE_NOT_FOUND, DBUS_ERROR_LIMITS_EXCEEDED, DBUS_ERROR_NO_MEMORY, DBUS_ERROR_NO_NETWORK, DBUS_ERROR_NO_SERVER, DBUS_ERROR_NOT_SUPPORTED, and DBUS_ERROR_TIMEOUT.

Referenced by _dbus_become_daemon(), _dbus_change_identity(), _dbus_check_dir_is_private_to_user(), _dbus_close(), _dbus_connect_tcp_socket(), _dbus_connect_unix_socket(), _dbus_directory_get_next_file(), _dbus_directory_open(), _dbus_file_get_contents(), _dbus_full_duplex_pipe(), _dbus_get_autolaunch_address(), _dbus_listen_tcp_socket(), _dbus_listen_unix_socket(), _dbus_read_credentials_unix_socket(), _dbus_stat(), _dbus_string_save_to_file(), and _dbus_write_pid_file().

void _dbus_exit ( int  code  ) 

Exit the process, returning the given value.

Parameters:
code the exit code

Definition at line 2083 of file dbus-sysdeps-unix.c.

Referenced by _dbus_abort().

void _dbus_fd_set_close_on_exec ( int  fd  ) 

Sets the file descriptor to be close on exec.

Should be called for all file descriptors in D-Bus code.

Parameters:
fd the file descriptor

Definition at line 2124 of file dbus-sysdeps-unix.c.

Referenced by _dbus_server_new_for_domain_socket(), _dbus_server_new_for_tcp_socket(), _dbus_spawn_async_with_babysitter(), _dbus_transport_new_for_domain_socket(), and _dbus_transport_new_for_tcp_socket().

dbus_bool_t _dbus_file_exists ( const char *  file  ) 

File/directory interface.

Parameters:
file full path to the file
Returns:
TRUE if file exists

Definition at line 351 of file dbus-sysdeps-util-unix.c.

Referenced by _dbus_user_at_console().

dbus_bool_t _dbus_file_get_contents ( DBusString str,
const DBusString filename,
DBusError error 
)

Appends the contents of the given file to the string, returning error code.

At the moment, won't open a file more than a megabyte in size.

Parameters:
str the string to append to
filename filename to load
error place to set an error
Returns:
FALSE if error was set

Definition at line 1573 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), _dbus_read(), _dbus_string_set_length(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

dbus_bool_t _dbus_full_duplex_pipe ( int *  fd1,
int *  fd2,
dbus_bool_t  blocking,
DBusError error 
)

Creates a full-duplex pipe (as in socketpair()).

Sets both ends of the pipe nonblocking.

Todo:
libdbus only uses this for the debug-pipe server, so in 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.
Parameters:
fd1 return location for one end
fd2 return location for the other end
blocking TRUE if pipe should be blocking
error error return
Returns:
FALSE on failure (if error is set)

Definition at line 2256 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), _dbus_warn(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

Referenced by _dbus_spawn_async_with_babysitter().

dbus_bool_t _dbus_generate_random_ascii ( DBusString str,
int  n_bytes 
)

Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII subset.

Parameters:
str the string
n_bytes the number of random ASCII bytes to append to string
Returns:
TRUE on success, FALSE if no memory or other failure

Definition at line 780 of file dbus-sysdeps.c.

References _dbus_assert, _dbus_generate_random_bytes(), _dbus_string_validate_ascii(), FALSE, and TRUE.

Referenced by _dbus_server_listen_platform_specific(), and _dbus_string_save_to_file().

dbus_bool_t _dbus_generate_random_bytes ( DBusString str,
int  n_bytes 
)

Generates the given number of random bytes, using the best mechanism we can come up with.

Parameters:
str the string
n_bytes the number of random bytes to append to string
Returns:
TRUE on success, FALSE if no memory

Definition at line 2042 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_read(), _dbus_string_set_length(), NULL, and TRUE.

Referenced by _dbus_generate_random_ascii(), and _dbus_generate_random_bytes_buffer().

void _dbus_generate_random_bytes_buffer ( char *  buffer,
int  n_bytes 
)

Fills n_bytes of the given buffer with random bytes.

Parameters:
buffer an allocated buffer
n_bytes the number of bytes in buffer to write to

Definition at line 748 of file dbus-sysdeps.c.

References _dbus_generate_pseudorandom_bytes_buffer(), _dbus_generate_random_bytes(), _dbus_string_copy_to_buffer(), _dbus_string_free(), and _dbus_string_init().

Referenced by _dbus_generate_uuid().

dbus_bool_t _dbus_get_autolaunch_address ( DBusString address,
DBusError error 
)

Determines the address of the session bus by querying a platform-specific method.

If successful, returns TRUE and appends the address to address. If a failure happens, returns FALSE and sets an error in error.

Parameters:
address a DBusString where the address can be stored
error a DBusError to store the error in case of failure
Returns:
TRUE on success, FALSE if an error happened

Definition at line 2369 of file dbus-sysdeps-unix.c.

References _dbus_assert, _dbus_error_from_errno(), _dbus_get_local_machine_uuid_encoded(), _DBUS_N_ELEMENTS, _dbus_read(), _dbus_string_free(), _dbus_string_init(), _dbus_string_set_length(), DBUS_ERROR_SPAWN_EXEC_FAILED, dbus_set_error(), FALSE, NULL, READ_END, TRUE, and WRITE_END.

void _dbus_get_current_time ( long *  tv_sec,
long *  tv_usec 
)

Get current time, as in gettimeofday().

Parameters:
tv_sec return location for number of seconds
tv_usec return location for number of microseconds (thousandths)

Definition at line 1549 of file dbus-sysdeps-unix.c.

References NULL.

Referenced by _dbus_connection_block_pending_call(), _dbus_generate_pseudorandom_bytes_buffer(), and _dbus_generate_uuid().

dbus_bool_t _dbus_get_standard_session_servicedirs ( DBusList **  dirs  ) 

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:

XDG_DATA_HOME=${XDG_DATA_HOME-$HOME/.local/share} XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}

and

DBUS_DATADIR

Parameters:
dirs the directory list we are returning
Returns:
FALSE on OOM

Definition at line 2668 of file dbus-sysdeps-unix.c.

References _dbus_concat_dir_and_file(), _dbus_getenv(), _dbus_homedir_from_current_process(), _dbus_string_append(), _dbus_string_free(), _dbus_string_init(), _dbus_string_init_const(), FALSE, NULL, and TRUE.

const char* _dbus_get_tmpdir ( void   ) 

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

Definition at line 2325 of file dbus-sysdeps-unix.c.

References _dbus_assert, and NULL.

const char * _dbus_getenv ( const char *  varname  ) 

Wrapper for getenv().

Parameters:
varname name of environment variable
Returns:
value of environment variable or NULL if unset

Definition at line 170 of file dbus-sysdeps.c.

Referenced by _dbus_abort(), _dbus_become_daemon(), _dbus_get_standard_session_servicedirs(), and _dbus_keyring_new_homedir().

unsigned long _dbus_getpid ( void   ) 

Gets our process ID.

Returns:
process ID

Definition at line 1417 of file dbus-sysdeps-unix.c.

Referenced by _dbus_abort(), and _dbus_warn_check_failed().

dbus_uid_t _dbus_getuid ( void   ) 

Gets our UID.

Returns:
process UID

Definition at line 1426 of file dbus-sysdeps-unix.c.

dbus_bool_t _dbus_group_info_fill ( DBusGroupInfo info,
const DBusString groupname,
DBusError error 
)

Initializes the given DBusGroupInfo struct with information about the given group name.

Parameters:
info the group info struct
groupname name of group
error the error return
Returns:
FALSE if error is set

Definition at line 736 of file dbus-sysdeps-util-unix.c.

References DBUS_GID_UNSET.

Referenced by _dbus_user_database_lookup_group().

dbus_bool_t _dbus_group_info_fill_gid ( DBusGroupInfo info,
dbus_gid_t  gid,
DBusError error 
)

Initializes the given DBusGroupInfo struct with information about the given group ID.

Parameters:
info the group info struct
gid group ID
error the error return
Returns:
FALSE if error is set

Definition at line 755 of file dbus-sysdeps-util-unix.c.

References NULL.

Referenced by _dbus_user_database_lookup_group().

void _dbus_group_info_free ( DBusGroupInfo info  ) 

Frees the members of info (but not info itself).

Parameters:
info the group info

Definition at line 604 of file dbus-sysdeps.c.

References dbus_free(), and DBusGroupInfo::groupname.

Referenced by _dbus_group_info_free_allocated().

int _dbus_listen_tcp_socket ( const char *  host,
dbus_uint32_t  port,
DBusError error 
)

Creates a socket and binds it to the given path, then listens on the socket.

The socket is set to be nonblocking.

Parameters:
host the host name to listen on
port the prot to listen on
error return location for errors
Returns:
the listening file descriptor or -1 on error

Definition at line 767 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), _dbus_open_tcp_socket(), _DBUS_ZERO, dbus_set_error(), and NULL.

Referenced by _dbus_server_new_for_tcp_socket().

dbus_bool_t _dbus_make_file_world_readable ( const DBusString filename,
DBusError error 
)

Makes the file readable by every user in the system.

Parameters:
filename the filename
error error location
Returns:
TRUE if the file's permissions could be changed.

Definition at line 1815 of file dbus-sysdeps-unix.c.

References DBUS_ERROR_FAILED, dbus_set_error(), FALSE, and TRUE.

dbus_bool_t _dbus_open_tcp_socket ( int *  fd,
DBusError error 
)

Socket interface.

Todo:
Use for the file descriptors a struct
  • struct DBusSocket{ int d; }; - instead of int to get type-safety which will be checked by the compiler.

Definition at line 101 of file dbus-sysdeps-unix.c.

Referenced by _dbus_connect_tcp_socket(), and _dbus_listen_tcp_socket().

dbus_bool_t _dbus_parse_uid ( const DBusString uid_str,
dbus_uid_t uid 
)

Gets a UID from a UID string.

Parameters:
uid_str the UID in string form
uid UID to fill in
Returns:
TRUE if successfully filled in UID

Definition at line 816 of file dbus-sysdeps.c.

References _dbus_string_parse_int(), FALSE, and TRUE.

dbus_bool_t _dbus_path_is_absolute ( const DBusString filename  ) 

Checks whether the filename is an absolute path.

Parameters:
filename the filename
Returns:
TRUE if an absolute path

Definition at line 406 of file dbus-sysdeps-util-unix.c.

References FALSE.

int _dbus_poll ( DBusPollFD fds,
int  n_fds,
int  timeout_milliseconds 
)

Wrapper for poll().

Parameters:
fds the file descriptors to poll
n_fds number of descriptors in the array
timeout_milliseconds timeout or -1 for infinite
Returns:
numbers of fds with revents, or <0 on error

Definition at line 1451 of file dbus-sysdeps-unix.c.

References _DBUS_POLLERR, _DBUS_POLLHUP, _DBUS_POLLIN, _DBUS_POLLNVAL, _DBUS_POLLOUT, _DBUS_POLLPRI, _dbus_warn(), NULL, and DBusPollFD::revents.

void _dbus_print_backtrace ( void   ) 

On GNU libc systems, print a crude backtrace to stderr.

On other systems, print "no backtrace support" and block for possible gdb attachment if an appropriate environment variable is set.

Definition at line 2211 of file dbus-sysdeps-unix.c.

Referenced by _dbus_abort().

int _dbus_printf_string_upper_bound ( const char *  format,
va_list  args 
)

Measure the length of the given format string and arguments, not including the terminating nul.

Parameters:
format a printf-style format string
args arguments for the format string
Returns:
length of the given format string and args

Definition at line 2311 of file dbus-sysdeps-unix.c.

Referenced by _dbus_string_append_printf_valist().

dbus_bool_t _dbus_read_credentials_unix_socket ( int  client_fd,
DBusCredentials credentials,
DBusError error 
)

Reads a single byte which must be nul (an error occurs otherwise), and reads unix credentials if available.

Fills in pid/uid/gid with -1 if no credentials are available. Return value indicates whether a byte was read, not whether 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 use sendmsg()/recvmsg() to transmit credentials.

Parameters:
client_fd the client file descriptor
credentials struct to fill with credentials of client
error location to store error code
Returns:
TRUE on success

Definition at line 912 of file dbus-sysdeps-unix.c.

References _dbus_assert, _dbus_credentials_clear(), _dbus_error_from_errno(), DBUS_ERROR_FAILED, DBUS_GID_FORMAT, DBUS_PID_FORMAT, DBUS_PID_UNSET, dbus_set_error(), DBUS_UID_FORMAT, FALSE, DBusCredentials::gid, NULL, DBusCredentials::pid, TRUE, and DBusCredentials::uid.

dbus_bool_t _dbus_read_local_machine_uuid ( DBusGUID machine_id,
dbus_bool_t  create_if_not_found,
DBusError error 
)

Reads the uuid of the machine we're running on from the dbus configuration.

Optionally try to create it (only root can do this usually).

On UNIX, reads a file that gets created by dbus-uuidgen in a post-install script. On Windows, if there's a standard machine uuid we could just use that, but I can't find one with the right properties (the hardware profile guid can change without rebooting I believe). If there's no standard one we might want to use the registry instead of a file for this, and I'm not sure how we'd ensure the uuid gets created.

Parameters:
machine_id guid to init with the machine's uuid
create_if_not_found try to create the uuid if it doesn't exist
error the error return
Returns:
FALSE if the error is set

Definition at line 2524 of file dbus-sysdeps-unix.c.

References _dbus_read_uuid_file(), and _dbus_string_init_const().

Referenced by _dbus_get_local_machine_uuid_encoded(), and dbus_internal_do_not_use_get_uuid().

int _dbus_read_socket ( int  fd,
DBusString buffer,
int  count 
)

Like _dbus_read(), but only works on sockets so is available on Windows.

Parameters:
fd the socket
buffer string to append data to
count max amount of data to read
Returns:
number of bytes appended to the string

Definition at line 146 of file dbus-sysdeps-unix.c.

References _dbus_read().

dbus_bool_t _dbus_send_credentials_unix_socket ( int  server_fd,
DBusError error 
)

Sends a single nul byte with our UNIX credentials as ancillary data.

Returns TRUE if the data was successfully written. On systems that don't support sending credentials, just writes a byte, doesn't send any 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 can be written, so you must select() first.

The point of the byte is that on some systems we have to use sendmsg()/recvmsg() to transmit credentials.

Parameters:
server_fd file descriptor for connection to server
error return location for error code
Returns:
TRUE if the byte was sent

Definition at line 1082 of file dbus-sysdeps-unix.c.

References FALSE, and TRUE.

void _dbus_set_signal_handler ( int  sig,
DBusSignalHandler  handler 
)

Installs a UNIX signal handler.

Parameters:
sig the signal to handle
handler the handler

Definition at line 303 of file dbus-sysdeps-util-unix.c.

References NULL.

dbus_bool_t _dbus_setenv ( const char *  varname,
const char *  value 
)

Wrapper for setenv().

If the value is NULL, unsets the environment variable.

There is an unfixable memleak in that it is unsafe to free memory malloced for use with setenv. This is because we can not rely on internal implementation details of the underlying libc library.

Parameters:
varname name of environment variable
value value of environment variable
Returns:
TRUE on success.

Definition at line 102 of file dbus-sysdeps.c.

References _dbus_assert, FALSE, NULL, and TRUE.

void _dbus_sleep_milliseconds ( int  milliseconds  ) 

Sleeps the given number of milliseconds.

Parameters:
milliseconds number of milliseconds

Definition at line 1994 of file dbus-sysdeps-unix.c.

Referenced by _dbus_abort().

dbus_bool_t _dbus_stat ( const DBusString filename,
DBusStat statbuf,
DBusError error 
)

stat() wrapper.

Parameters:
filename the filename to stat
statbuf the stat info to fill in
error return location for error
Returns:
FALSE if error was set

Definition at line 423 of file dbus-sysdeps-util-unix.c.

References _dbus_error_from_errno(), DBusStat::atime, DBusStat::ctime, dbus_set_error(), FALSE, DBusStat::gid, DBusStat::mode, DBusStat::mtime, DBusStat::nlink, DBusStat::size, TRUE, and DBusStat::uid.

Referenced by _dbus_is_console_user().

dbus_bool_t _dbus_string_get_dirname ( const DBusString filename,
DBusString dirname 
)

Get the directory name from a complete filename.

Parameters:
filename the filename
dirname string to append directory name to
Returns:
FALSE if no memory

Definition at line 776 of file dbus-sysdeps-util-unix.c.

References _dbus_assert, _dbus_string_append(), _dbus_string_copy_len(), _dbus_string_find_byte_backward(), and NULL.

dbus_bool_t _dbus_string_save_to_file ( const DBusString str,
const DBusString filename,
DBusError error 
)

Writes a string out to a file.

If the file exists, it will be atomically overwritten by the new data.

Parameters:
str the string to write out
filename the file to save string to
error error to be filled in on failure
Returns:
FALSE on failure

Definition at line 1679 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), _dbus_generate_random_ascii(), _dbus_string_append(), _dbus_string_copy(), _dbus_string_free(), _dbus_string_init(), _dbus_write(), DBUS_ERROR_NO_MEMORY, dbus_set_error(), FALSE, NULL, and TRUE.

dbus_bool_t _dbus_threads_init_platform_specific ( void   ) 

Initialize threads as in dbus_threads_init_default(), appropriately for the platform.

Returns:
FALSE if no memory

Definition at line 317 of file dbus-sysdeps-pthread.c.

References dbus_threads_init().

Referenced by dbus_threads_init_default().

dbus_bool_t _dbus_user_at_console ( const char *  username,
DBusError error 
)

Checks if user is at the console.

Parameters:
username user to check
error return location for errors
Returns:
TRUE is the user is at the consolei and there are no errors

Definition at line 363 of file dbus-sysdeps-util-unix.c.

References _dbus_file_exists(), _dbus_string_append(), _dbus_string_free(), _dbus_string_init(), and FALSE.

Referenced by _dbus_is_console_user().

dbus_bool_t _dbus_user_info_fill ( DBusUserInfo info,
const DBusString username,
DBusError error 
)

Gets user info for the given username.

Parameters:
info user info object to initialize
username the username
error error return
Returns:
TRUE on success

Definition at line 1366 of file dbus-sysdeps-unix.c.

References DBUS_UID_UNSET.

Referenced by _dbus_user_database_lookup().

dbus_bool_t _dbus_user_info_fill_uid ( DBusUserInfo info,
dbus_uid_t  uid,
DBusError error 
)

Gets user info for the given user ID.

Parameters:
info user info object to initialize
uid the user ID
error error return
Returns:
TRUE on success

Definition at line 1383 of file dbus-sysdeps-unix.c.

References NULL.

Referenced by _dbus_user_database_lookup().

void _dbus_user_info_free ( DBusUserInfo info  ) 

Frees the members of info (but not info itself).

Parameters:
info the user info struct

Definition at line 591 of file dbus-sysdeps.c.

References dbus_free(), DBusUserInfo::group_ids, DBusUserInfo::homedir, and DBusUserInfo::username.

Referenced by _dbus_user_info_free_allocated().

dbus_bool_t _dbus_write_pid_file ( const DBusString filename,
unsigned long  pid,
DBusError error 
)

Creates a file containing the process ID.

Parameters:
filename the filename to write to
pid our process ID
error return location for errors
Returns:
FALSE on failure

Definition at line 195 of file dbus-sysdeps-util-unix.c.

References _dbus_close(), _dbus_error_from_errno(), dbus_set_error(), FALSE, NULL, and TRUE.

Referenced by _dbus_become_daemon().

int _dbus_write_socket ( int  fd,
const DBusString buffer,
int  start,
int  len 
)

Like _dbus_write(), but only supports sockets and is thus available on Windows.

Parameters:
fd the file descriptor to write
buffer the buffer to write data from
start the first byte in the buffer to write
len the number of bytes to try to write
Returns:
the number of bytes written or -1 on error

Definition at line 164 of file dbus-sysdeps-unix.c.

References _dbus_write().

Referenced by _dbus_become_daemon().

int _dbus_write_socket_two ( int  fd,
const DBusString buffer1,
int  start1,
int  len1,
const DBusString buffer2,
int  start2,
int  len2 
)

Like _dbus_write_two() but only works on sockets and is thus available on Windows.

Parameters:
fd the file descriptor
buffer1 first buffer
start1 first byte to write in first buffer
len1 number of bytes to write from first buffer
buffer2 second buffer, or NULL
start2 first byte to write in second buffer
len2 number of bytes to write in second buffer
Returns:
total bytes written from both buffers, or -1 on error

Definition at line 186 of file dbus-sysdeps-unix.c.

References _dbus_write_two().


Generated on Fri Sep 21 18:12:15 2007 for D-Bus by  doxygen 1.5.1