dbus_bool_t bus_registry_set_service_context_table (BusRegistry *registry, DBusHashTable *table) { DBusHashTable *new_table; DBusHashIter iter; new_table = bus_selinux_id_table_new (); if (!new_table) return FALSE; _dbus_hash_iter_init (table, &iter); while (_dbus_hash_iter_next (&iter)) { const char *service = _dbus_hash_iter_get_string_key (&iter); const char *context = _dbus_hash_iter_get_value (&iter); if (!bus_selinux_id_table_insert (new_table, service, context)) return FALSE; } if (registry->service_sid_table) _dbus_hash_table_unref (registry->service_sid_table); registry->service_sid_table = new_table; return TRUE; }
DBusLoop* _dbus_loop_new (void) { DBusLoop *loop; loop = dbus_new0 (DBusLoop, 1); if (loop == NULL) return NULL; loop->watches = _dbus_hash_table_new (DBUS_HASH_POLLABLE, NULL, free_watch_table_entry); loop->socket_set = _dbus_socket_set_new (0); if (loop->watches == NULL || loop->socket_set == NULL) { if (loop->watches != NULL) _dbus_hash_table_unref (loop->watches); if (loop->socket_set != NULL) _dbus_socket_set_free (loop->socket_set); dbus_free (loop); return NULL; } loop->refcount = 1; return loop; }
void bus_registry_unref (BusRegistry *registry) { _dbus_assert (registry->refcount > 0); registry->refcount -= 1; if (registry->refcount == 0) { if (registry->service_hash) _dbus_hash_table_unref (registry->service_hash); if (registry->service_pool) _dbus_mem_pool_free (registry->service_pool); if (registry->owner_pool) _dbus_mem_pool_free (registry->owner_pool); if (registry->service_sid_table) _dbus_hash_table_unref (registry->service_sid_table); dbus_free (registry); } }
static void pipe_hash_unref (void) { _dbus_assert (server_pipe_hash != NULL); _dbus_assert (server_pipe_hash_refcount > 0); server_pipe_hash_refcount -= 1; if (server_pipe_hash_refcount == 0) { _dbus_hash_table_unref (server_pipe_hash); server_pipe_hash = NULL; } }
void _dbus_user_database_unref (DBusUserDatabase *db) { _dbus_assert (db->refcount > 0); db->refcount -= 1; if (db->refcount == 0) { if (db->users) _dbus_hash_table_unref (db->users); if (db->groups) _dbus_hash_table_unref (db->groups); if (db->users_by_name) _dbus_hash_table_unref (db->users_by_name); if (db->groups_by_name) _dbus_hash_table_unref (db->groups_by_name); dbus_free (db); } }
void bus_policy_unref (BusPolicy *policy) { _dbus_assert (policy->refcount > 0); policy->refcount -= 1; if (policy->refcount == 0) { _dbus_list_foreach (&policy->default_rules, free_rule_func, NULL); _dbus_list_clear (&policy->default_rules); _dbus_list_foreach (&policy->mandatory_rules, free_rule_func, NULL); _dbus_list_clear (&policy->mandatory_rules); _dbus_list_foreach (&policy->at_console_true_rules, free_rule_func, NULL); _dbus_list_clear (&policy->at_console_true_rules); _dbus_list_foreach (&policy->at_console_false_rules, free_rule_func, NULL); _dbus_list_clear (&policy->at_console_false_rules); if (policy->rules_by_uid) { _dbus_hash_table_unref (policy->rules_by_uid); policy->rules_by_uid = NULL; } if (policy->rules_by_gid) { _dbus_hash_table_unref (policy->rules_by_gid); policy->rules_by_gid = NULL; } dbus_free (policy); } }
void _dbus_loop_unref (DBusLoop *loop) { _dbus_assert (loop != NULL); _dbus_assert (loop->refcount > 0); loop->refcount -= 1; if (loop->refcount == 0) { while (loop->need_dispatch) { DBusConnection *connection = _dbus_list_pop_first (&loop->need_dispatch); dbus_connection_unref (connection); } _dbus_hash_table_unref (loop->watches); _dbus_socket_set_free (loop->socket_set); dbus_free (loop); } }
static int run_session (const char *dbus_daemon, const char *config_file, char *bus_address, char **argv, int prog_arg) { char *dbus_daemon_argv[3]; int ret = 127; HANDLE server_handle = NULL; HANDLE app_handle = NULL; DWORD exit_code; DBusString argv_strings[4]; DBusString address; char **env = NULL; DBusHashTable *env_table = NULL; long sec,usec; dbus_bool_t result = TRUE; char *key = NULL; char *value = NULL; if (!_dbus_string_init (&argv_strings[0])) result = FALSE; if (!_dbus_string_init (&argv_strings[1])) result = FALSE; if (!_dbus_string_init (&argv_strings[2])) result = FALSE; if (!_dbus_string_init (&address)) result = FALSE; if (!result) goto out; /* run dbus daemon */ _dbus_get_real_time (&sec, &usec); /* On Windows it's difficult to make use of --print-address to * convert a listenable address into a connectable address, so instead * we tell the temporary dbus-daemon to use the Windows autolaunch * mechanism, with a unique scope that is shared by this dbus-daemon, * the app process that defines its lifetime, and any other child * processes they might have. */ _dbus_string_append_printf (&address, "autolaunch:scope=dbus-tmp-session-%ld%ld-" DBUS_PID_FORMAT, sec, usec, _dbus_getpid ()); _dbus_string_append_printf (&argv_strings[0], "%s", dbus_daemon); if (config_file != NULL) _dbus_string_append_printf (&argv_strings[1], "--config-file=%s", config_file); else _dbus_string_append_printf (&argv_strings[1], "--session"); _dbus_string_append_printf (&argv_strings[2], "--address=%s", _dbus_string_get_const_data (&address)); dbus_daemon_argv[0] = _dbus_string_get_data (&argv_strings[0]); dbus_daemon_argv[1] = _dbus_string_get_data (&argv_strings[1]); dbus_daemon_argv[2] = _dbus_string_get_data (&argv_strings[2]); dbus_daemon_argv[3] = NULL; server_handle = _dbus_spawn_program (dbus_daemon, dbus_daemon_argv, NULL); if (!server_handle) { _dbus_win_stderr_win_error (me, "Could not start dbus daemon", GetLastError ()); goto out; } /* run app */ env = _dbus_get_environment (); env_table = _dbus_hash_table_new (DBUS_HASH_STRING, dbus_free, dbus_free); if (!_dbus_hash_table_from_array (env_table, env, '=')) { goto out; } /* replace DBUS_SESSION_BUS_ADDRESS in environment */ if (!_dbus_string_steal_data (&address, &value)) goto out; key = _dbus_strdup ("DBUS_SESSION_BUS_ADDRESS"); if (key == NULL) goto out; if (_dbus_hash_table_insert_string (env_table, key, value)) { /* env_table took ownership, do not free separately */ key = NULL; value = NULL; } else { /* we still own key and value, the cleanup code will free them */ goto out; } _dbus_hash_table_remove_string (env_table, "DBUS_STARTER_ADDRESS"); _dbus_hash_table_remove_string (env_table, "DBUS_STARTER_BUS_TYPE"); _dbus_hash_table_remove_string (env_table, "DBUS_SESSION_BUS_PID"); _dbus_hash_table_remove_string (env_table, "DBUS_SESSION_BUS_WINDOWID"); dbus_free_string_array (env); env = _dbus_hash_table_to_array (env_table, '='); if (!env) goto out; app_handle = _dbus_spawn_program (argv[prog_arg], argv + prog_arg, env); if (!app_handle) { _dbus_win_stderr_win_error (me, "unable to start child process", GetLastError ()); goto out; } WaitForSingleObject (app_handle, INFINITE); if (!GetExitCodeProcess (app_handle, &exit_code)) { _dbus_win_stderr_win_error (me, "could not fetch exit code", GetLastError ()); goto out; } ret = exit_code; out: TerminateProcess (server_handle, 0); if (server_handle != NULL) CloseHandle (server_handle); if (app_handle != NULL) CloseHandle (app_handle); _dbus_string_free (&argv_strings[0]); _dbus_string_free (&argv_strings[1]); _dbus_string_free (&argv_strings[2]); _dbus_string_free (&address); dbus_free_string_array (env); if (env_table != NULL) _dbus_hash_table_unref (env_table); dbus_free (key); dbus_free (value); return ret; }