D-Bus 1.15.12
Data Structures | Macros | Enumerations | Functions | Variables

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.
 
#define _dbus_assert_not_reached(explanation)    _dbus_real_assert_not_reached (explanation, __FILE__, __LINE__)
 Aborts with an error message if called.
 
#define _DBUS_N_ELEMENTS(array)   ((int) (sizeof ((array)) / sizeof ((array)[0])))
 Computes the number of elements in a fixed-size array using sizeof().
 
#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.
 
#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.
 
#define _DBUS_ZERO(object)   (memset (&(object), '\0', sizeof ((object))))
 Sets all bits in an object to zero.
 
#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_LOCK(name)   _dbus_lock (_DBUS_LOCK_##name)
 Locks a global lock, initializing it first if necessary.
 
#define _DBUS_UNLOCK(name)   _dbus_unlock (_DBUS_LOCK_##name)
 Unlocks a global lock.
 
#define LIVE_CHILDREN(sitter)   ((sitter)->socket_to_babysitter.fd >= 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.
 

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

 _DBUS_STATIC_ASSERT (sizeof(void *)==DBUS_SIZEOF_VOID_P)
 
 _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF(void *)==_DBUS_ALIGNOF(DBusShutdownFunction))
 
int _dbus_get_check_failed_count (void)
 
void _dbus_warn (const char *format,...)
 Prints a warning message to stderr.
 
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 defaults to fatal.
 
char * _dbus_strdup (const char *str)
 Duplicates a string.
 
void * _dbus_memdup (const void *mem, size_t n_bytes)
 Duplicates a block of memory.
 
char ** _dbus_dup_string_array (const char **array)
 Duplicates a string array.
 
dbus_bool_t _dbus_string_array_contains (const char **array, const char *str)
 Checks whether a string array contains the given string.
 
size_t _dbus_string_array_length (const char **array)
 Returns the size of a string array.
 
dbus_bool_t _dbus_generate_uuid (DBusGUID *uuid, DBusError *error)
 Generates a new UUID.
 
dbus_bool_t _dbus_uuid_encode (const DBusGUID *uuid, DBusString *encoded)
 Hex-encode a UUID.
 
dbus_bool_t _dbus_write_uuid_file (const DBusString *filename, const DBusGUID *uuid, DBusError *error)
 Write the give UUID to a file.
 
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.
 
dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str, DBusError *error)
 Gets the hex-encoded UUID of the machine this function is executed on.
 
void _dbus_warn_return_if_fail (const char *function, const char *assertion, const char *file, int line)
 
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.
 
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.
 
DBusBabysitter_dbus_babysitter_ref (DBusBabysitter *sitter)
 Increment the reference count on the babysitter object.
 
void _dbus_babysitter_unref (DBusBabysitter *sitter)
 Decrement the reference count on the babysitter object.
 
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.
 
dbus_bool_t _dbus_babysitter_get_child_exited (DBusBabysitter *sitter)
 Checks whether the child has exited, without blocking.
 
dbus_bool_t _dbus_babysitter_get_child_exit_status (DBusBabysitter *sitter, int *status)
 Gets the exit status of the child.
 
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).
 
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.
 
dbus_bool_t _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, const char *log_name, char *const *argv, char *const *env, DBusSpawnFlags flags, DBusSpawnChildSetupFunc child_setup, void *user_data, DBusError *error)
 Spawns a new process.
 
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.
 
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).
 
dbus_bool_t _dbus_verify_daemon_user (const char *user)
 Verify that after the fork we can successfully change to this user.
 
dbus_bool_t _dbus_change_to_daemon_user (const char *user, DBusError *error)
 Changes the user and group the bus is running as.
 
DBusRLimit * _dbus_rlimit_save_fd_limit (DBusError *error)
 
dbus_bool_t _dbus_rlimit_raise_fd_limit (DBusError *error)
 
dbus_bool_t _dbus_rlimit_restore_fd_limit (DBusRLimit *saved, DBusError *error)
 
void _dbus_rlimit_free (DBusRLimit *lim)
 
void _dbus_set_signal_handler (int sig, DBusSignalHandler handler)
 Installs a UNIX signal handler.
 
dbus_bool_t _dbus_file_exists (const char *file)
 Checks if a file exists.
 
dbus_bool_t _dbus_path_is_absolute (const DBusString *filename)
 Checks whether the filename is an absolute path.
 
dbus_bool_t _dbus_stat (const DBusString *filename, DBusStat *statbuf, DBusError *error)
 stat() wrapper.
 
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_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.
 
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.
 
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.
 
dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids, DBusError *error)
 Gets all groups corresponding to the given UNIX user ID.
 
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.
 
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.
 
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.
 
