Utilities and portability
D-Bus secret internal implementation details

Utility functions (_dbus_assert(), _dbus_warn(), etc.) More...

## Data Structures

struct | DBusBabysitter
| Babysitter implementation details. More...
struct | DBusDirIter
| Internals of directory iterator. More...

## Macros

#define | _dbus_assert(condition) _dbus_real_assert ((condition) != 0, #condition, __FILE__, __LINE__, _DBUS_FUNCTION_NAME)
| Aborts with an error message if the condition is false. More...
#define | _dbus_assert_not_reached(explanation) _dbus_real_assert_not_reached (explanation, __FILE__, __LINE__)
| Aborts with an error message if called. More...
#define | _DBUS_N_ELEMENTS(array) ((int) (sizeof ((array)) / sizeof ((array)[0])))
| Computes the number of elements in a fixed-size array using sizeof(). More...
#define | _DBUS_POINTER_TO_INT(pointer) ((intptr_t)(pointer))
| Safely casts a void* to an integer; should only be used on void* that actually contain integers, for example one created with _DBUS_INT_TO_POINTER. More...
#define | _DBUS_INT_TO_POINTER(integer) ((void*)((intptr_t)(integer)))
| Safely stuffs an integer into a pointer, to be extracted later with _DBUS_POINTER_TO_INT. More...
#define | _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
| Sets all bits in an object to zero. More...
#define | _DBUS_INT16_MIN ((dbus_int16_t) 0x8000)
| Minimum value of type "int16".
#define | _DBUS_INT16_MAX ((dbus_int16_t) 0x7fff)
| Maximum value of type "int16".
#define | _DBUS_UINT16_MAX ((dbus_uint16_t)0xffff)
| Maximum value of type "uint16".
#define | _DBUS_INT32_MIN ((dbus_int32_t) 0x80000000)
| Minimum value of type "int32".
#define | _DBUS_INT32_MAX ((dbus_int32_t) 0x7fffffff)
| Maximum value of type "int32".
#define | _DBUS_UINT32_MAX ((dbus_uint32_t)0xffffffff)
| Maximum value of type "uint32".
#define | _DBUS_INT_MIN _DBUS_INT32_MIN
| Minimum value of type "int".
#define | _DBUS_INT_MAX _DBUS_INT32_MAX
| Maximum value of type "int".
#define | _DBUS_UINT_MAX _DBUS_UINT32_MAX
| Maximum value of type "uint".
#define | _DBUS_LOCK_NAME(name) _dbus_lock_##name
| Expands to name of a global lock variable.
#define | _DBUS_DEFINE_GLOBAL_LOCK(name) DBusRMutex *_dbus_lock_##name
| Defines a global lock variable with the given name. More...
#define | _DBUS_DECLARE_GLOBAL_LOCK(name) extern DBusRMutex *_dbus_lock_##name
| Expands to declaration of a global lock defined with _DBUS_DEFINE_GLOBAL_LOCK. More...
#define | _DBUS_LOCK(name) _dbus_rmutex_lock (_dbus_lock_##name)
| Locks a global lock.
#define | _DBUS_UNLOCK(name) _dbus_rmutex_unlock (_dbus_lock_##name)
| Unlocks a global lock.
#define | LIVE_CHILDREN(sitter) ((sitter)->socket_to_babysitter >= 0 || (sitter)->error_pipe_from_child >= 0)
| Macro returns TRUE if the babysitter still has live sockets open to the babysitter child or the grandchild.
#define | READ_END 0
| Helps remember which end of the pipe is which.
#define | WRITE_END 1
| Helps remember which end of the pipe is which.

## Typedefs

typedef void(* | DBusForeachFunction )(void *element, void *data)
| Used to iterate over each item in a collection, such as a DBusList.

## Enumerations

enum | ReadStatus { READ_STATUS_OK, READ_STATUS_ERROR, READ_STATUS_EOF }
| Enumeration for status of a read() More...
enum | { CHILD_EXITED, CHILD_FORK_FAILED, CHILD_EXEC_FAILED, CHILD_PID }

## Functions