dbus_bool_t _dbus_generate_random_bytes_buffer (char *buffer, int n_bytes, DBusError *error)
 Fills n_bytes of the given buffer with random bytes.
 
dbus_bool_t _dbus_generate_random_ascii (DBusString *str, int n_bytes, DBusError *error)
 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 errno, or Windows errno or WinSock error value into a DBusError name.
 
const char * _dbus_error_from_system_errno (void)
 Converts the current system errno value into a DBusError name.
 
void _dbus_set_errno_to_zero (void)
 Assign 0 to the global errno variable.
 
dbus_bool_t _dbus_get_is_errno_enomem (int e)
 See if errno is ENOMEM.
 
dbus_bool_t _dbus_get_is_errno_eintr (int e)
 See if errno is EINTR.
 
dbus_bool_t _dbus_get_is_errno_epipe (int e)
 See if errno is EPIPE.
 
dbus_bool_t _dbus_get_is_errno_etoomanyrefs (int e)
 See if errno is ETOOMANYREFS.
 
const char * _dbus_strerror_from_errno (void)
 Get error message from errno.
 
void _dbus_log (DBusSystemLogSeverity severity, const char *msg,...)
 Log a message to the system log file (e.g.
 
dbus_bool_t _dbus_inet_sockaddr_to_string (const void *sockaddr_pointer, size_t len, char *string, size_t string_len, const char **family_name, dbus_uint16_t *port, DBusError *error)
 
void _dbus_set_error_with_inet_sockaddr (DBusError *error, const void *sockaddr_pointer, size_t len, const char *description, int saved_errno)
 
void _dbus_combine_tcp_errors (DBusList **sources, const char *summary, const char *host, const char *port, DBusError *dest)
 
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.
 
dbus_bool_t _dbus_get_user_id (const DBusString *username, dbus_uid_t *uid)
 Gets user ID given username.
 
dbus_bool_t _dbus_get_group_id (const DBusString *groupname, dbus_gid_t *gid)
 Gets group ID given groupname.
 
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.
 
const 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.
 
dbus_bool_t _dbus_groups_from_uid (dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids, DBusError *error)
 Gets all groups corresponding to the given UID.
 
void _dbus_user_info_unref (DBusUserInfo *info)
 Decrements the reference count.
 
void _dbus_group_info_unref (DBusGroupInfo *info)
 Decrements the reference count.
 
void _dbus_user_info_free (DBusUserInfo *info)
 Frees the members of info (but not info itself)
 
void _dbus_group_info_free (DBusGroupInfo *info)
 Frees the members of info (but not info itself).
 
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.
 
const 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.
 
dbus_bool_t _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()).
 
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.
 
dbus_bool_t _dbus_homedir_from_current_process (const DBusString **homedir)
 Gets homedir of user owning current process.
 
dbus_bool_t _dbus_homedir_from_uid (dbus_uid_t uid, DBusString *homedir)
 Gets the home directory for the given user.
 
dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, const DBusString *username, DBusCredentialsAddFlags flags, DBusError *error)
 Adds the credentials corresponding to the given username.
 
DBusUserDatabase * _dbus_user_database_new (void)
 Creates a new user database object used to look up and cache user information.
 
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.
 
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.
 
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.
 

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.
 

Detailed Description

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

Macro Definition Documentation

◆ _dbus_assert

#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
conditioncondition which must be true.

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

◆ _dbus_assert_not_reached

#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
explanationexplanation of what happened if the code was reached.

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

◆ _DBUS_INT16_MAX

#define _DBUS_INT16_MAX   ((dbus_int16_t) 0x7fff)

Maximum value of type "int16".

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

◆ _DBUS_INT16_MIN

#define _DBUS_INT16_MIN   ((dbus_int16_t) 0x8000)

Minimum value of type "int16".

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

◆ _DBUS_INT32_MAX

#define _DBUS_INT32_MAX   ((dbus_int32_t) 0x7fffffff)

Maximum value of type "int32".

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

◆ _DBUS_INT32_MIN

#define _DBUS_INT32_MIN   ((dbus_int32_t) 0x80000000)

Minimum value of type "int32".

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

◆ _DBUS_INT_MAX

#define _DBUS_INT_MAX   _DBUS_INT32_MAX

Maximum value of type "int".

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

◆ _DBUS_INT_MIN

#define _DBUS_INT_MIN   _DBUS_INT32_MIN

Minimum value of type "int".

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

◆ _DBUS_INT_TO_POINTER

#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
integerthe integer to stuff into a pointer.

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

◆ _DBUS_LOCK

#define _DBUS_LOCK (   name)    _dbus_lock (_DBUS_LOCK_##name)

Locks a global lock, initializing it first if necessary.

Returns
FALSE if not enough memory

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

◆ _DBUS_LOCK_NAME

#define _DBUS_LOCK_NAME (   name)    _DBUS_LOCK_##name

Expands to name of a global lock variable.

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

◆ _DBUS_N_ELEMENTS

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

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

Parameters
arraythe array to count elements in.

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

◆ _DBUS_POINTER_TO_INT

#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
pointerpointer to extract an integer from.

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

◆ _DBUS_UINT16_MAX

#define _DBUS_UINT16_MAX   ((dbus_uint16_t)0xffff)

Maximum value of type "uint16".

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

◆ _DBUS_UINT32_MAX

#define _DBUS_UINT32_MAX   ((dbus_uint32_t)0xffffffff)

Maximum value of type "uint32".

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

◆ _DBUS_UINT_MAX

#define _DBUS_UINT_MAX   _DBUS_UINT32_MAX

Maximum value of type "uint".

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

◆ _DBUS_UNLOCK

#define _DBUS_UNLOCK (   name)    _dbus_unlock (_DBUS_LOCK_##name)

Unlocks a global lock.

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

◆ _DBUS_ZERO

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

Sets all bits in an object to zero.

Parameters
objectthe object to be zeroed.

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

◆ LIVE_CHILDREN

#define LIVE_CHILDREN (   sitter)    ((sitter)->socket_to_babysitter.fd >= 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.

Definition at line 697 of file dbus-spawn-unix.c.

◆ READ_END

#define READ_END   0

Helps remember which end of the pipe is which.

Definition at line 895 of file dbus-spawn-unix.c.

◆ WRITE_END

#define WRITE_END   1

Helps remember which end of the pipe is which.

Definition at line 897 of file dbus-spawn-unix.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Definition at line 240 of file dbus-spawn-unix.c.

◆ ReadStatus

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 75 of file dbus-spawn-unix.c.

Function Documentation

◆ _dbus_babysitter_get_child_exit_status()

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
sitterthe babysitter
statusthe returned status code
Returns
FALSE on failure

Definition at line 753 of file dbus-spawn-unix.c.

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

◆ _dbus_babysitter_get_child_exited()

dbus_bool_t _dbus_babysitter_get_child_exited ( DBusBabysitter sitter)

Checks whether the child has exited, without blocking.

Parameters
sitterthe babysitter

Definition at line 728 of file dbus-spawn-unix.c.

References FALSE, LIVE_CHILDREN, and DBusBabysitter::socket_to_babysitter.

Referenced by _dbus_babysitter_get_child_exit_status(), and _dbus_babysitter_set_child_exit_error().

◆ _dbus_babysitter_kill_child()

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
sitterthe babysitter object

Definition at line 706 of file dbus-spawn-unix.c.

References DBusBabysitter::grandchild_pid, LIVE_CHILDREN, and TRUE.

◆ _dbus_babysitter_ref()

DBusBabysitter * _dbus_babysitter_ref ( DBusBabysitter sitter)

Increment the reference count on the babysitter object.

Parameters
sitterthe babysitter
Returns
the babysitter

Definition at line 314 of file dbus-spawn-unix.c.

References _dbus_assert, NULL, and DBusBabysitter::refcount.

◆ _dbus_babysitter_set_child_exit_error()

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
sitterthe babysitter
erroran error to fill in

Definition at line 777 of file dbus-spawn-unix.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::have_child_status, DBusBabysitter::have_exec_errnum, DBusBabysitter::have_fork_errnum, DBusBabysitter::log_name, and DBusBabysitter::status.

◆ _dbus_babysitter_set_result_function()

void _dbus_babysitter_set_result_function ( DBusBabysitter sitter,
DBusBabysitterFinishedFunc  finished,
void *  user_data 
)

Definition at line 1535 of file dbus-spawn-unix.c.

◆ _dbus_babysitter_set_watch_functions()

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
sitterthe babysitter
add_functionfunction to begin monitoring a new descriptor.
remove_functionfunction to stop monitoring a descriptor.
toggled_functionfunction to notify when the watch is enabled/disabled
datadata to pass to add_function and remove_function.
free_data_functionfunction to be called to free the data.
Returns
FALSE on failure (no memory)

Definition at line 835 of file dbus-spawn-unix.c.

References _dbus_watch_list_set_functions(), and DBusBabysitter::watches.

◆ _dbus_babysitter_unref()

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
sitterthe babysitter

Definition at line 336 of file dbus-spawn-unix.c.

References _dbus_assert, _dbus_warn(), _dbus_watch_list_free(), dbus_free(), DBusBabysitter::log_name, NULL, DBusBabysitter::refcount, DBusBabysitter::sitter_pid, DBusBabysitter::status, and DBusBabysitter::watches.

Referenced by _dbus_spawn_async_with_babysitter().