void | _dbus_warn (const char *format,...)
| Prints a warning message to stderr. More...
void | _dbus_warn_check_failed (const char *format,...)
| Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in that it prefixes the pid and defaults to fatal. More...
char * | _dbus_strdup (const char *str)
| Duplicates a string. More...
void * | _dbus_memdup (const void *mem, size_t n_bytes)
| Duplicates a block of memory. More...
char ** | _dbus_dup_string_array (const char **array)
| Duplicates a string array. More...
dbus_bool_t | _dbus_string_array_contains (const char **array, const char *str)
| Checks whether a string array contains the given string. More...
void | _dbus_generate_uuid (DBusGUID *uuid)
| Generates a new UUID. More...
dbus_bool_t | _dbus_uuid_encode (const DBusGUID *uuid, DBusString *encoded)
| Hex-encode a UUID. More...
dbus_bool_t | _dbus_read_uuid_file (const DBusString *filename, DBusGUID *uuid, dbus_bool_t create_if_not_found, DBusError *error)
| Reads (and optionally writes) a uuid to a file. More...
dbus_bool_t | _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str)
| Gets the hex-encoded UUID of the machine this function is executed on. More...
void | _dbus_real_assert (dbus_bool_t condition, const char *condition_text, const char *file, int line, const char *func)
| Internals of _dbus_assert(); it's a function rather than a macro with the inline code so that the assertion failure blocks don't show up in test suite coverage, and to shrink code size. More...
void | _dbus_real_assert_not_reached (const char *explanation, const char *file, int line)
| Internals of _dbus_assert_not_reached(); it's a function rather than a macro with the inline code so that the assertion failure blocks don't show up in test suite coverage, and to shrink code size. More...
DBusBabysitter * | _dbus_babysitter_ref (DBusBabysitter *sitter)
| Increment the reference count on the babysitter object. More...
void | _dbus_babysitter_unref (DBusBabysitter *sitter)
| Decrement the reference count on the babysitter object. More...
void | _dbus_babysitter_kill_child (DBusBabysitter *sitter)
| Blocks until the babysitter process gives us the PID of the spawned grandchild, then kills the spawned grandchild. More...
dbus_bool_t | _dbus_babysitter_get_child_exited (DBusBabysitter *sitter)
| Checks whether the child has exited, without blocking. More...
dbus_bool_t | _dbus_babysitter_get_child_exit_status (DBusBabysitter *sitter, int *status)
| Gets the exit status of the child. More...
void | _dbus_babysitter_set_child_exit_error (DBusBabysitter *sitter, DBusError *error)
| Sets the DBusError with an explanation of why the spawned child process exited (on a signal, or whatever). More...
dbus_bool_t | _dbus_babysitter_set_watch_functions (DBusBabysitter *sitter, DBusAddWatchFunction add_function, DBusRemoveWatchFunction remove_function, DBusWatchToggledFunction toggled_function, void *data, DBusFreeFunction free_data_function)
| Sets watch functions to notify us when the babysitter object needs to read/write file descriptors. More...
dbus_bool_t | _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, char **argv, char **env, DBusSpawnChildSetupFunc child_setup, void *user_data, DBusError *error)
| Spawns a new process. More...
void | _dbus_babysitter_set_result_function (DBusBabysitter *sitter, DBusBabysitterFinishedFunc finished, void *user_data)
dbus_bool_t | _dbus_become_daemon (const DBusString *pidfile, DBusPipe *print_pid_pipe, DBusError *error, dbus_bool_t keep_umask)
| Does the chdir, fork, setsid, etc. More...
dbus_bool_t | _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile, DBusPipe *print_pid_pipe, dbus_pid_t pid_to_write, DBusError *error)
| Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a pipe (if non-NULL). More...
dbus_bool_t | _dbus_verify_daemon_user (const char *user)
| Verify that after the fork we can successfully change to this user. More...
dbus_bool_t | _dbus_change_to_daemon_user (const char *user, DBusError *error)
| Changes the user and group the bus is running as. More...
void | _dbus_request_file_descriptor_limit (unsigned int limit)
| Attempt to ensure that the current process can open at least file descriptors. More...
void | _dbus_init_system_log (void)
void | _dbus_system_log (DBusSystemLogSeverity severity, const char *msg,...)
| Log a message to the system log file (e.g. More...
void | _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
| Log a message to the system log file (e.g. More...
void | _dbus_set_signal_handler (int sig, DBusSignalHandler handler)
| Installs a UNIX signal handler. More...
dbus_bool_t | _dbus_file_exists (const char *file)
| Checks if a file exists. More...
dbus_bool_t | _dbus_user_at_console (const char *username, DBusError *error)
| Checks if user is at the console. More...
dbus_bool_t | _dbus_path_is_absolute (const DBusString *filename)
| Checks whether the filename is an absolute path. More...
dbus_bool_t | _dbus_stat (const DBusString *filename, DBusStat *statbuf, DBusError *error)
| stat() wrapper. More...
DBusDirIter * | _dbus_directory_open (const DBusString *filename, DBusError *error)
| Open a directory to iterate over. More...
dbus_bool_t | _dbus_directory_get_next_file (DBusDirIter *iter, DBusString *filename, DBusError *error)
| Get next file in the directory. More...
void | _dbus_directory_close (DBusDirIter *iter)
| Closes a directory iteration.
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. More...
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. More...
dbus_bool_t | _dbus_parse_unix_user_from_config (const DBusString *username, dbus_uid_t *uid_p)
| Parse a UNIX user from the bus config file. More...
dbus_bool_t | _dbus_parse_unix_group_from_config (const DBusString *groupname, dbus_gid_t *gid_p)
| Parse a UNIX group from the bus config file. More...
dbus_bool_t | _dbus_unix_groups_from_uid (dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
| Gets all groups corresponding to the given UNIX user ID. More...
dbus_bool_t | _dbus_unix_user_is_at_console (dbus_uid_t uid, DBusError *error)
| Checks to see if the UNIX user ID is at the console. More...
dbus_bool_t | _dbus_unix_user_is_process_owner (dbus_uid_t uid)
| Checks to see if the UNIX user ID matches the UID of the process. More...
dbus_bool_t | _dbus_windows_user_is_process_owner (const char *windows_sid)
| Checks to see if the Windows user SID matches the owner of the process. More...
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. More...
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. More...
const char * | _dbus_error_from_errno (int error_number)
| Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name. More...
const char * | _dbus_error_from_system_errno (void)
| Converts the current system errno value into a DBusError name. More...
void | _dbus_set_errno_to_zero (void)
| Assign 0 to the global errno variable.
dbus_bool_t | _dbus_get_is_errno_nonzero (void)
| See if errno is set. More...
dbus_bool_t | _dbus_get_is_errno_enomem (void)
| See if errno is ENOMEM. More...
dbus_bool_t | _dbus_get_is_errno_eintr (void)
| See if errno is EINTR. More...
dbus_bool_t | _dbus_get_is_errno_epipe (void)
| See if errno is EPIPE. More...
const char * | _dbus_strerror_from_errno (void)
| Get error message from errno. More...
dbus_bool_t | _dbus_is_console_user (dbus_uid_t uid, DBusError *error)
| Checks to see if the UID sent in is the console user. More...
dbus_bool_t | _dbus_get_user_id (const DBusString *username, dbus_uid_t *uid)
| Gets user ID given username. More...
dbus_bool_t | _dbus_get_group_id (const DBusString *groupname, dbus_gid_t *gid)
| Gets group ID given groupname. More...
dbus_bool_t | _dbus_get_user_id_and_primary_group (const DBusString *username, dbus_uid_t *uid_p, dbus_gid_t *gid_p)
| Gets user ID and primary group given username. More...
DBusGroupInfo * | _dbus_user_database_lookup_group (DBusUserDatabase *db, dbus_gid_t gid, const DBusString *groupname, DBusError *error)
| Looks up a gid or group name in the user database. More...
dbus_bool_t | _dbus_user_database_get_groupname (DBusUserDatabase *db, const DBusString *groupname, const DBusGroupInfo **info, DBusError *error)
| Gets the user information for the given group name, returned group info should not be freed. More...
dbus_bool_t | _dbus_user_database_get_gid (DBusUserDatabase *db, dbus_gid_t gid, const DBusGroupInfo **info, DBusError *error)
| Gets the user information for the given GID, returned group info should not be freed. More...
dbus_bool_t | _dbus_groups_from_uid (dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
| Gets all groups corresponding to the given UID. More...
void | _dbus_user_info_free_allocated (DBusUserInfo *info)
| Frees the given DBusUserInfo's members with _dbus_user_info_free() and also calls dbus_free() on the block itself. More...
void | _dbus_group_info_free_allocated (DBusGroupInfo *info)
| Frees the given DBusGroupInfo's members with _dbus_group_info_free() and also calls dbus_free() on the block itself. More...
void | _dbus_user_info_free (DBusUserInfo *info)
| Frees the members of info (but not info itself) More...
void | _dbus_group_info_free (DBusGroupInfo *info)
| Frees the members of info (but not info itself). More...
dbus_bool_t | _dbus_is_a_number (const DBusString *str, unsigned long *num)
| Checks if a given string is actually a number and converts it if it is. More...
DBusUserInfo * | _dbus_user_database_lookup (DBusUserDatabase *db, dbus_uid_t uid, const DBusString *username, DBusError *error)
| Looks up a uid or username in the user database. More...
void | _dbus_user_database_lock_system (void)
| Locks global system user database.
void | _dbus_user_database_unlock_system (void)
| Unlocks global system user database.
DBusUserDatabase * | _dbus_user_database_get_system (void)
| Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system()). More...
void | _dbus_user_database_flush_system (void)
| Flushes the system global user database;.
dbus_bool_t | _dbus_username_from_current_process (const DBusString **username)
| Gets username of user owning current process. More...
dbus_bool_t | _dbus_homedir_from_current_process (const DBusString **homedir)
| Gets homedir of user owning current process. More...
dbus_bool_t | _dbus_homedir_from_username (const DBusString *username, DBusString *homedir)
| Gets the home directory for the given user. More...
dbus_bool_t | _dbus_homedir_from_uid (dbus_uid_t uid, DBusString *homedir)
| Gets the home directory for the given user. More...
dbus_bool_t | _dbus_credentials_add_from_user (DBusCredentials *credentials, const DBusString *username)
| Adds the credentials corresponding to the given username. More...
DBusUserDatabase * | _dbus_user_database_new (void)
| Creates a new user database object used to look up and cache user information. More...
void | _dbus_user_database_flush (DBusUserDatabase *db)
| Flush all information out of the user database.
void | _dbus_user_database_unref (DBusUserDatabase *db)
| Decrements refcount of user database. More...
dbus_bool_t | _dbus_user_database_get_uid (DBusUserDatabase *db, dbus_uid_t uid, const DBusUserInfo **info, DBusError *error)
| Gets the user information for the given UID, returned user info should not be freed. More...
dbus_bool_t | _dbus_user_database_get_username (DBusUserDatabase *db, const DBusString *username, const DBusUserInfo **info, DBusError *error)
| Gets the user information for the given username. More...

## Variables

const char * | _dbus_no_memory_message = "Not enough memory"
| Fixed "out of memory" error message, just to avoid making up a different string every time and wasting space.
const char * | _dbus_return_if_fail_warning_format
| String used in _dbus_return_if_fail macro. More...

## Detailed Description

Utility functions (_dbus_assert(), _dbus_warn(), etc.)

## Macro Definition Documentation

#define _dbus_assert | ( |  | condition) |  | _dbus_real_assert ((condition) != 0, #condition, __FILE__, __LINE__, _DBUS_FUNCTION_NAME)

Aborts with an error message if the condition is false.

Parameters

  condition | condition which must be true.

Definition at line 139 of file dbus-internals.h.

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_auth_decode_data(), _dbus_auth_encode_data(), _dbus_auth_get_buffer(), _dbus_auth_get_bytes_to_send(), _dbus_auth_get_guid_from_server(), _dbus_auth_get_identity(), _dbus_auth_ref(), _dbus_auth_return_buffer(), _dbus_auth_unref(), _dbus_babysitter_ref(), _dbus_babysitter_unref(), _dbus_cmutex_free_at_location(), _dbus_cmutex_new_at_location(), _dbus_condvar_free_at_location(), _dbus_condvar_new_at_location(), _dbus_connection_block_pending_call(), _dbus_connection_close_if_only_one_ref(), _dbus_connection_close_possibly_shared(), _dbus_connection_message_sent_unlocked(), _dbus_connection_queue_received_message_link(), _dbus_connection_ref_unlocked(), _dbus_connection_send_and_unlock(), _dbus_connection_toggle_watch_unlocked(), _dbus_connection_unref_unlocked(), _dbus_counter_ref(), _dbus_counter_unref(), _dbus_credentials_add_from_current_process(), _dbus_credentials_ref(), _dbus_credentials_unref(), _dbus_data_slot_allocator_alloc(), _dbus_data_slot_allocator_free(), _dbus_data_slot_list_get(), _dbus_data_slot_list_set(), _dbus_decompose_path(), _dbus_generate_random_ascii(), _dbus_get_autolaunch_address(), _dbus_get_environment(), _dbus_get_tmpdir(), _dbus_groups_from_uid(), _dbus_hash_iter_get_int_key(), _dbus_hash_iter_get_string_key(), _dbus_hash_iter_get_uintptr_key(), _dbus_hash_iter_get_value(), _dbus_hash_iter_init(), _dbus_hash_iter_lookup(), _dbus_hash_iter_next(), _dbus_hash_iter_remove_entry(), _dbus_hash_iter_set_value(), _dbus_hash_table_free_preallocated_entry(), _dbus_hash_table_insert_int(), _dbus_hash_table_insert_string(), _dbus_hash_table_insert_string_preallocated(), _dbus_hash_table_insert_uintptr(), _dbus_hash_table_lookup_int(), _dbus_hash_table_lookup_string(), _dbus_hash_table_lookup_uintptr(), _dbus_hash_table_new(), _dbus_hash_table_remove_int(), _dbus_hash_table_remove_string(), _dbus_hash_table_remove_uintptr(), _dbus_header_create(), _dbus_header_delete_field(), _dbus_header_get_byte_order(), _dbus_header_get_field_basic(), _dbus_header_get_message_type(), _dbus_header_have_message_untrusted(), _dbus_header_load(), _dbus_header_set_field_basic(), _dbus_header_set_serial(), _dbus_keyring_new_for_credentials(), _dbus_list_copy(), _dbus_lookup_launchd_socket(), _dbus_marshal_byteswap(), _dbus_marshal_read_basic(), _dbus_marshal_read_uint32(), _dbus_marshal_set_basic(), _dbus_marshal_skip_basic(), _dbus_marshal_write_basic(), _dbus_marshal_write_fixed_multi(), _dbus_mem_pool_alloc(), _dbus_mem_pool_dealloc(), _dbus_mem_pool_new(), _dbus_message_get_network_data(), _dbus_message_get_unix_fds(), _dbus_message_iter_get_args_valist(), _dbus_message_loader_get_buffer(), _dbus_message_loader_get_corruption_reason(), _dbus_message_loader_get_is_corrupted(), _dbus_message_loader_get_unix_fds(), _dbus_message_loader_queue_messages(), _dbus_message_loader_return_buffer(), _dbus_message_loader_return_unix_fds(), _dbus_message_remove_counter(), _dbus_object_tree_get_user_data_unlocked(), _dbus_object_tree_ref(), _dbus_object_tree_register(), _dbus_object_tree_unref(), _dbus_object_tree_unregister_and_unlock(), _dbus_pending_call_complete(), _dbus_pending_call_get_connection_and_lock(), _dbus_pending_call_get_connection_unlocked(), _dbus_pending_call_get_reply_serial_unlocked(), _dbus_pending_call_get_timeout_unlocked(), _dbus_pending_call_is_timeout_added_unlocked(), _dbus_pending_call_new_unlocked(), _dbus_pending_call_queue_timeout_error_unlocked(), _dbus_pending_call_set_reply_serial_unlocked(), _dbus_pending_call_set_reply_unlocked(), _dbus_pending_call_set_timeout_added_unlocked(), _dbus_pending_call_unref_and_unlock(), _dbus_read(), _dbus_read_credentials_socket(), _dbus_read_socket(), _dbus_read_socket_with_unix_fds(), _dbus_rmutex_free_at_location(), _dbus_rmutex_new_at_location(), _dbus_send_credentials_socket(), _dbus_server_finalize_base(), _dbus_server_init_base(), _dbus_server_ref_unlocked(), _dbus_server_toggle_watch(), _dbus_server_unref_unlocked(), _dbus_setenv(), _dbus_string_append(), _dbus_string_append_len(), _dbus_string_copy_data(), _dbus_string_copy_len(), _dbus_string_copy_to_buffer(), _dbus_string_copy_to_buffer_with_nul(), _dbus_string_delete(), _dbus_string_ends_with_c_str(), _dbus_string_equal_c_str(), _dbus_string_equal_substring(), _dbus_string_find_blank(), _dbus_string_find_byte_backward(), _dbus_string_find_eol(), _dbus_string_find_to(), _dbus_string_get_byte(), _dbus_string_get_const_data_len(), _dbus_string_get_data_len(), _dbus_string_get_dirname(), _dbus_string_hex_decode(), _dbus_string_hex_encode(), _dbus_string_init_const(), _dbus_string_init_const_len(), _dbus_string_init_preallocated(), _dbus_string_insert_8_aligned(), _dbus_string_insert_alignment(), _dbus_string_insert_byte(), _dbus_string_insert_bytes(), _dbus_string_lengthen(), _dbus_string_move(), _dbus_string_move_len(), _dbus_string_pop_line(), _dbus_string_replace_len(), _dbus_string_set_byte(), _dbus_string_set_length(), _dbus_string_shorten(), _dbus_string_skip_blank(), _dbus_string_skip_white(), _dbus_string_skip_white_reverse(), _dbus_string_starts_with_c_str(), _dbus_string_steal_data(), _dbus_string_tolower_ascii(), _dbus_string_toupper_ascii(), _dbus_string_validate_ascii(), _dbus_string_validate_nul(), _dbus_string_validate_utf8(), _dbus_swap_array(), _dbus_timeout_set_interval(), _dbus_timeout_unref(), _dbus_transport_disconnect(), _dbus_transport_do_iteration(), _dbus_transport_get_is_authenticated(), _dbus_transport_handle_watch(), _dbus_transport_init_base(), _dbus_transport_open_platform_specific(), _dbus_transport_open_socket(), _dbus_transport_queue_messages(), _dbus_transport_ref(), _dbus_transport_set_connection(), _dbus_transport_unref(), _dbus_type_reader_delete(), _dbus_type_reader_get_array_length(), _dbus_type_reader_get_current_type(), _dbus_type_reader_get_element_type(), _dbus_type_reader_read_basic(), _dbus_type_reader_read_fixed_multi(), _dbus_type_reader_read_raw(), _dbus_type_reader_recurse(), _dbus_type_reader_set_basic(), _dbus_type_signature_next(), _dbus_type_writer_unrecurse(), _dbus_type_writer_write_fixed_multi(), _dbus_unpack_uint16(), _dbus_unpack_uint32(), _dbus_user_database_get_system(), _dbus_user_database_lookup(), _dbus_user_database_unref(), _dbus_validate_body_with_reason(), _dbus_validate_interface(), _dbus_validate_member(), _dbus_validate_path(), _dbus_validate_signature(), _dbus_validate_signature_with_reason(), _dbus_verbose_bytes(), _dbus_verbose_bytes_of_string(), _dbus_watch_new(), _dbus_watch_unref(), _dbus_write_socket_two(), _dbus_write_two(), dbus_address_entry_get_value(), dbus_address_unescape_value(), dbus_bus_set_unique_name(), dbus_connection_borrow_message(), dbus_connection_get_unix_user(), dbus_connection_get_windows_user(), dbus_connection_return_message(), dbus_connection_send_with_reply_and_block(), dbus_connection_steal_borrowed_message(), dbus_error_has_name(), dbus_error_init(), dbus_error_is_set(), dbus_free(), dbus_message_contains_unix_fds(), dbus_message_demarshal_bytes_needed(), dbus_message_lock(), dbus_message_ref(), dbus_message_unref(), dbus_parse_address(), dbus_server_disconnect(), dbus_server_listen(), dbus_server_unref(), dbus_set_error(), dbus_set_error_const(), and dbus_watch_get_flags().

#define _dbus_assert_not_reached | ( |  | explanation) |  | _dbus_real_assert_not_reached (explanation, __FILE__, __LINE__)

Aborts with an error message if called.

The given explanation will be printed.

Parameters

  explanation | explanation of what happened if the code was reached.

Definition at line 149 of file dbus-internals.h.

Referenced by _dbus_babysitter_get_child_exit_status(), _dbus_become_daemon(), _dbus_credentials_include(), _dbus_data_slot_allocator_alloc(), _dbus_hash_table_new(), _dbus_header_set_field_basic(), _dbus_marshal_read_basic(), _dbus_marshal_set_basic(), _dbus_marshal_skip_basic(), _dbus_marshal_write_basic(), _dbus_marshal_write_fixed_multi(), _dbus_mem_pool_dealloc(), _dbus_message_loader_get_unix_fds(), _dbus_message_loader_return_unix_fds(), _dbus_poll(), _dbus_spawn_async_with_babysitter(), _dbus_string_pop_line(), _dbus_timeout_list_remove_timeout(), _dbus_type_get_alignment(), _dbus_type_reader_recurse(), _dbus_type_writer_write_basic(), _dbus_type_writer_write_fixed_multi(), and _dbus_watch_list_remove_watch().

#define _DBUS_DECLARE_GLOBAL_LOCK | ( |  | name) |  | extern DBusRMutex *_dbus_lock_##name

Expands to declaration of a global lock defined with _DBUS_DEFINE_GLOBAL_LOCK.

The lock must be added to the list to initialize in dbus_threads_init().

Definition at line 307 of file dbus-internals.h.

#define _DBUS_DEFINE_GLOBAL_LOCK | ( |  | name) |  | DBusRMutex *_dbus_lock_##name

Defines a global lock variable with the given name.

The lock must be added to the list to initialize in dbus_threads_init().

Definition at line 308 of file dbus-internals.h.

#define _DBUS_INT_TO_POINTER | ( |  | integer) |  | ((void*)((intptr_t)(integer)))

Safely stuffs an integer into a pointer, to be extracted later with _DBUS_POINTER_TO_INT.

Only guaranteed to preserve 32 bits.

Parameters

  integer | the integer to stuff into a pointer.

Definition at line 181 of file dbus-internals.h.

Referenced by _dbus_hash_table_insert_int(), _dbus_hash_table_lookup_int(), _dbus_hash_table_remove_int(), and _dbus_validate_signature_with_reason().

#define _DBUS_N_ELEMENTS | ( |  | array) |  | ((int) (sizeof ((array)) / sizeof ((array)[0])))

Computes the number of elements in a fixed-size array using sizeof().

Parameters

  array | the array to count elements in.

Definition at line 178 of file dbus-internals.h.

Referenced by _dbus_get_autolaunch_address(), _dbus_hash_table_new(), _dbus_lookup_launchd_socket(), _dbus_transport_open(), and dbus_server_listen().

#define _DBUS_POINTER_TO_INT | ( |  | pointer) |  | ((intptr_t)(pointer))

Safely casts a void* to an integer; should only be used on void* that actually contain integers, for example one created with _DBUS_INT_TO_POINTER.

Only guaranteed to preserve 32 bits. (i.e. it's used to store 32-bit ints in pointers, but can't be used to store 64-bit pointers in ints.)

Parameters

  pointer | pointer to extract an integer from.

Definition at line 180 of file dbus-internals.h.

Referenced by _dbus_hash_iter_get_int_key(), and _dbus_validate_signature_with_reason().

#define _DBUS_ZERO | ( |  | object) |  | (memset (&(object), '\0', sizeof ((object))))

Sets all bits in an object to zero.

Parameters

  object | the object to be zeroed.

Definition at line 183 of file dbus-internals.h.

Referenced by _dbus_connect_unix_socket(), _dbus_full_duplex_pipe(), _dbus_listen_tcp_socket(), _dbus_listen_unix_socket(), _dbus_read_credentials_socket(), _dbus_read_socket_with_unix_fds(), _dbus_sha_final(), _dbus_socket_can_pass_unix_fd(), and _dbus_write_socket_two().

## Enumeration Type Documentation

enum ReadStatus

Enumeration for status of a read()

Enumerator
READ_STATUS_OK | Read succeeded.
READ_STATUS_ERROR | Some kind of error.
READ_STATUS_EOF | EOF returned.

Definition at line 57 of file dbus-spawn.c.

## Function Documentation

dbus_bool_t _dbus_babysitter_get_child_exit_status | ( | DBusBabysitter * | sitter,
|  | int * | status
| ) |  |

Gets the exit status of the child.

We do this so implementation specific detail is not cluttering up dbus, for example the system launcher code. This can only be called if the child has exited, i.e. call _dbus_babysitter_get_child_exited(). It returns FALSE if the child did not return a status code, e.g. because the child was signaled or we failed to ever launch the child in the first place.

Parameters

  sitter | the babysitter
  status | the returned status code

Returns
  FALSE on failure

Definition at line 663 of file dbus-spawn.c.

References _dbus_assert_not_reached, _dbus_babysitter_get_child_exited(), FALSE, DBusBabysitter::status, and TRUE.

dbus_bool_t _dbus_babysitter_get_child_exited | ( | DBusBabysitter * | sitter) |  |

Checks whether the child has exited, without blocking.

Parameters

  sitter | the babysitter

Definition at line 638 of file dbus-spawn.c.

References FALSE, LIVE_CHILDREN, NULL, and DBusBabysitter::socket_to_babysitter.

Referenced by _dbus_babysitter_get_child_exit_status(), and _dbus_babysitter_set_child_exit_error().

void _dbus_babysitter_kill_child | ( | DBusBabysitter * | sitter) |  |

Blocks until the babysitter process gives us the PID of the spawned grandchild, then kills the spawned grandchild.

Parameters

  sitter | the babysitter object

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

References DBusBabysitter::grandchild_pid, LIVE_CHILDREN, NULL, and TRUE.

DBusBabysitter* _dbus_babysitter_ref | ( | DBusBabysitter * | sitter) |  |

Increment the reference count on the babysitter object.

Parameters

  sitter | the babysitter

Returns
  the babysitter

Definition at line 253 of file dbus-spawn.c.

References _dbus_assert, NULL, and DBusBabysitter::refcount.

void _dbus_babysitter_set_child_exit_error | ( | DBusBabysitter * | sitter,
|  | DBusError * | error
| ) |  |

Sets the DBusError with an explanation of why the spawned child process exited (on a signal, or whatever).

If the child process has not exited, does nothing (error will remain unset).

Parameters

  sitter | the babysitter
  error | an error to fill in

Definition at line 687 of file dbus-spawn.c.

References _dbus_babysitter_get_child_exited(), DBUS_ERROR_FAILED, DBUS_ERROR_NO_MEMORY, DBUS_ERROR_SPAWN_CHILD_EXITED, DBUS_ERROR_SPAWN_CHILD_SIGNALED, DBUS_ERROR_SPAWN_EXEC_FAILED, dbus_set_error(), DBusBabysitter::errnum, DBusBabysitter::executable, DBusBabysitter::have_exec_errnum, DBusBabysitter::have_fork_errnum, and DBusBabysitter::status.

dbus_bool_t _dbus_babysitter_set_watch_functions | ( | DBusBabysitter * | sitter,
|  | DBusAddWatchFunction | add_function,
|  | DBusRemoveWatchFunction | remove_function,
|  | DBusWatchToggledFunction | toggled_function,
|  | void * | data,
|  | DBusFreeFunction | free_data_function
| ) |  |

Sets watch functions to notify us when the babysitter object needs to read/write file descriptors.

Parameters

  sitter | the babysitter
  add_function | function to begin monitoring a new descriptor.
  remove_function | function to stop monitoring a descriptor.
  toggled_function | function to notify when the watch is enabled/disabled
  data | data to pass to add_function and remove_function.
  free_data_function | function to be called to free the data.

Returns
  FALSE on failure (no memory)

Definition at line 745 of file dbus-spawn.c.

References _dbus_watch_list_set_functions(), and DBusBabysitter::watches.

void _dbus_babysitter_unref | ( | DBusBabysitter * | sitter) |  |

Decrement the reference count on the babysitter object.

When the reference count of the babysitter object reaches zero, the babysitter is killed and the child that was being babysat gets emancipated.

Parameters

  sitter | the babysitter

Definition at line 275 of file dbus-spawn.c.

References _dbus_assert, _dbus_close_socket(), _dbus_warn(), _dbus_watch_invalidate(), _dbus_watch_list_free(), _dbus_watch_unref(), dbus_free(), DBusBabysitter::executable, NULL, DBusBabysitter::refcount, DBusBabysitter::sitter_pid, DBusBabysitter::sitter_watch, DBusBabysitter::status, and DBusBabysitter::watches.

Referenced by _dbus_spawn_async_with_babysitter().

dbus_bool_t _dbus_become_daemon | ( | const DBusString * | pidfile,
|  | DBusPipe * | print_pid_pipe,
|  | DBusError * | error,
|  | dbus_bool_t | keep_umask
| ) |  |

Does the chdir, fork, setsid, etc.

to become a daemon process.

Parameters

  pidfile | NULL, or pidfile to create
  print_pid_pipe | pipe to print daemon's pid to, or -1 for none
  error | return location for errors
  keep_umask | TRUE to keep the original umask

Returns
  FALSE on failure

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

dbus_bool_t _dbus_change_to_daemon_user | ( | const char * | user,
|  | DBusError * | error
| ) |  |

Changes the user and group the bus is running as.

Parameters

  user | the user to become
  error | return location for errors

Returns
  FALSE on failure

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

dbus_bool_t _dbus_credentials_add_from_user | ( | DBusCredentials * | credentials,
|  | const DBusString * | username
| ) |  |

Adds the credentials corresponding to the given username.

Used among other purposes to parses a desired identity provided from a client in the auth protocol. On UNIX this means parsing a UID, on Windows probably parsing an SID string.

Todo:
  this is broken because it treats OOM and parse error the same way. Needs a DBusError.

Parameters

  credentials | credentials to fill in
  username | the username

Returns
  TRUE if the username existed and we got some credentials

Definition at line 493 of file dbus-userdb.c.

References _dbus_credentials_add_unix_uid(), _dbus_credentials_add_windows_sid(), _dbus_string_get_const_data(), _dbus_user_database_get_system(), _dbus_user_database_get_username(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, NULL, TRUE, and DBusUserInfo::uid.

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.

This function is not re-entrant, and not necessarily thread-safe. Only use it for test code or single-threaded utilities.

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 697 of file dbus-sysdeps-util-unix.c.

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 649 of file dbus-sysdeps-util-unix.c.

char** _dbus_dup_string_array | ( | const char ** | array) |  |

Duplicates a string array.

Result may be freed with dbus_free_string_array(). Returns NULL if memory allocation fails. If the array to be duplicated is NULL, returns NULL.

Parameters

  array | array to duplicate.

Returns
  newly-allocated copy.

Definition at line 596 of file dbus-internals.c.

References _dbus_strdup(), dbus_free_string_array(), dbus_new0, and NULL.

Referenced by _dbus_auth_set_mechanisms(), and dbus_server_set_auth_mechanisms().

const char* _dbus_error_from_errno | ( | int | error_number) |  |

Converts a UNIX errno, or Windows errno or WinSock error value 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 612 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_to_daemon_user(), _dbus_check_dir_is_private_to_user(), _dbus_close(), _dbus_close_socket(), _dbus_command_for_pid(), _dbus_connect_exec(), _dbus_connect_unix_socket(), _dbus_directory_get_next_file(), _dbus_directory_open(), _dbus_dup(), _dbus_error_from_system_errno(), _dbus_file_get_contents(), _dbus_full_duplex_pipe(), _dbus_is_console_user(), _dbus_listen_systemd_sockets(), _dbus_listen_tcp_socket(), _dbus_listen_unix_socket(), _dbus_read_credentials_socket(), _dbus_send_credentials_socket(), _dbus_stat(), and _dbus_string_save_to_file().

const char* _dbus_error_from_system_errno | ( | void | ) |  |

Converts the current system errno value into a DBusError name.

Returns
  an error name

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

References _dbus_error_from_errno().

dbus_bool_t _dbus_file_exists | ( | const char * | file) |  |

Checks if a file exists.

File interface.

Parameters

  file | full path to the file

Returns
  TRUE if file exists

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

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 573 of file dbus-sysdeps.c.

References _dbus_assert, _dbus_generate_random_bytes(), _dbus_string_get_byte(), _dbus_string_get_length(), _dbus_string_set_byte(), _dbus_string_validate_ascii(), FALSE, and TRUE.

Referenced by _dbus_server_listen_platform_specific(), and _dbus_string_save_to_file().

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 541 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().

void _dbus_generate_uuid | ( | DBusGUID * | uuid) |  |

Generates a new UUID.

If you change how this is done, there's some text about it in the spec that should also change.

Parameters

  uuid | the uuid to initialize

Definition at line 659 of file dbus-internals.c.

References _dbus_generate_random_bytes_buffer(), _dbus_get_real_time(), DBusGUID::as_bytes, DBusGUID::as_uint32s, and NULL.

Referenced by _dbus_get_local_machine_uuid_encoded(), _dbus_server_init_base(), and dbus_internal_do_not_use_create_uuid().

dbus_bool_t _dbus_get_group_id | ( | const DBusString * | groupname,
|  | dbus_gid_t * | gid
| ) |  |

Gets group ID given groupname.

Parameters

  groupname | the groupname
  gid | return location for GID

Returns
  TRUE if group name existed and we got the GID

Definition at line 155 of file dbus-userdb-util.c.

References _dbus_user_database_get_groupname(), _dbus_user_database_get_system(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, DBusGroupInfo::gid, NULL, and TRUE.

Referenced by _dbus_parse_unix_group_from_config().

dbus_bool_t _dbus_get_is_errno_eintr | ( | void | ) |  |

See if errno is EINTR.

Returns
  TRUE if errno == EINTR

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

dbus_bool_t _dbus_get_is_errno_enomem | ( | void | ) |  |

See if errno is ENOMEM.

Returns
  TRUE if errno == ENOMEM

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

dbus_bool_t _dbus_get_is_errno_epipe | ( | void | ) |  |

See if errno is EPIPE.

Returns
  TRUE if errno == EPIPE

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

dbus_bool_t _dbus_get_is_errno_nonzero | ( | void | ) |  |

See if errno is set.

Returns
  TRUE if errno is not 0

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

dbus_bool_t _dbus_get_local_machine_uuid_encoded | ( | DBusString * | uuid_str) |  |

Gets the hex-encoded UUID of the machine this function is executed on.

This UUID is guaranteed to be the same for a given machine at least until it next reboots, though it also makes some effort to be the same forever, it may change if the machine is reconfigured or its hardware is modified.

Parameters

  uuid_str | string to append hex-encoded machine uuid to

Returns
  FALSE if no memory

Definition at line 865 of file dbus-internals.c.

References _dbus_current_generation, _dbus_generate_uuid(), _DBUS_LOCK, _dbus_read_local_machine_uuid(), _DBUS_UNLOCK, _dbus_uuid_encode(), _dbus_warn_check_failed(), dbus_error_free(), DBUS_ERROR_INIT, FALSE, and DBusError::message.

Referenced by _dbus_get_autolaunch_address(), and dbus_get_local_machine_id().

dbus_bool_t _dbus_get_user_id | ( | const DBusString * | username,
|  | dbus_uid_t * | uid
| ) |  |

Gets user ID given username.

Parameters

  username | the username
  uid | return location for UID

Returns
  TRUE if username existed and we got the UID

Definition at line 141 of file dbus-userdb-util.c.

References _dbus_get_user_id_and_primary_group(), and NULL.

Referenced by _dbus_parse_unix_user_from_config().

dbus_bool_t _dbus_get_user_id_and_primary_group | ( | const DBusString * | username,
|  | dbus_uid_t * | uid_p,
|  | dbus_gid_t * | gid_p
| ) |  |

Gets user ID and primary group given username.

Parameters

  username | the username
  uid_p | return location for UID
  gid_p | return location for GID

Returns
  TRUE if username existed and we got the UID and GID

Definition at line 191 of file dbus-userdb-util.c.

References _dbus_user_database_get_system(), _dbus_user_database_get_username(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, NULL, DBusUserInfo::primary_gid, TRUE, and DBusUserInfo::uid.

Referenced by _dbus_change_to_daemon_user(), _dbus_get_user_id(), and _dbus_verify_daemon_user().

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 895 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 914 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 89 of file dbus-userdb.c.

References dbus_free(), and DBusGroupInfo::groupname.

Referenced by _dbus_group_info_free_allocated().

void _dbus_group_info_free_allocated | ( | DBusGroupInfo * | info) |  |

Frees the given DBusGroupInfo's members with _dbus_group_info_free() and also calls dbus_free() on the block itself.

Parameters

  info | the info

Definition at line 61 of file dbus-userdb.c.

References _dbus_group_info_free(), dbus_free(), and NULL.

Referenced by _dbus_user_database_lookup_group(), and _dbus_user_database_new().

dbus_bool_t _dbus_groups_from_uid | ( | dbus_uid_t | uid,
|  | dbus_gid_t ** | group_ids,
|  | int * | n_group_ids
| ) |  |

Gets all groups corresponding to the given UID.

Returns FALSE if no memory, or user isn't known, but always initializes group_ids to a NULL array.

Parameters

  uid | the UID
  group_ids | return location for array of group IDs
  n_group_ids | return location for length of returned array

Returns
  TRUE if the UID existed and we got some credentials

Definition at line 381 of file dbus-userdb-util.c.

References _dbus_assert, _dbus_user_database_get_system(), _dbus_user_database_get_uid(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), dbus_new, FALSE, DBusUserInfo::group_ids, DBusUserInfo::n_group_ids, NULL, TRUE, and DBusUserInfo::uid.

Referenced by _dbus_unix_groups_from_uid().

dbus_bool_t _dbus_homedir_from_current_process | ( | const DBusString ** | homedir) |  |

Gets homedir of user owning current process.

The returned string is valid until dbus_shutdown() is called.

Parameters

  homedir | place to store pointer to homedir

Returns
  FALSE if no memory

Definition at line 386 of file dbus-userdb.c.

References _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, and TRUE.

Referenced by _dbus_get_standard_session_servicedirs().

dbus_bool_t _dbus_homedir_from_uid | ( | dbus_uid_t | uid,
|  | DBusString * | homedir
| ) |  |

Gets the home directory for the given user.

Parameters

  uid | the uid
  homedir | string to append home directory to

Returns
  TRUE if user existed and we appended their homedir

Definition at line 447 of file dbus-userdb.c.

References _dbus_string_append(), _dbus_user_database_get_system(), _dbus_user_database_get_uid(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, DBusUserInfo::homedir, NULL, and TRUE.

Referenced by _dbus_append_keyring_directory_for_credentials().

dbus_bool_t _dbus_homedir_from_username | ( | const DBusString * | username,
|  | DBusString * | homedir
| ) |  |

Gets the home directory for the given user.

Parameters

  username | the username
  homedir | string to append home directory to

Returns
  TRUE if user existed and we appended their homedir

Definition at line 408 of file dbus-userdb.c.

References _dbus_string_append(), _dbus_user_database_get_system(), _dbus_user_database_get_username(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, DBusUserInfo::homedir, NULL, and TRUE.

dbus_bool_t _dbus_is_a_number | ( | const DBusString * | str,
|  | unsigned long * | num
| ) |  |

Checks if a given string is actually a number and converts it if it is.

Parameters

  str | the string to check
  num | the memory location of the unsigned long to fill in

Returns
  TRUE if str is a number and num is filled in

Definition at line 103 of file dbus-userdb.c.

References _dbus_string_get_length(), _dbus_string_parse_uint(), FALSE, and TRUE.

Referenced by _dbus_user_database_lookup(), and _dbus_user_database_lookup_group().

dbus_bool_t _dbus_is_console_user | ( | dbus_uid_t | uid,
|  | DBusError * | error
| ) |  |

Checks to see if the UID sent in is the console user.

Parameters

  uid | UID of person to check
  error | return location for errors

Returns
  TRUE if the UID is the same as the console user and there are no errors

Definition at line 49 of file dbus-userdb-util.c.

References _dbus_error_from_errno(), _dbus_stat(), _dbus_string_append(), _dbus_string_free(), _dbus_string_init(), _dbus_user_at_console(), _dbus_user_database_get_system(), _dbus_user_database_lock_system(), _dbus_user_database_lookup(), _dbus_user_database_unlock_system(), DBUS_ERROR_FAILED, dbus_set_error(), DBUS_UID_FORMAT, FALSE, NULL, TRUE, DBusStat::uid, and DBusUserInfo::username.

Referenced by _dbus_unix_user_is_at_console().

void* _dbus_memdup | ( | const void * | mem,
|  | size_t | n_bytes
| ) |  |

Duplicates a block of memory.

Returns NULL on failure.

Parameters

  mem | memory to copy
  n_bytes | number of bytes to copy

Returns
  the copy

Definition at line 573 of file dbus-internals.c.

References dbus_malloc(), and NULL.

Referenced by _dbus_credentials_add_adt_audit_data(), and _dbus_decompose_path().

dbus_bool_t _dbus_parse_unix_group_from_config | ( | const DBusString * | groupname,
|  | dbus_gid_t * | gid_p
| ) |  |

Parse a UNIX group from the bus config file.

On Windows, this should simply always fail (just return FALSE).

Parameters

  groupname | the groupname text
  gid_p | place to return the gid

Returns
  TRUE on success

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

dbus_bool_t _dbus_parse_unix_user_from_config | ( | const DBusString * | username,
|  | dbus_uid_t * | uid_p
| ) |  |

Parse a UNIX user from the bus config file.

On Windows, this should simply always fail (just return FALSE).

Parameters

  username | the username text
  uid_p | place to return the uid

Returns
  TRUE on success

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

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 584 of file dbus-sysdeps-util-unix.c.

Referenced by _dbus_get_standard_session_servicedirs().

dbus_bool_t _dbus_read_uuid_file | ( | const DBusString * | filename,
|  | DBusGUID * | uuid,
|  | dbus_bool_t | create_if_not_found,
|  | DBusError * | error
| ) |  |

Reads (and optionally writes) a uuid to a file.

Initializes the uuid unless an error is returned.

Parameters

  filename | the name of the file
  uuid | uuid to be initialized with the loaded uuid
  create_if_not_found | TRUE to create a new uuid and save it if the file doesn't exist
  error | the error return

Returns
  FALSE if the error is set

Definition at line 818 of file dbus-internals.c.

References dbus_error_free(), dbus_error_has_name(), DBUS_ERROR_INIT, DBUS_ERROR_INVALID_FILE_CONTENT, dbus_move_error(), FALSE, and TRUE.

Referenced by _dbus_read_local_machine_uuid(), and dbus_internal_do_not_use_get_uuid().

void _dbus_real_assert | ( | dbus_bool_t | condition,
|  | const char * | condition_text,
|  | const char * | file,
|  | int | line,
|  | const char * | func
| ) |  |

Internals of _dbus_assert(); it's a function rather than a macro with the inline code so that the assertion failure blocks don't show up in test suite coverage, and to shrink code size.

Parameters

  condition | TRUE if assertion succeeded
  condition_text | condition as a string
  file | file the assertion is in
  line | line the assertion is in
  func | function the assertion is in

Definition at line 921 of file dbus-internals.c.

References _dbus_abort(), _dbus_pid_for_log(), and _dbus_warn().

void _dbus_real_assert_not_reached | ( | const char * | explanation,
|  | const char * | file,
|  | int | line
| ) |  |

Internals of _dbus_assert_not_reached(); it's a function rather than a macro with the inline code so that the assertion failure blocks don't show up in test suite coverage, and to shrink code size.

Parameters

  explanation | what was reached that shouldn't have been
  file | file the assertion is in
  line | line the assertion is in

Definition at line 946 of file dbus-internals.c.

References _dbus_abort(), _dbus_pid_for_log(), and _dbus_warn().

void _dbus_request_file_descriptor_limit | ( | unsigned int | limit) |  |

Attempt to ensure that the current process can open at least file descriptors.

If is lower than the current, it will not be lowered. No error is returned if the request can not be satisfied.

Number of file descriptors

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

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 509 of file dbus-sysdeps-util-unix.c.

dbus_bool_t _dbus_spawn_async_with_babysitter | ( | DBusBabysitter ** | sitter_p,
|  | char ** | argv,
|  | char ** | env,
|  | DBusSpawnChildSetupFunc | child_setup,
|  | void * | user_data,
|  | DBusError * | error
| ) |  |

Spawns a new process.

The executable name and argv[0] are the same, both are provided in argv[0]. The child_setup function is passed the given user_data and is run in the child just before calling exec().

Also creates a "babysitter" which tracks the status of the child process, advising the parent if the child exits. If the spawn fails, no babysitter is created. If sitter_p is NULL, no babysitter is kept.

Parameters

  sitter_p | return location for babysitter or NULL
  argv | the executable and arguments
  env | the environment (not used on unix yet)
  child_setup | function to call in child pre-exec()
  user_data | user data for setup function
  error | error object to be filled in if function fails

Returns
  TRUE on success, FALSE if error is filled in

Definition at line 1137 of file dbus-spawn.c.

References _dbus_assert_not_reached, _dbus_babysitter_unref(), _dbus_full_duplex_pipe(), _dbus_strdup(), _dbus_watch_invalidate(), _dbus_watch_list_add_watch(), _dbus_watch_new(), _dbus_watch_unref(), DBUS_ERROR_NO_MEMORY, DBUS_ERROR_SPAWN_FORK_FAILED, dbus_free_string_array(), dbus_set_error(), dbus_set_error_const(), DBUS_WATCH_READABLE, DBusBabysitter::error_pipe_from_child, DBusBabysitter::error_watch, DBusBabysitter::executable, FALSE, NULL, READ_END, DBusBabysitter::sitter_pid, DBusBabysitter::sitter_watch, DBusBabysitter::socket_to_babysitter, TRUE, DBusBabysitter::watches, and WRITE_END.

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 601 of file dbus-sysdeps-util-unix.c.

Referenced by _dbus_is_console_user().

char* _dbus_strdup | ( | const char * | str) |  |

Duplicates a string.

Result must be freed with dbus_free(). Returns NULL if memory allocation fails. If the string to be duplicated is NULL, returns NULL.

Parameters

  str | string to duplicate.

Returns
  newly-allocated copy.

Definition at line 545 of file dbus-internals.c.

References dbus_malloc(), and NULL.

Referenced by _dbus_credentials_add_windows_sid(), _dbus_dup_string_array(), _dbus_get_environment(), _dbus_message_iter_get_args_valist(), _dbus_server_new_for_domain_socket(), _dbus_spawn_async_with_babysitter(), _dbus_transport_get_windows_user(), _dbus_transport_open(), _dbus_transport_open_platform_specific(), dbus_bus_get_id(), dbus_bus_register(), dbus_bus_set_unique_name(), dbus_connection_get_server_id(), dbus_server_get_address(), and dbus_set_error().

const char* _dbus_strerror_from_errno | ( | void | ) |  |

Get error message from errno.

Returns
  _dbus_strerror(errno)

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

Referenced by _dbus_close_socket(), _dbus_create_directory(), _dbus_delete_file(), _dbus_full_duplex_pipe(), _dbus_listen_tcp_socket(), _dbus_poll(), _dbus_send_credentials_socket(), _dbus_write_socket(), and _dbus_write_socket_two().

dbus_bool_t _dbus_string_array_contains | ( | const char ** | array,
|  | const char * | str
| ) |  |

Checks whether a string array contains the given string.

Parameters

  array | array to search.
  str | string to look for

Returns
  TRUE if array contains string

Definition at line 636 of file dbus-internals.c.

References FALSE, NULL, and TRUE.

void _dbus_system_log | ( | DBusSystemLogSeverity | severity,
|  | const char * | msg,
|  |  | ...
| ) |  |

Log a message to the system log file (e.g.

syslog on Unix).

Parameters

  severity | a severity value
  msg | a printf-style format string
  args | arguments for the format string

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

void _dbus_system_logv | ( | DBusSystemLogSeverity | severity,
|  | const char * | msg,
|  | va_list | args
| ) |  |

Log a message to the system log file (e.g.

syslog on Unix).

Parameters

  severity | a severity value
  msg | a printf-style format string
  args | arguments for the format string

If the FATAL severity is given, this function will terminate the program with an error code.

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

Referenced by _dbus_system_log().

dbus_bool_t _dbus_unix_groups_from_uid | ( | dbus_uid_t | uid,
|  | dbus_gid_t ** | group_ids,
|  | int * | n_group_ids
| ) |  |

Gets all groups corresponding to the given UNIX user ID.

On UNIX, just calls _dbus_groups_from_uid(). On Windows, should always fail since we don't know any UNIX groups.

Parameters

  uid | the UID
  group_ids | return location for array of group IDs
  n_group_ids | return location for length of returned array

Returns
  TRUE if the UID existed and we got some credentials

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

dbus_bool_t _dbus_unix_user_is_at_console | ( | dbus_uid_t | uid,
|  | DBusError * | error
| ) |  |

Checks to see if the UNIX user ID is at the console.

Should always fail on Windows (set the error to DBUS_ERROR_NOT_SUPPORTED).

Parameters

  uid | UID of person to check
  error | return location for errors

Returns
  TRUE if the UID is the same as the console user and there are no errors

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

dbus_bool_t _dbus_unix_user_is_process_owner | ( | dbus_uid_t | uid) |  |

Checks to see if the UNIX user ID matches the UID of the process.

Should always return FALSE on Windows.

Parameters

  uid | the UNIX user ID

Returns
  TRUE if this uid owns the process.

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

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 540 of file dbus-sysdeps-util-unix.c.

References _dbus_concat_dir_and_file(), _dbus_file_exists(), _dbus_string_append(), _dbus_string_free(), _dbus_string_get_const_data(), _dbus_string_init(), _dbus_string_init_const(), and FALSE.

Referenced by _dbus_is_console_user().

dbus_bool_t _dbus_user_database_get_gid | ( | DBusUserDatabase * | db,
|  | dbus_gid_t | gid,
|  | const DBusGroupInfo ** | info,
|  | DBusError * | error
| ) |  |

Gets the user information for the given GID, returned group info should not be freed.

Parameters

  db | user database
  gid | the group ID
  info | return location for const ref to group info
  error | error location

Returns
  FALSE if error is set

Definition at line 360 of file dbus-userdb-util.c.

References _dbus_user_database_lookup_group(), and NULL.

dbus_bool_t _dbus_user_database_get_groupname | ( | DBusUserDatabase * | db,
|  | const DBusString * | groupname,
|  | const DBusGroupInfo ** | info,
|  | DBusError * | error
| ) |  |

Gets the user information for the given group name, returned group info should not be freed.

Parameters

  db | user database
  groupname | the group name
  info | return location for const ref to group info
  error | error location

Returns
  FALSE if error is set

Definition at line 340 of file dbus-userdb-util.c.

References _dbus_user_database_lookup_group(), DBUS_GID_UNSET, and NULL.

Referenced by _dbus_get_group_id().

DBusUserDatabase* _dbus_user_database_get_system | ( | void | ) |  |

Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system()).

Returns
  the database or NULL if no memory

Definition at line 333 of file dbus-userdb.c.

References _dbus_assert.

Referenced by _dbus_credentials_add_from_user(), _dbus_get_group_id(), _dbus_get_user_id_and_primary_group(), _dbus_groups_from_uid(), _dbus_homedir_from_uid(), _dbus_homedir_from_username(), and _dbus_is_console_user().

dbus_bool_t _dbus_user_database_get_uid | ( | DBusUserDatabase * | db,
|  | dbus_uid_t | uid,
|  | const DBusUserInfo ** | info,
|  | DBusError * | error
| ) |  |

Gets the user information for the given UID, returned user info should not be freed.

Parameters

  db | user database
  uid | the user ID
  info | return location for const ref to user info
  error | error location

Returns
  FALSE if error is set

Definition at line 638 of file dbus-userdb.c.

References _dbus_user_database_lookup(), and NULL.

Referenced by _dbus_groups_from_uid(), and _dbus_homedir_from_uid().

dbus_bool_t _dbus_user_database_get_username | ( | DBusUserDatabase * | db,
|  | const DBusString * | username,
|  | const DBusUserInfo ** | info,
|  | DBusError * | error
| ) |  |

Gets the user information for the given username.

Parameters

  db | user database
  username | the user name
  info | return location for const ref to user info
  error | error location

Returns
  FALSE if error is set

Definition at line 657 of file dbus-userdb.c.

References _dbus_user_database_lookup(), DBUS_UID_UNSET, and NULL.

Referenced by _dbus_credentials_add_from_user(), _dbus_get_user_id_and_primary_group(), and _dbus_homedir_from_username().

DBusUserInfo* _dbus_user_database_lookup | ( | DBusUserDatabase * | db,
|  | dbus_uid_t | uid,
|  | const DBusString * | username,
|  | DBusError * | error
| ) |  |

Looks up a uid or username in the user database.

Only one of name or UID can be provided. There are wrapper functions for this that are better to use, this one does no locking or anything on the database and otherwise sort of sucks.

Parameters

  db | the database
  uid | the user ID or DBUS_UID_UNSET
  username | username or NULL
  error | error to fill in

Returns
  the entry in the database

Definition at line 128 of file dbus-userdb.c.

References _dbus_assert, _dbus_hash_table_insert_string(), _dbus_hash_table_insert_uintptr(), _dbus_hash_table_lookup_string(), _dbus_hash_table_lookup_uintptr(), _dbus_hash_table_remove_uintptr(), _dbus_is_a_number(), _dbus_string_get_const_data(), _dbus_user_info_fill(), _dbus_user_info_fill_uid(), _dbus_user_info_free_allocated(), DBUS_ERROR_NO_MEMORY, dbus_new0, dbus_set_error(), DBUS_UID_FORMAT, DBUS_UID_UNSET, NULL, DBusUserInfo::uid, and DBusUserInfo::username.

Referenced by _dbus_is_console_user(), _dbus_user_database_get_uid(), and _dbus_user_database_get_username().

DBusGroupInfo* _dbus_user_database_lookup_group | ( | DBusUserDatabase * | db,
|  | dbus_gid_t | gid,
|  | const DBusString * | groupname,
|  | DBusError * | error
| ) |  |

Looks up a gid or group name in the user database.

Only one of name or GID can be provided. There are wrapper functions for this that are better to use, this one does no locking or anything on the database and otherwise sort of sucks.

Parameters

  db | the database
  gid | the group ID or DBUS_GID_UNSET
  groupname | group name or NULL
  error | error to fill in

Returns
  the entry in the database

Definition at line 235 of file dbus-userdb-util.c.

References _dbus_group_info_fill(), _dbus_group_info_fill_gid(), _dbus_group_info_free_allocated(), _dbus_hash_table_insert_string(), _dbus_hash_table_insert_uintptr(), _dbus_hash_table_lookup_string(), _dbus_hash_table_lookup_uintptr(), _dbus_hash_table_remove_uintptr(), _dbus_is_a_number(), _dbus_string_get_const_data(), DBUS_ERROR_NO_MEMORY, DBUS_GID_FORMAT, DBUS_GID_UNSET, dbus_new0, dbus_set_error(), DBUS_UID_UNSET, DBusGroupInfo::gid, DBusGroupInfo::groupname, and NULL.

Referenced by _dbus_user_database_get_gid(), and _dbus_user_database_get_groupname().

DBusUserDatabase* _dbus_user_database_new | ( | void | ) |  |

Creates a new user database object used to look up and cache user information.

Returns
  new database, or NULL on out of memory

Definition at line 531 of file dbus-userdb.c.

References _dbus_group_info_free_allocated(), _dbus_hash_table_new(), _dbus_user_database_unref(), _dbus_user_info_free_allocated(), DBUS_HASH_STRING, DBUS_HASH_UINTPTR, dbus_new0, and NULL.

void _dbus_user_database_unref | ( | DBusUserDatabase * | db) |  |

Decrements refcount of user database.

Parameters

  db | the database

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

References _dbus_assert, _dbus_hash_table_unref(), and dbus_free().

Referenced by _dbus_user_database_new().

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 76 of file dbus-userdb.c.

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

Referenced by _dbus_user_info_free_allocated().

void _dbus_user_info_free_allocated | ( | DBusUserInfo * | info) |  |

Frees the given DBusUserInfo's members with _dbus_user_info_free() and also calls dbus_free() on the block itself.

Parameters

  info | the info

Definition at line 45 of file dbus-userdb.c.

References _dbus_user_info_free(), dbus_free(), and NULL.

Referenced by _dbus_user_database_lookup(), and _dbus_user_database_new().

dbus_bool_t _dbus_username_from_current_process | ( | const DBusString ** | username) |  |

Gets username of user owning current process.

The returned string is valid until dbus_shutdown() is called.

Parameters

  username | place to store pointer to username

Returns
  FALSE if no memory

Definition at line 364 of file dbus-userdb.c.

References _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, and TRUE.

dbus_bool_t _dbus_uuid_encode | ( | const DBusGUID * | uuid,
|  | DBusString * | encoded
| ) |  |

Hex-encode a UUID.

Parameters

  uuid | the uuid
  encoded | string to append hex uuid to

Returns
  FALSE if no memory

Definition at line 681 of file dbus-internals.c.

References _dbus_string_get_length(), _dbus_string_hex_encode(), _dbus_string_init_const_len(), and DBusGUID::as_bytes.

Referenced by _dbus_get_local_machine_uuid_encoded(), and _dbus_server_init_base().

dbus_bool_t _dbus_verify_daemon_user | ( | const char * | user) |  |

Verify that after the fork we can successfully change to this user.

Parameters

  user | the username given in the daemon configuration

Returns
  TRUE if username is valid

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

void _dbus_warn | ( | const char * | format,
|  |  | ...
| ) |  |

Prints a warning message to stderr.

Can optionally be made to exit fatally by setting DBUS_FATAL_WARNINGS, but this is rarely used. This function should be considered pretty much equivalent to fprintf(stderr). _dbus_warn_check_failed() on the other hand is suitable for use when a programming mistake has been made.

Parameters

  format | printf-style format string.

Definition at line 245 of file dbus-internals.c.

References _dbus_abort().

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_babysitter_unref(), _dbus_change_to_daemon_user(), _dbus_full_duplex_pipe(), _dbus_get_tmpdir(), _dbus_listen_tcp_socket(), _dbus_listen_unix_socket(), _dbus_marshal_skip_basic(), _dbus_message_iter_get_args_valist(), _dbus_object_tree_unregister_and_unlock(), _dbus_poll(), _dbus_real_assert(), _dbus_real_assert_not_reached(), _dbus_server_new_for_launchd(), _dbus_watch_unref(), dbus_connection_register_fallback(), dbus_connection_register_object_path(), dbus_malloc(), dbus_malloc0(), dbus_message_append_args_valist(), and dbus_realloc().

void _dbus_warn_check_failed | ( | const char * | format,
|  |  | ...
| ) |  |

Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in that it prefixes the pid and defaults to fatal.

This should be used only when a programming error has been detected. (NOT for unavoidable errors that an app might handle - those should be returned as DBusError.) Calling this means "there is a bug"

Definition at line 273 of file dbus-internals.c.

References _dbus_abort(), and _dbus_pid_for_log().

Referenced by _dbus_data_slot_allocator_alloc(), _dbus_get_local_machine_uuid_encoded(), _dbus_marshal_read_basic(), _dbus_transport_handle_watch(), _dbus_type_reader_recurse(), dbus_connection_close(), dbus_connection_remove_filter(), dbus_connection_unref(), dbus_server_ref(), dbus_server_set_timeout_functions(), dbus_server_set_watch_functions(), dbus_server_unref(), and dbus_watch_handle().

dbus_bool_t _dbus_windows_user_is_process_owner | ( | const char * | windows_sid) |  |

Checks to see if the Windows user SID matches the owner of the process.

Should always return FALSE on UNIX.

Parameters

  windows_sid | the Windows user SID

Returns
  TRUE if this user owns the process.

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

dbus_bool_t _dbus_write_pid_to_file_and_pipe | ( | const DBusString * | pidfile,
|  | DBusPipe * | print_pid_pipe,
|  | dbus_pid_t | pid_to_write,
|  | DBusError * | error
| ) |  |

Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a pipe (if non-NULL).

Does nothing if pidfile and print_pid_pipe are both NULL.

Parameters

  pidfile | the file to write to or NULL
  print_pid_pipe | the pipe to write to or NULL
  pid_to_write | the pid to write out
  error | error on failure

Returns
  FALSE if error is set

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

Referenced by _dbus_become_daemon().

## Variable Documentation

const char* _dbus_return_if_fail_warning_format

Initial value:
=
"arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
"This is normally a bug in some application using the D-Bus library.\n"

String used in _dbus_return_if_fail macro.

Definition at line 902 of file dbus-internals.c.

Referenced by dbus_server_ref(), and dbus_server_unref().