◆ _dbus_become_daemon()

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
pidfileNULL, or pidfile to create
print_pid_pipepipe to print daemon's pid to, or -1 for none
errorreturn location for errors
keep_umaskTRUE to keep the original umask
Returns
FALSE on failure

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

References _dbus_assert_not_reached, _dbus_ensure_standard_fds(), _dbus_error_from_errno(), _dbus_getenv(), _dbus_warn(), _dbus_write_pid_to_file_and_pipe(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, DBusError::message, NULL, and TRUE.

◆ _dbus_change_to_daemon_user()

dbus_bool_t _dbus_change_to_daemon_user ( const char *  user,
DBusError error 
)

Changes the user and group the bus is running as.

Parameters
userthe user to become
errorreturn location for errors
Returns
FALSE on failure

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

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

◆ _dbus_combine_tcp_errors()

void _dbus_combine_tcp_errors ( DBusList **  sources,
const char *  summary,
const char *  host,
const char *  port,
DBusError dest 
)

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

◆ _dbus_credentials_add_from_user()

dbus_bool_t _dbus_credentials_add_from_user ( DBusCredentials credentials,
const DBusString username,
DBusCredentialsAddFlags  flags,
DBusError error 
)

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.

Parameters
credentialscredentials to fill in
usernamethe username
Returns
TRUE if the username existed and we got some credentials

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

References _dbus_credentials_add_unix_uid(), _dbus_is_a_number(), _dbus_user_database_get_system(), _dbus_user_database_get_username(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), DBUS_ERROR_INVALID_ARGS, dbus_set_error(), DBUS_UID_UNSET, FALSE, NULL, TRUE, and DBusUserInfo::uid.

◆ _dbus_directory_close()

void _dbus_directory_close ( DBusDirIter iter)

Closes a directory iteration.

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

References DBusDirIter::d, and dbus_free().

◆ _dbus_directory_get_next_file()

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
iterthe iterator
filenamestring to be set to the next file in the dir
errorreturn location for error
Returns
TRUE if filename was filled in with a new filename

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

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

◆ _dbus_directory_open()

DBusDirIter * _dbus_directory_open ( const DBusString filename,
DBusError error 
)

Open a directory to iterate over.

Parameters
filenamethe directory name
errorexception return object or NULL
Returns
new iterator, or NULL on error

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

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

◆ _dbus_dup_string_array()

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
arrayarray to duplicate.
Returns
newly-allocated copy.

Definition at line 672 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().

◆ _dbus_error_from_errno()

const char * _dbus_error_from_errno ( int  error_number)

◆ _dbus_error_from_system_errno()

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

References _dbus_error_from_errno().

◆ _dbus_file_exists()

dbus_bool_t _dbus_file_exists ( const char *  file)

Checks if a file exists.

File interface.

Parameters
filefull path to the file
Returns
TRUE if file exists

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

◆ _dbus_generate_random_ascii()

dbus_bool_t _dbus_generate_random_ascii ( DBusString str,
int  n_bytes,
DBusError error 
)

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

Parameters
strthe string
n_bytesthe number of random ASCII bytes to append to string
errorlocation to store reason for failure
Returns
TRUE on success, FALSE if no memory or other failure

Definition at line 525 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_string_save_to_file().

◆ _dbus_generate_random_bytes_buffer()

dbus_bool_t _dbus_generate_random_bytes_buffer ( char *  buffer,
int  n_bytes,
DBusError error 
)

Fills n_bytes of the given buffer with random bytes.

Random numbers.

Parameters
bufferan allocated buffer
n_bytesthe number of bytes in buffer to write to
errorlocation to store reason for failure
Returns
TRUE on success

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

References _dbus_generate_random_bytes(), _dbus_string_copy_to_buffer(), _dbus_string_free(), _dbus_string_init(), FALSE, and TRUE.

Referenced by _dbus_generate_uuid().

◆ _dbus_generate_uuid()

dbus_bool_t _dbus_generate_uuid ( DBusGUID uuid,
DBusError error 
)

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
uuidthe uuid to initialize
errorlocation to store reason for failure
Returns
TRUE on success

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

References _dbus_generate_random_bytes_buffer(), _dbus_get_real_time(), DBusGUID::as_bytes, DBusGUID::as_uint32s, dbus_error_free(), dbus_error_init(), dbus_set_error(), FALSE, DBusError::message, DBusError::name, NULL, and TRUE.

Referenced by _dbus_create_uuid(), _dbus_read_local_machine_uuid(), _dbus_read_uuid_file(), and _dbus_server_init_base().

◆ _dbus_get_check_failed_count()

int _dbus_get_check_failed_count ( void  )

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

◆ _dbus_get_group_id()

dbus_bool_t _dbus_get_group_id ( const DBusString groupname,
dbus_gid_t gid 
)

Gets group ID given groupname.

Parameters
groupnamethe groupname
gidreturn location for GID
Returns
TRUE if group name existed and we got the GID

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

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

Referenced by _dbus_parse_unix_group_from_config().

◆ _dbus_get_is_errno_eintr()

dbus_bool_t _dbus_get_is_errno_eintr ( int  e)

See if errno is EINTR.

Returns
TRUE if e == EINTR

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

◆ _dbus_get_is_errno_enomem()

dbus_bool_t _dbus_get_is_errno_enomem ( int  e)

See if errno is ENOMEM.

Returns
TRUE if e == ENOMEM

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

◆ _dbus_get_is_errno_epipe()

dbus_bool_t _dbus_get_is_errno_epipe ( int  e)

See if errno is EPIPE.

Returns
TRUE if errno == EPIPE

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

◆ _dbus_get_is_errno_etoomanyrefs()

dbus_bool_t _dbus_get_is_errno_etoomanyrefs ( int  e)

See if errno is ETOOMANYREFS.

Returns
TRUE if errno == ETOOMANYREFS

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

References FALSE.

◆ _dbus_get_local_machine_uuid_encoded()

dbus_bool_t _dbus_get_local_machine_uuid_encoded ( DBusString uuid_str,
DBusError error 
)

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_strstring to append hex-encoded machine uuid to
errorlocation to store reason for failure
Returns
TRUE if successful

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

References _dbus_current_generation, _DBUS_LOCK, _dbus_read_local_machine_uuid(), _DBUS_UNLOCK, _dbus_uuid_encode(), FALSE, and TRUE.

Referenced by _dbus_get_autolaunch_address(), and dbus_try_get_local_machine_id().

◆ _dbus_get_user_id()

dbus_bool_t _dbus_get_user_id ( const DBusString username,
dbus_uid_t uid 
)

Gets user ID given username.

Parameters
usernamethe username
uidreturn location for UID
Returns
TRUE if username existed and we got the UID

Definition at line 131 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_get_user_id_and_primary_group()

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
usernamethe username
uid_preturn location for UID
gid_preturn location for GID
Returns
TRUE if username existed and we got the UID and GID

Definition at line 186 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_group_info_fill()

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
infothe group info struct
groupnamename of group
errorthe error return
Returns
FALSE if error is set

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

References DBUS_GID_UNSET.

Referenced by _dbus_user_database_lookup_group().

◆ _dbus_group_info_fill_gid()

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
infothe group info struct
gidgroup ID
errorthe error return
Returns
FALSE if error is set

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

References NULL.

Referenced by _dbus_user_database_lookup_group().

◆ _dbus_group_info_free()

void _dbus_group_info_free ( DBusGroupInfo info)

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

Parameters
infothe group info

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

References dbus_free(), and DBusGroupInfo::groupname.

Referenced by _dbus_group_info_unref().

◆ _dbus_group_info_unref()

void _dbus_group_info_unref ( DBusGroupInfo info)

Decrements the reference count.

If it reaches 0, frees the given DBusGroupInfo's members with _dbus_group_info_free() and also calls dbus_free() on the block itself

Parameters
infothe info

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

References _dbus_assert, _dbus_group_info_free(), dbus_free(), NULL, and DBusGroupInfo::refcount.

Referenced by _dbus_user_database_lookup_group(), and _dbus_user_database_new().

◆ _dbus_groups_from_uid()

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

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
uidthe UID
group_idsreturn location for array of group IDs
n_group_idsreturn location for length of returned array
errorerror to fill in on failure
Returns
TRUE if the UID existed and we got some credentials

Definition at line 349 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_homedir_from_current_process()

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
homedirplace to store pointer to homedir
Returns
FALSE if no memory

Definition at line 442 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_homedir_from_uid()

dbus_bool_t _dbus_homedir_from_uid ( dbus_uid_t  uid,
DBusString homedir 
)

Gets the home directory for the given user.

Parameters
uidthe uid
homedirstring to append home directory to
Returns
TRUE if user existed and we appended their homedir

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

References _dbus_getenv(), _dbus_geteuid(), _dbus_getuid(), _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_inet_sockaddr_to_string()

dbus_bool_t _dbus_inet_sockaddr_to_string ( const void *  sockaddr_pointer,
size_t  len,
char *  string,
size_t  string_len,
const char **  family_name,
dbus_uint16_t *  port,
DBusError error 
)

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

◆ _dbus_is_a_number()

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
strthe string to check
numthe memory location of the unsigned long to fill in
Returns
TRUE if str is a number and num is filled in

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

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

Referenced by _dbus_credentials_add_from_user(), _dbus_user_database_lookup(), and _dbus_user_database_lookup_group().

◆ _dbus_is_console_user()

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
uidUID of person to check
errorreturn location for errors
Returns
TRUE if the UID is the same as the console user and there are no errors

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

References _dbus_error_from_errno(), _dbus_stat(), _dbus_string_append(), _dbus_string_free(), _dbus_string_init(), dbus_set_error(), DBUS_UID_FORMAT, FALSE, NULL, TRUE, and DBusStat::uid.

Referenced by _dbus_unix_user_is_at_console().

◆ _dbus_log()

void _dbus_log ( DBusSystemLogSeverity  severity,
const char *  msg,
  ... 
)

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

syslog on Unix) and/or stderr.

Parameters
severitya severity value
msga printf-style format string

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

References _dbus_logv().

◆ _dbus_memdup()

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

Duplicates a block of memory.

Returns NULL on failure.

Parameters
memmemory to copy
n_bytesnumber of bytes to copy
Returns
the copy

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

References dbus_malloc(), and NULL.

Referenced by _dbus_credentials_add_adt_audit_data(), and _dbus_decompose_path().

◆ _dbus_parse_unix_group_from_config()

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
groupnamethe groupname text
gid_pplace to return the gid
Returns
TRUE on success

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

References _dbus_get_group_id().

◆ _dbus_parse_unix_user_from_config()

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
usernamethe username text
uid_pplace to return the uid
Returns
TRUE on success

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

References _dbus_get_user_id().

◆ _dbus_path_is_absolute()

dbus_bool_t _dbus_path_is_absolute ( const DBusString filename)

Checks whether the filename is an absolute path.

Parameters
filenamethe filename
Returns
TRUE if an absolute path

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

References _dbus_string_get_byte(), _dbus_string_get_length(), and FALSE.

◆ _dbus_read_uuid_file()

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
filenamethe name of the file
uuiduuid to be initialized with the loaded uuid
create_if_not_foundTRUE to create a new uuid and save it if the file doesn't exist
errorthe error return
Returns
FALSE if the error is set

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

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

Referenced by _dbus_get_uuid(), and _dbus_read_local_machine_uuid().

◆ _dbus_real_assert()

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
conditionTRUE if assertion succeeded
condition_textcondition as a string
filefile the assertion is in
lineline the assertion is in
funcfunction the assertion is in

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

References _dbus_abort(), and _dbus_warn().

◆ _dbus_real_assert_not_reached()

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
explanationwhat was reached that shouldn't have been
filefile the assertion is in
lineline the assertion is in

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

References _dbus_abort(), and _dbus_warn().

◆ _dbus_rlimit_free()

void _dbus_rlimit_free ( DBusRLimit *  lim)

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

◆ _dbus_rlimit_raise_fd_limit()

dbus_bool_t _dbus_rlimit_raise_fd_limit ( DBusError error)

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

◆ _dbus_rlimit_restore_fd_limit()

dbus_bool_t _dbus_rlimit_restore_fd_limit ( DBusRLimit *  saved,
DBusError error 
)

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

◆ _dbus_rlimit_save_fd_limit()

DBusRLimit * _dbus_rlimit_save_fd_limit ( DBusError error)

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

◆ _dbus_set_errno_to_zero()

void _dbus_set_errno_to_zero ( void  )

Assign 0 to the global errno variable.

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

Referenced by _dbus_string_parse_int(), _dbus_string_parse_int64(), and _dbus_string_parse_uint().

◆ _dbus_set_error_with_inet_sockaddr()

void _dbus_set_error_with_inet_sockaddr ( DBusError error,
const void *  sockaddr_pointer,
size_t  len,
const char *  description,
int  saved_errno 
)

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

◆ _dbus_set_signal_handler()

void _dbus_set_signal_handler ( int  sig,
DBusSignalHandler  handler 
)

Installs a UNIX signal handler.

Parameters
sigthe signal to handle
handlerthe handler

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

References NULL.

◆ _dbus_spawn_async_with_babysitter()

dbus_bool_t _dbus_spawn_async_with_babysitter ( DBusBabysitter **  sitter_p,
const char *  log_name,
char *const *  argv,
char *const *  env,
DBusSpawnFlags flags  flags,
DBusSpawnChildSetupFunc child_setup  child_setup,
void *  user_data,
DBusError error 
)

Spawns a new process.

On Unix platforms, the child_setup function is passed the given user_data and is run in the child after fork() but before calling exec(). This can be used to change uid, resource limits and so on. On Windows, this functionality does not fit the multi-processing model (Windows does the equivalent of fork() and exec() in a single API call), and the child_setup function and its user_data are ignored.

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_preturn location for babysitter or NULL
log_namethe name under which to log messages about this process being spawned
argvthe executable and arguments
envthe environment, or NULL to copy the parent's
child_setupfunction to call in child pre-exec()
user_datauser data for setup function
errorerror object to be filled in if function fails
Returns
TRUE on success, FALSE if error is filled in

Definition at line 1279 of file dbus-spawn-unix.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_babysitter_unref(), _dbus_dup(), _dbus_error_from_errno(), _dbus_fd_set_close_on_exec(), _dbus_reset_oom_score_adj(), _dbus_socketpair(), _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_set_error(), DBUS_WATCH_READABLE, DBusBabysitter::error_pipe_from_child, DBusBabysitter::error_watch, FALSE, DBusBabysitter::log_name, NULL, READ_END, DBusBabysitter::sitter_pid, DBusBabysitter::sitter_watch, DBusBabysitter::socket_to_babysitter, TRUE, DBusBabysitter::watches, and WRITE_END.

◆ _dbus_stat()

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

stat() wrapper.

Parameters
filenamethe filename to stat
statbufthe stat info to fill in
errorreturn location for error
Returns
FALSE if error was set

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

References _dbus_error_from_errno(), _dbus_string_get_const_data(), 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_strdup()

char * _dbus_strdup ( const char *  str)

◆ _dbus_strerror_from_errno()

const char * _dbus_strerror_from_errno ( void  )

◆ _dbus_string_array_contains()

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

Checks whether a string array contains the given string.

Parameters
arrayarray to search.
strstring to look for
Returns
TRUE if array contains string

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

References FALSE, NULL, and TRUE.

◆ _dbus_string_array_length()

size_t _dbus_string_array_length ( const char **  array)

Returns the size of a string array.

Parameters
arrayarray to search.
Returns
size of array

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

◆ _dbus_unix_groups_from_uid()

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

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
uidthe UID
group_idsreturn location for array of group IDs
n_group_idsreturn location for length of returned array
errorerror location
Returns
TRUE if the UID existed and we got some credentials

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

References _dbus_groups_from_uid().

◆ _dbus_unix_user_is_at_console()

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
uidUID of person to check
errorreturn location for errors
Returns
TRUE if the UID is the same as the console user and there are no errors

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

References _dbus_is_console_user().

◆ _dbus_unix_user_is_process_owner()

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
uidthe UNIX user ID
Returns
TRUE if this uid owns the process.

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

References _dbus_geteuid().

◆ _dbus_user_database_flush()

void _dbus_user_database_flush ( DBusUserDatabase *  db)

Flush all information out of the user database.

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

References _dbus_hash_table_remove_all().

Referenced by _dbus_user_database_flush_system().

◆ _dbus_user_database_flush_system()

void _dbus_user_database_flush_system ( void  )

Flushes the system global user database;.

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

References _dbus_user_database_flush(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), and NULL.

Referenced by _dbus_flush_caches().

◆ _dbus_user_database_get_system()

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 383 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(), and _dbus_homedir_from_uid().

◆ _dbus_user_database_get_uid()

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
dbuser database
uidthe user ID
inforeturn location for const ref to user info
errorerror location
Returns
FALSE if error is set

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

References _dbus_user_database_lookup(), and NULL.

Referenced by _dbus_groups_from_uid(), and _dbus_homedir_from_uid().

◆ _dbus_user_database_get_username()

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
dbuser database
usernamethe user name
inforeturn location for const ref to user info
errorerror location
Returns
FALSE if error is set

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

References _dbus_user_database_lookup(), DBUS_UID_UNSET, and NULL.

Referenced by _dbus_credentials_add_from_user(), and _dbus_get_user_id_and_primary_group().

◆ _dbus_user_database_lock_system()

dbus_bool_t _dbus_user_database_lock_system ( void  )

◆ _dbus_user_database_lookup()

const 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
dbthe database
uidthe user ID or DBUS_UID_UNSET
usernameusername or NULL
errorerror to fill in
Returns
the entry in the database (borrowed, do not free)

Definition at line 160 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_unref(), DBUS_ERROR_NO_MEMORY, dbus_new0, dbus_set_error(), DBUS_UID_FORMAT, DBUS_UID_UNSET, NULL, DBusUserInfo::refcount, DBusUserInfo::uid, and DBusUserInfo::username.

Referenced by _dbus_user_database_get_uid(), and _dbus_user_database_get_username().

◆ _dbus_user_database_lookup_group()

const 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
dbthe database
gidthe group ID or DBUS_GID_UNSET
groupnamegroup name or NULL
errorerror to fill in
Returns
the entry in the database (borrowed, do not free)

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

References _dbus_group_info_fill(), _dbus_group_info_fill_gid(), _dbus_group_info_unref(), _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, NULL, and DBusGroupInfo::refcount.

Referenced by _dbus_get_group_id().

◆ _dbus_user_database_new()

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

References _dbus_group_info_unref(), _dbus_hash_table_new(), _dbus_user_database_unref(), _dbus_user_info_unref(), DBUS_HASH_STRING, DBUS_HASH_UINTPTR, dbus_new0, and NULL.

◆ _dbus_user_database_unlock_system()

void _dbus_user_database_unlock_system ( void  )

◆ _dbus_user_database_unref()

void _dbus_user_database_unref ( DBusUserDatabase *  db)

Decrements refcount of user database.

Parameters
dbthe database

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

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

Referenced by _dbus_user_database_new().

◆ _dbus_user_info_free()

void _dbus_user_info_free ( DBusUserInfo info)

Frees the members of info (but not info itself)

Parameters
infothe user info struct

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

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

Referenced by _dbus_user_info_unref().

◆ _dbus_user_info_unref()

void _dbus_user_info_unref ( DBusUserInfo info)

Decrements the reference count.

If it reaches 0, frees the given DBusUserInfo's members with _dbus_user_info_free() and also calls dbus_free() on the block itself

Parameters
infothe info

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

References _dbus_assert, _dbus_user_info_free(), dbus_free(), NULL, and DBusUserInfo::refcount.

Referenced by _dbus_user_database_lookup(), and _dbus_user_database_new().

◆ _dbus_username_from_current_process()

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
usernameplace to store pointer to username
Returns
FALSE if no memory

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

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

◆ _dbus_uuid_encode()

dbus_bool_t _dbus_uuid_encode ( const DBusGUID uuid,
DBusString encoded 
)

Hex-encode a UUID.

Parameters
uuidthe uuid
encodedstring to append hex uuid to
Returns
FALSE if no memory

Definition at line 788 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(), _dbus_server_init_base(), and _dbus_write_uuid_file().

◆ _dbus_verify_daemon_user()

dbus_bool_t _dbus_verify_daemon_user ( const char *  user)

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

Parameters
userthe username given in the daemon configuration
Returns
TRUE if username is valid

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

References _dbus_get_user_id_and_primary_group(), _dbus_string_init_const(), and NULL.

◆ _dbus_warn()

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
formatprintf-style format string.

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

References _dbus_abort(), and _dbus_logv().

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_babysitter_unref(), _dbus_become_daemon(), _dbus_change_to_daemon_user(), _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_real_assert(), _dbus_real_assert_not_reached(), _dbus_server_new_for_launchd(), _dbus_socketpair(), _dbus_watch_unref(), dbus_connection_register_fallback(), dbus_connection_register_object_path(), dbus_malloc(), dbus_malloc0(), dbus_message_append_args_valist(), and dbus_realloc().

◆ _dbus_warn_check_failed()

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 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 310 of file dbus-internals.c.

References _dbus_abort(), and _dbus_logv().

Referenced by _dbus_marshal_read_basic(), _dbus_transport_handle_watch(), _dbus_type_reader_recurse(), dbus_connection_close(), dbus_connection_remove_filter(), dbus_connection_unref(), dbus_get_local_machine_id(), dbus_server_set_timeout_functions(), dbus_server_set_watch_functions(), and dbus_watch_handle().

◆ _dbus_warn_return_if_fail()

void _dbus_warn_return_if_fail ( const char *  function,
const char *  assertion,
const char *  file,
int  line 
)

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

◆ _dbus_windows_user_is_process_owner()

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_sidthe Windows user SID
Returns
TRUE if this user owns the process.

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

References FALSE.

◆ _dbus_write_pid_to_file_and_pipe()

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
pidfilethe file to write to or NULL
print_pid_pipethe pipe to write to or NULL
pid_to_writethe pid to write out
errorerror on failure
Returns
FALSE if error is set

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

References _dbus_string_append_printf(), _dbus_string_free(), _dbus_string_get_const_data(), _dbus_string_get_length(), _dbus_string_init(), DBUS_ERROR_FAILED, dbus_error_is_set(), DBUS_PID_FORMAT, dbus_set_error(), FALSE, NULL, and TRUE.

Referenced by _dbus_become_daemon().

◆ _dbus_write_uuid_file()

dbus_bool_t _dbus_write_uuid_file ( const DBusString filename,
const DBusGUID uuid,
DBusError error 
)

Write the give UUID to a file.

Parameters
filenamethe file to write
uuidthe UUID to save
errorused to raise an error
Returns
FALSE on error

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

References _dbus_string_append_byte(), _dbus_string_free(), _dbus_string_init(), _dbus_string_save_to_file(), _dbus_uuid_encode(), FALSE, and TRUE.

Referenced by _dbus_read_local_machine_uuid(), and _dbus_read_uuid_file().

Variable Documentation

◆ _dbus_no_memory_message

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.

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