diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-06-02 04:08:39 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-07-09 19:47:23 +0200 |
commit | b3ed8675a4eba35c6a7f43a86a89f706ffe07f84 (patch) | |
tree | 9bc3db75ced3dd8d5da9eb5266a714f81add3986 | |
parent | 921bc585ca44b02684d368058a8df8300342dcd0 (diff) |
activation: optionally, use systemd for system bus activation
-rw-r--r-- | bus/activation.c | 549 | ||||
-rw-r--r-- | bus/activation.h | 7 | ||||
-rw-r--r-- | bus/bus.c | 13 | ||||
-rw-r--r-- | bus/bus.h | 2 | ||||
-rw-r--r-- | bus/desktop-file.h | 5 | ||||
-rw-r--r-- | bus/dispatch.c | 640 | ||||
-rw-r--r-- | bus/driver.c | 222 | ||||
-rw-r--r-- | bus/main.c | 7 | ||||
-rw-r--r-- | bus/test.c | 2 |
9 files changed, 825 insertions, 622 deletions
diff --git a/bus/activation.c b/bus/activation.c index 9d454c76..ee5efa8e 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -6,7 +6,7 @@ * Copyright (C) 2004 Imendio HB * * Licensed under the Academic Free License version 2.1 - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -16,7 +16,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -70,6 +70,7 @@ typedef struct char *name; char *exec; char *user; + char *systemd_service; unsigned long mtime; BusServiceDirectory *s_dir; char *filename; @@ -91,6 +92,7 @@ typedef struct BusActivation *activation; char *service_name; char *exec; + char *systemd_service; DBusList *entries; int n_entries; DBusBabysitter *babysitter; @@ -103,7 +105,7 @@ static BusServiceDirectory * bus_service_directory_ref (BusServiceDirectory *dir) { _dbus_assert (dir->refcount); - + dir->refcount++; return dir; @@ -113,8 +115,8 @@ bus_service_directory_ref (BusServiceDirectory *dir) static void bus_service_directory_unref (BusServiceDirectory *dir) { - if (dir == NULL) - return; + if (dir == NULL) + return; _dbus_assert (dir->refcount > 0); dir->refcount--; @@ -134,10 +136,10 @@ bus_pending_activation_entry_free (BusPendingActivationEntry *entry) { if (entry->activation_message) dbus_message_unref (entry->activation_message); - + if (entry->connection) dbus_connection_unref (entry->connection); - + dbus_free (entry); } @@ -151,7 +153,7 @@ handle_timeout_callback (DBusTimeout *timeout, _dbus_wait_for_memory (); } -static BusPendingActivation * +static BusPendingActivation * bus_pending_activation_ref (BusPendingActivation *pending_activation) { _dbus_assert (pending_activation->refcount > 0); @@ -164,7 +166,7 @@ static void bus_pending_activation_unref (BusPendingActivation *pending_activation) { DBusList *link; - + if (pending_activation == NULL) /* hash table requires this */ return; @@ -173,7 +175,7 @@ bus_pending_activation_unref (BusPendingActivation *pending_activation) if (pending_activation->refcount > 0) return; - + if (pending_activation->timeout_added) { _dbus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context), @@ -184,7 +186,7 @@ bus_pending_activation_unref (BusPendingActivation *pending_activation) if (pending_activation->timeout) _dbus_timeout_unref (pending_activation->timeout); - + if (pending_activation->babysitter) { if (!_dbus_babysitter_set_watch_functions (pending_activation->babysitter, @@ -192,12 +194,13 @@ bus_pending_activation_unref (BusPendingActivation *pending_activation) pending_activation->babysitter, NULL)) _dbus_assert_not_reached ("setting watch functions to NULL failed"); - + _dbus_babysitter_unref (pending_activation->babysitter); } - + dbus_free (pending_activation->service_name); dbus_free (pending_activation->exec); + dbus_free (pending_activation->systemd_service); link = _dbus_list_get_first_link (&pending_activation->entries); @@ -215,7 +218,7 @@ bus_pending_activation_unref (BusPendingActivation *pending_activation) pending_activation->n_entries; _dbus_assert (pending_activation->activation->n_pending_activations >= 0); - + dbus_free (pending_activation); } @@ -233,17 +236,18 @@ bus_activation_entry_unref (BusActivationEntry *entry) { if (entry == NULL) /* hash table requires this */ return; - + _dbus_assert (entry->refcount > 0); entry->refcount--; - - if (entry->refcount > 0) + + if (entry->refcount > 0) return; - + dbus_free (entry->name); dbus_free (entry->exec); dbus_free (entry->user); dbus_free (entry->filename); + dbus_free (entry->systemd_service); dbus_free (entry); } @@ -255,20 +259,21 @@ update_desktop_file_entry (BusActivation *activation, BusDesktopFile *desktop_file, DBusError *error) { - char *name, *exec, *user, *exec_tmp; + char *name, *exec, *user, *exec_tmp, *systemd_service; BusActivationEntry *entry; DBusStat stat_buf; DBusString file_path; DBusError tmp_error; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + name = NULL; exec = NULL; user = NULL; exec_tmp = NULL; entry = NULL; - + systemd_service = NULL; + dbus_error_init (&tmp_error); if (!_dbus_string_init (&file_path)) @@ -276,21 +281,21 @@ update_desktop_file_entry (BusActivation *activation, BUS_SET_OOM (error); return FALSE; } - + if (!_dbus_string_append (&file_path, s_dir->dir_c) || !_dbus_concat_dir_and_file (&file_path, filename)) { BUS_SET_OOM (error); goto failed; } - - if (!_dbus_stat (&file_path, &stat_buf, NULL)) + + if (!_dbus_stat (&file_path, &stat_buf, NULL)) { dbus_set_error (error, DBUS_ERROR_FAILED, "Can't stat the service file\n"); goto failed; } - + if (!bus_desktop_file_get_string (desktop_file, DBUS_SERVICE_SECTION, DBUS_SERVICE_NAME, @@ -328,13 +333,37 @@ update_desktop_file_entry (BusActivation *activation, } _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error); - entry = _dbus_hash_table_lookup_string (s_dir->entries, + /* systemd service is never required */ + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_SYSTEMD_SERVICE, + &systemd_service, &tmp_error)) + { + _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); + /* if we got OOM, then exit */ + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + goto failed; + } + else + { + /* if we have error because we didn't find anything then continue */ + dbus_error_free (&tmp_error); + dbus_free (systemd_service); + systemd_service = NULL; + } + } + + _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error); + + entry = _dbus_hash_table_lookup_string (s_dir->entries, _dbus_string_get_const_data (filename)); exec = strdup (_dbus_replace_install_prefix (exec_tmp)); if (entry == NULL) /* New file */ - { + { /* FIXME we need a better-defined algorithm for which service file to * pick than "whichever one is first in the directory listing" */ @@ -344,19 +373,20 @@ update_desktop_file_entry (BusActivation *activation, "Service %s already exists in activation entry list\n", name); goto failed; } - + entry = dbus_new0 (BusActivationEntry, 1); if (entry == NULL) { BUS_SET_OOM (error); goto failed; } - + entry->name = name; entry->exec = exec; entry->user = user; + entry->systemd_service = systemd_service; entry->refcount = 1; - + entry->s_dir = s_dir; entry->filename = _dbus_strdup (_dbus_string_get_const_data (filename)); if (!entry->filename) @@ -370,7 +400,7 @@ update_desktop_file_entry (BusActivation *activation, BUS_SET_OOM (error); goto failed; } - + if (!_dbus_hash_table_insert_string (s_dir->entries, entry->filename, bus_activation_entry_ref (entry))) { /* Revert the insertion in the entries table */ @@ -392,10 +422,12 @@ update_desktop_file_entry (BusActivation *activation, name, _dbus_string_get_const_data (&file_path)); goto failed; } - + dbus_free (entry->name); dbus_free (entry->exec); dbus_free (entry->user); + dbus_free (entry->systemd_service); + entry->systemd_service = systemd_service; entry->name = name; entry->exec = exec; entry->user = user; @@ -405,15 +437,15 @@ update_desktop_file_entry (BusActivation *activation, BUS_SET_OOM (error); /* Also remove path to entries hash since we want this in sync with * the entries hash table */ - _dbus_hash_table_remove_string (entry->s_dir->entries, + _dbus_hash_table_remove_string (entry->s_dir->entries, entry->filename); bus_activation_entry_unref (entry); return FALSE; } } - + entry->mtime = stat_buf.mtime; - + _dbus_string_free (&file_path); bus_activation_entry_unref (entry); @@ -423,11 +455,12 @@ failed: dbus_free (name); dbus_free (exec_tmp); dbus_free (user); + dbus_free (systemd_service); _dbus_string_free (&file_path); if (entry) bus_activation_entry_unref (entry); - + return FALSE; } @@ -445,15 +478,15 @@ check_service_file (BusActivation *activation, retval = TRUE; tmp_entry = entry; - + _dbus_string_init_const (&filename, entry->filename); - + if (!_dbus_string_init (&file_path)) { BUS_SET_OOM (error); return FALSE; } - + if (!_dbus_string_append (&file_path, entry->s_dir->dir_c) || !_dbus_concat_dir_and_file (&file_path, &filename)) { @@ -461,7 +494,7 @@ check_service_file (BusActivation *activation, retval = FALSE; goto out; } - + if (!_dbus_stat (&file_path, &stat_buf, NULL)) { _dbus_verbose ("****** Can't stat file \"%s\", removing from cache\n", @@ -474,20 +507,20 @@ check_service_file (BusActivation *activation, retval = TRUE; goto out; } - else + else { - if (stat_buf.mtime > entry->mtime) + if (stat_buf.mtime > entry->mtime) { BusDesktopFile *desktop_file; DBusError tmp_error; - + dbus_error_init (&tmp_error); - + desktop_file = bus_desktop_file_load (&file_path, &tmp_error); if (desktop_file == NULL) { _dbus_verbose ("Could not load %s: %s\n", - _dbus_string_get_const_data (&file_path), + _dbus_string_get_const_data (&file_path), tmp_error.message); if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) { @@ -499,10 +532,10 @@ check_service_file (BusActivation *activation, retval = TRUE; goto out; } - - /* @todo We can return OOM or a DBUS_ERROR_FAILED error + + /* @todo We can return OOM or a DBUS_ERROR_FAILED error * Handle these both better - */ + */ if (!update_desktop_file_entry (activation, entry->s_dir, &filename, desktop_file, &tmp_error)) { bus_desktop_file_free (desktop_file); @@ -516,12 +549,12 @@ check_service_file (BusActivation *activation, retval = TRUE; goto out; } - + bus_desktop_file_free (desktop_file); retval = TRUE; } } - + out: _dbus_string_free (&file_path); @@ -546,14 +579,14 @@ update_directory (BusActivation *activation, dbus_bool_t retval; BusActivationEntry *entry; DBusString full_path; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + iter = NULL; desktop_file = NULL; - + _dbus_string_init_const (&dir, s_dir->dir_c); - + if (!_dbus_string_init (&filename)) { BUS_SET_OOM (error); @@ -570,24 +603,24 @@ update_directory (BusActivation *activation, retval = FALSE; /* from this point it's safe to "goto out" */ - + iter = _dbus_directory_open (&dir, error); if (iter == NULL) { _dbus_verbose ("Failed to open directory %s: %s\n", - s_dir->dir_c, + s_dir->dir_c, error ? error->message : "unknown"); goto out; } - + /* Now read the files */ dbus_error_init (&tmp_error); while (_dbus_directory_get_next_file (iter, &filename, &tmp_error)) { _dbus_assert (!dbus_error_is_set (&tmp_error)); - + _dbus_string_set_length (&full_path, 0); - + if (!_dbus_string_ends_with_c_str (&filename, ".service")) { _dbus_verbose ("Skipping non-.service file %s\n", @@ -596,21 +629,21 @@ update_directory (BusActivation *activation, } entry = _dbus_hash_table_lookup_string (s_dir->entries, _dbus_string_get_const_data (&filename)); - if (entry) /* Already has this service file in the cache */ + if (entry) /* Already has this service file in the cache */ { if (!check_service_file (activation, entry, NULL, error)) goto out; continue; } - + if (!_dbus_string_append (&full_path, s_dir->dir_c) || !_dbus_concat_dir_and_file (&full_path, &filename)) { BUS_SET_OOM (error); goto out; } - + /* New file */ desktop_file = bus_desktop_file_load (&full_path, &tmp_error); if (desktop_file == NULL) @@ -624,19 +657,19 @@ update_directory (BusActivation *activation, dbus_move_error (&tmp_error, error); goto out; } - + dbus_error_free (&tmp_error); continue; } - /* @todo We can return OOM or a DBUS_ERROR_FAILED error + /* @todo We can return OOM or a DBUS_ERROR_FAILED error * Handle these both better - */ + */ if (!update_desktop_file_entry (activation, s_dir, &filename, desktop_file, &tmp_error)) { bus_desktop_file_free (desktop_file); desktop_file = NULL; - + _dbus_verbose ("Could not add %s to activation entry list: %s\n", _dbus_string_get_const_data (&full_path), tmp_error.message); @@ -662,7 +695,7 @@ update_directory (BusActivation *activation, dbus_move_error (&tmp_error, error); goto out; } - + retval = TRUE; out: @@ -670,12 +703,12 @@ update_directory (BusActivation *activation, _DBUS_ASSERT_ERROR_IS_SET (error); else _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + if (iter != NULL) _dbus_directory_close (iter); _dbus_string_free (&filename); _dbus_string_free (&full_path); - + return retval; } @@ -878,7 +911,7 @@ bus_activation_new (BusContext *context, (DBusFreeFunction) dbus_free, (DBusFreeFunction) dbus_free); - if (activation->environment == NULL) + if (activation->environment == NULL) { BUS_SET_OOM (error); goto failed; @@ -891,9 +924,9 @@ bus_activation_new (BusContext *context, } return activation; - + failed: - bus_activation_unref (activation); + bus_activation_unref (activation); return NULL; } @@ -901,7 +934,7 @@ BusActivation * bus_activation_ref (BusActivation *activation) { _dbus_assert (activation->refcount > 0); - + activation->refcount += 1; return activation; @@ -916,13 +949,13 @@ bus_activation_unref (BusActivation *activation) if (activation->refcount > 0) return; - + dbus_free (activation->server_address); if (activation->entries) _dbus_hash_table_unref (activation->entries); if (activation->pending_activations) _dbus_hash_table_unref (activation->pending_activations); - if (activation->directories) + if (activation->directories) _dbus_hash_table_unref (activation->directories); if (activation->environment) _dbus_hash_table_unref (activation->environment); @@ -935,13 +968,13 @@ add_bus_environment (BusActivation *activation, DBusError *error) { const char *type; - + if (!bus_activation_set_environment_variable (activation, "DBUS_STARTER_ADDRESS", activation->server_address, error)) return FALSE; - + type = bus_context_get_type (activation->context); if (type != NULL) { @@ -988,13 +1021,13 @@ restore_pending (void *data) _dbus_verbose ("Restoring pending activation for service %s, has timeout = %d\n", d->pending_activation->service_name, d->pending_activation->timeout_added); - + _dbus_hash_table_insert_string_preallocated (d->pending_activation->activation->pending_activations, d->hash_entry, d->pending_activation->service_name, d->pending_activation); bus_pending_activation_ref (d->pending_activation); - + d->hash_entry = NULL; } @@ -1008,7 +1041,7 @@ free_pending_restore_data (void *data) d->hash_entry); bus_pending_activation_unref (d->pending_activation); - + dbus_free (d); } @@ -1021,12 +1054,12 @@ add_restore_pending_to_transaction (BusTransaction *transaction, d = dbus_new (RestorePendingData, 1); if (d == NULL) return FALSE; - + d->pending_activation = pending_activation; d->hash_entry = _dbus_hash_table_preallocate_entry (d->pending_activation->activation->pending_activations); - + bus_pending_activation_ref (d->pending_activation); - + if (d->hash_entry == NULL || !bus_transaction_add_cancel_hook (transaction, restore_pending, d, free_pending_restore_data)) @@ -1036,7 +1069,7 @@ add_restore_pending_to_transaction (BusTransaction *transaction, } _dbus_verbose ("Saved pending activation to be restored if the transaction fails\n"); - + return TRUE; } @@ -1051,7 +1084,7 @@ bus_activation_service_created (BusActivation *activation, DBusList *link; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + /* Check if it's a pending activation */ pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name); @@ -1063,14 +1096,14 @@ bus_activation_service_created (BusActivation *activation, { BusPendingActivationEntry *entry = link->data; DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link); - + if (dbus_connection_get_is_connected (entry->connection)) { /* Only send activation replies to regular activation requests. */ if (!entry->auto_activation) { dbus_uint32_t result; - + message = dbus_message_new_method_return (entry->activation_message); if (!message) { @@ -1079,7 +1112,7 @@ bus_activation_service_created (BusActivation *activation, } result = DBUS_START_REPLY_SUCCESS; - + if (!dbus_message_append_args (message, DBUS_TYPE_UINT32, &result, DBUS_TYPE_INVALID)) @@ -1088,18 +1121,18 @@ bus_activation_service_created (BusActivation *activation, BUS_SET_OOM (error); goto error; } - + if (!bus_transaction_send_from_driver (transaction, entry->connection, message)) { dbus_message_unref (message); BUS_SET_OOM (error); goto error; } - + dbus_message_unref (message); } } - + link = next; } @@ -1119,7 +1152,7 @@ bus_activation_send_pending_auto_activation_messages (BusActivation *activation DBusList *link; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + /* Check if it's a pending activation */ pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, bus_service_get_name (service)); @@ -1136,7 +1169,7 @@ bus_activation_send_pending_auto_activation_messages (BusActivation *activation if (entry->auto_activation && dbus_connection_get_is_connected (entry->connection)) { DBusConnection *addressed_recipient; - + addressed_recipient = bus_service_get_primary_owners_connection (service); /* Resume dispatching where we left off in bus_dispatch() */ @@ -1156,7 +1189,7 @@ bus_activation_send_pending_auto_activation_messages (BusActivation *activation BUS_SET_OOM (error); goto error; } - + _dbus_hash_table_remove_string (activation->pending_activations, bus_service_get_name (service)); return TRUE; @@ -1178,19 +1211,19 @@ try_send_activation_failure (BusPendingActivation *pending_activation, BusActivation *activation; DBusList *link; BusTransaction *transaction; - + activation = pending_activation->activation; transaction = bus_transaction_new (activation->context); if (transaction == NULL) return FALSE; - + link = _dbus_list_get_first_link (&pending_activation->entries); while (link != NULL) { BusPendingActivationEntry *entry = link->data; DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link); - + if (dbus_connection_get_is_connected (entry->connection)) { if (!bus_transaction_send_error_reply (transaction, @@ -1199,12 +1232,12 @@ try_send_activation_failure (BusPendingActivation *pending_activation, entry->activation_message)) goto error; } - + link = next; } bus_transaction_execute_and_free (transaction); - + return TRUE; error: @@ -1391,7 +1424,7 @@ remove_babysitter_watch (DBusWatch *watch, void *data) { BusPendingActivation *pending_activation = data; - + _dbus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context), watch, babysitter_watch_callback, pending_activation); } @@ -1401,12 +1434,12 @@ pending_activation_timed_out (void *data) { BusPendingActivation *pending_activation = data; DBusError error; - + /* Kill the spawned process, since it sucks * (not sure this is what we want to do, but * may as well try it for now) */ - if (pending_activation->babysitter) + if (pending_activation->babysitter) _dbus_babysitter_kill_child (pending_activation->babysitter); dbus_error_init (&error); @@ -1432,7 +1465,7 @@ cancel_pending (void *data) if (pending_activation->babysitter) _dbus_babysitter_kill_child (pending_activation->babysitter); - + _dbus_hash_table_remove_string (pending_activation->activation->pending_activations, pending_activation->service_name); } @@ -1441,31 +1474,31 @@ static void free_pending_cancel_data (void *data) { BusPendingActivation *pending_activation = data; - + bus_pending_activation_unref (pending_activation); } static dbus_bool_t add_cancel_pending_to_transaction (BusTransaction *transaction, BusPendingActivation *pending_activation) -{ +{ if (!bus_transaction_add_cancel_hook (transaction, cancel_pending, pending_activation, free_pending_cancel_data)) return FALSE; - bus_pending_activation_ref (pending_activation); - + bus_pending_activation_ref (pending_activation); + _dbus_verbose ("Saved pending activation to be canceled if the transaction fails\n"); - + return TRUE; } -static dbus_bool_t +static dbus_bool_t update_service_cache (BusActivation *activation, DBusError *error) { DBusHashIter iter; - + _dbus_hash_iter_init (activation->directories, &iter); while (_dbus_hash_iter_next (&iter)) { @@ -1487,37 +1520,37 @@ update_service_cache (BusActivation *activation, DBusError *error) continue; } } - + return TRUE; } static BusActivationEntry * -activation_find_entry (BusActivation *activation, +activation_find_entry (BusActivation *activation, const char *service_name, DBusError *error) { BusActivationEntry *entry; - + entry = _dbus_hash_table_lookup_string (activation->entries, service_name); if (!entry) - { - if (!update_service_cache (activation, error)) + { + if (!update_service_cache (activation, error)) return NULL; entry = _dbus_hash_table_lookup_string (activation->entries, service_name); } - else + else { BusActivationEntry *updated_entry; - if (!check_service_file (activation, entry, &updated_entry, error)) + if (!check_service_file (activation, entry, &updated_entry, error)) return NULL; entry = updated_entry; } - if (!entry) + if (!entry) { dbus_set_error (error, DBUS_ERROR_SERVICE_UNKNOWN, "The name %s was not provided by any .service files", @@ -1639,7 +1672,7 @@ bus_activation_activate_service (BusActivation *activation, DBusHashIter iter; dbus_bool_t activated; DBusString command; - + activated = TRUE; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -1654,7 +1687,7 @@ bus_activation_activate_service (BusActivation *activation, } entry = activation_find_entry (activation, service_name, error); - if (!entry) + if (!entry) return FALSE; /* Bypass the registry lookup if we're auto-activating, bus_dispatch would not @@ -1667,9 +1700,9 @@ bus_activation_activate_service (BusActivation *activation, if (bus_registry_lookup (bus_context_get_registry (activation->context), &service_str) != NULL) { dbus_uint32_t result; - + _dbus_verbose ("Service \"%s\" is already active\n", service_name); - + message = dbus_message_new_method_return (activation_message); if (!message) @@ -1680,7 +1713,7 @@ bus_activation_activate_service (BusActivation *activation, } result = DBUS_START_REPLY_ALREADY_RUNNING; - + if (!dbus_message_append_args (message, DBUS_TYPE_UINT32, &result, DBUS_TYPE_INVALID)) @@ -1702,7 +1735,7 @@ bus_activation_activate_service (BusActivation *activation, return retval; } } - + pending_activation_entry = dbus_new0 (BusPendingActivationEntry, 1); if (!pending_activation_entry) { @@ -1717,7 +1750,7 @@ bus_activation_activate_service (BusActivation *activation, dbus_message_ref (activation_message); pending_activation_entry->connection = connection; dbus_connection_ref (connection); - + /* Check if the service is being activated */ pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name); if (pending_activation) @@ -1725,7 +1758,7 @@ bus_activation_activate_service (BusActivation *activation, if (!_dbus_list_append (&pending_activation->entries, pending_activation_entry)) { _dbus_verbose ("Failed to append a new entry to pending activation\n"); - + BUS_SET_OOM (error); bus_pending_activation_entry_free (pending_activation_entry); return FALSE; @@ -1740,23 +1773,23 @@ bus_activation_activate_service (BusActivation *activation, if (!pending_activation) { _dbus_verbose ("Failed to create pending activation\n"); - + BUS_SET_OOM (error); - bus_pending_activation_entry_free (pending_activation_entry); + bus_pending_activation_entry_free (pending_activation_entry); return FALSE; } pending_activation->activation = activation; pending_activation->refcount = 1; - + pending_activation->service_name = _dbus_strdup (service_name); if (!pending_activation->service_name) { _dbus_verbose ("Failed to copy service name for pending activation\n"); - + BUS_SET_OOM (error); bus_pending_activation_unref (pending_activation); - bus_pending_activation_entry_free (pending_activation_entry); + bus_pending_activation_entry_free (pending_activation_entry); return FALSE; } @@ -1770,6 +1803,19 @@ bus_activation_activate_service (BusActivation *activation, return FALSE; } + if (entry->systemd_service) + { + pending_activation->systemd_service = _dbus_strdup (entry->systemd_service); + if (!pending_activation->systemd_service) + { + _dbus_verbose ("Failed to copy systemd service for pending activation\n"); + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + } + pending_activation->timeout = _dbus_timeout_new (bus_context_get_activation_timeout (activation->context), pending_activation_timed_out, @@ -1778,7 +1824,7 @@ bus_activation_activate_service (BusActivation *activation, if (!pending_activation->timeout) { _dbus_verbose ("Failed to create timeout for pending activation\n"); - + BUS_SET_OOM (error); bus_pending_activation_unref (pending_activation); bus_pending_activation_entry_free (pending_activation_entry); @@ -1792,53 +1838,53 @@ bus_activation_activate_service (BusActivation *activation, NULL)) { _dbus_verbose ("Failed to add timeout for pending activation\n"); - + BUS_SET_OOM (error); bus_pending_activation_unref (pending_activation); - bus_pending_activation_entry_free (pending_activation_entry); + bus_pending_activation_entry_free (pending_activation_entry); return FALSE; } pending_activation->timeout_added = TRUE; - + if (!_dbus_list_append (&pending_activation->entries, pending_activation_entry)) { _dbus_verbose ("Failed to add entry to just-created pending activation\n"); - + BUS_SET_OOM (error); bus_pending_activation_unref (pending_activation); - bus_pending_activation_entry_free (pending_activation_entry); + bus_pending_activation_entry_free (pending_activation_entry); return FALSE; } pending_activation->n_entries += 1; pending_activation->activation->n_pending_activations += 1; - + activated = FALSE; _dbus_hash_iter_init (activation->pending_activations, &iter); while (_dbus_hash_iter_next (&iter)) { BusPendingActivation *p = _dbus_hash_iter_get_value (&iter); - - if (strcmp (p->exec, entry->exec) == 0) + + if (strcmp (p->exec, entry->exec) == 0) { activated = TRUE; break; } } - + if (!_dbus_hash_table_insert_string (activation->pending_activations, pending_activation->service_name, pending_activation)) { _dbus_verbose ("Failed to put pending activation in hash table\n"); - + BUS_SET_OOM (error); bus_pending_activation_unref (pending_activation); return FALSE; } } - + if (!add_cancel_pending_to_transaction (transaction, pending_activation)) { _dbus_verbose ("Failed to add pending activation cancel hook to transaction\n"); @@ -1848,10 +1894,99 @@ bus_activation_activate_service (BusActivation *activation, return FALSE; } - + if (activated) return TRUE; + if (bus_context_get_systemd_activation (activation->context)) + { + if (strcmp (service_name, "org.freedesktop.systemd1") == 0) + /* systemd itself is missing apparently. That can happen + only during early startup. Let's just wait until systemd + connects to us and do nothing. */ + return TRUE; + + if (entry->systemd_service) + { + BusTransaction *activation_transaction; + DBusString service_string; + BusService *service; + BusRegistry *registry; + + /* OK, we have a systemd service configured for this entry, + hence let's enqueue an activation request message. This + is implemented as a directed signal, not a method call, + for three reasons: 1) we don't expect a response on + success, where we just expect a name appearing on the + bus; 2) at this time the systemd service might not yet + have connected, so we wouldn't know the message serial at + this point to set up a pending call; 3) it is ugly if the + bus suddenly becomes the caller of a remote method. */ + + message = dbus_message_new_signal (DBUS_PATH_DBUS, + "org.freedesktop.systemd1.Activator", + "ActivationRequest"); + if (!message) + { + _dbus_verbose ("No memory to create activation message\n"); + BUS_SET_OOM (error); + return FALSE; + } + + if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) || + !dbus_message_set_destination (message, "org.freedesktop.systemd1") || + !dbus_message_append_args (message, + DBUS_TYPE_STRING, &entry->systemd_service, + DBUS_TYPE_INVALID)) + { + _dbus_verbose ("No memory to set args of activation message\n"); + dbus_message_unref (message); + BUS_SET_OOM (error); + return FALSE; + } + + /* Create our transaction */ + activation_transaction = bus_transaction_new (activation->context); + if (activation_transaction == NULL) + { + _dbus_verbose ("No memory to create activation transaction\n"); + dbus_message_unref (message); + BUS_SET_OOM (error); + return FALSE; + } + + /* Check whether systemd is already connected */ + registry = bus_connection_get_registry (connection); + _dbus_string_init_const (&service_string, "org.freedesktop.systemd1"); + service = bus_registry_lookup (registry, &service_string); + + if (service != NULL) + /* Wonderful, systemd is connected, let's just send the msg */ + retval = bus_dispatch_matches (activation_transaction, NULL, bus_service_get_primary_owners_connection (service), + message, error); + else + /* systemd is not around, let's "activate" it. */ + retval = bus_activation_activate_service (activation, connection, activation_transaction, TRUE, + message, "org.freedesktop.systemd1", error); + + dbus_message_unref (message); + + if (!retval) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("failed to send activation message: %s\n", error->name); + bus_transaction_cancel_and_free (activation_transaction); + return FALSE; + } + + bus_transaction_execute_and_free (activation_transaction); + return TRUE; + } + + /* OK, we have no configured systemd service, hence let's + proceed with traditional activation. */ + } + /* use command as system and session different */ if (!_dbus_string_init (&command)) { @@ -1907,7 +2042,7 @@ bus_activation_activate_service (BusActivation *activation, { _dbus_verbose ("Failed to parse command line: %s\n", entry->exec); _DBUS_ASSERT_ERROR_IS_SET (error); - + _dbus_hash_table_remove_string (activation->pending_activations, pending_activation->service_name); @@ -1935,7 +2070,7 @@ bus_activation_activate_service (BusActivation *activation, _dbus_verbose ("Spawning %s ...\n", argv[0]); if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter, argv, envp, - NULL, activation, + NULL, activation, error)) { _dbus_verbose ("Failed to spawn child\n"); @@ -1950,7 +2085,7 @@ bus_activation_activate_service (BusActivation *activation, envp = NULL; _dbus_assert (pending_activation->babysitter != NULL); - + if (!_dbus_babysitter_set_watch_functions (pending_activation->babysitter, add_babysitter_watch, remove_babysitter_watch, @@ -1962,7 +2097,7 @@ bus_activation_activate_service (BusActivation *activation, _dbus_verbose ("Failed to set babysitter watch functions\n"); return FALSE; } - + return TRUE; } @@ -2009,7 +2144,47 @@ bus_activation_list_services (BusActivation *activation, return FALSE; } - + +dbus_bool_t +dbus_activation_systemd_failure (BusActivation *activation, + DBusMessage *message) +{ + DBusError error; + const char *code, *str, *unit = NULL; + + dbus_error_init(&error); + + /* This is called whenever the systemd activator sent us a + response. We'll invalidate all pending activations that match the + unit name. */ + + if (dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &unit, + DBUS_TYPE_STRING, &code, + DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID)) + dbus_set_error(&error, code, str); + + if (unit) + { + DBusHashIter iter; + + _dbus_hash_iter_init (activation->pending_activations, + &iter); + + while (_dbus_hash_iter_next (&iter)) + { + BusPendingActivation *p = _dbus_hash_iter_get_value (&iter); + + if (p->systemd_service && strcmp (p->systemd_service, unit) == 0) + pending_activation_failed(p, &error); + } + } + + dbus_error_free(&error); + + return TRUE; +} #ifdef DBUS_BUILD_TESTS @@ -2025,8 +2200,8 @@ bus_activation_list_services (BusActivation *activation, static dbus_bool_t test_create_service_file (DBusString *dir, - const char *filename, - const char *name, + const char *filename, + const char *name, const char *exec) { DBusString file_name, full_path; @@ -2045,7 +2220,7 @@ test_create_service_file (DBusString *dir, ret_val = FALSE; goto out; } - + file = fopen (_dbus_string_get_const_data (&full_path), "w"); if (!file) { @@ -2066,9 +2241,9 @@ test_remove_service_file (DBusString *dir, const char *filename) { DBusString file_name, full_path; dbus_bool_t ret_val; - + ret_val = TRUE; - + _dbus_string_init_const (&file_name, filename); if (!_dbus_string_init (&full_path)) @@ -2098,9 +2273,9 @@ test_remove_directory (DBusString *dir) DBusDirIter *iter; DBusString filename, full_path; dbus_bool_t ret_val; - + ret_val = TRUE; - + if (!_dbus_string_init (&filename)) return FALSE; @@ -2109,15 +2284,15 @@ test_remove_directory (DBusString *dir) _dbus_string_free (&filename); return FALSE; } - + iter = _dbus_directory_open (dir, NULL); if (iter == NULL) { ret_val = FALSE; goto out; } - - while (_dbus_directory_get_next_file (iter, &filename, NULL)) + + while (_dbus_directory_get_next_file (iter, &filename, NULL)) { if (!test_remove_service_file (dir, _dbus_string_get_const_data (&filename))) { @@ -2144,13 +2319,13 @@ static dbus_bool_t init_service_reload_test (DBusString *dir) { DBusStat stat_buf; - + if (!_dbus_stat (dir, &stat_buf, NULL)) { if (!_dbus_create_directory (dir, NULL)) return FALSE; } - else + else { if (!test_remove_directory (dir)) return FALSE; @@ -2175,7 +2350,7 @@ cleanup_service_reload_test (DBusString *dir) return TRUE; } -typedef struct +typedef struct { BusActivation *activation; const char *service_name; @@ -2189,16 +2364,16 @@ check_func (void *data) BusActivationEntry *entry; DBusError error; dbus_bool_t ret_val; - + ret_val = TRUE; d = data; - + dbus_error_init (&error); - + entry = activation_find_entry (d->activation, d->service_name, &error); if (entry == NULL) { - if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { ret_val = TRUE; } @@ -2207,10 +2382,10 @@ check_func (void *data) if (d->expecting_find) ret_val = FALSE; } - + dbus_error_free (&error); } - else + else { if (!d->expecting_find) ret_val = FALSE; @@ -2229,7 +2404,7 @@ do_test (const char *description, dbus_bool_t oom_test, CheckData *data) else err = !check_func (data); - if (err) + if (err) _dbus_assert_not_reached ("Test failed"); return TRUE; @@ -2242,19 +2417,19 @@ do_service_reload_test (DBusString *dir, dbus_bool_t oom_test) DBusString address; DBusList *directories; CheckData d; - + directories = NULL; _dbus_string_init_const (&address, ""); - + if (!_dbus_list_append (&directories, _dbus_string_get_data (dir))) - return FALSE; + return FALSE; activation = bus_activation_new (NULL, &address, &directories, NULL); if (!activation) return FALSE; d.activation = activation; - + /* Check for existing service file */ d.expecting_find = TRUE; d.service_name = SERVICE_NAME_1; @@ -2275,10 +2450,10 @@ do_service_reload_test (DBusString *dir, dbus_bool_t oom_test) d.expecting_find = TRUE; d.service_name = SERVICE_NAME_2; - + if (!do_test ("Added service file", oom_test, &d)) return FALSE; - + /* Check for removed service file */ if (!test_remove_service_file (dir, SERVICE_FILE_2)) return FALSE; @@ -2288,9 +2463,9 @@ do_service_reload_test (DBusString *dir, dbus_bool_t oom_test) if (!do_test ("Removed service file", oom_test, &d)) return FALSE; - + /* Check for updated service file */ - + _dbus_sleep_milliseconds (1000); /* Sleep a second to make sure the mtime is updated */ if (!test_create_service_file (dir, SERVICE_FILE_1, SERVICE_NAME_3, "exec-3")) @@ -2306,7 +2481,7 @@ do_service_reload_test (DBusString *dir, dbus_bool_t oom_test) d.service_name = SERVICE_NAME_1; if (!do_test ("Updated service file, part 2", oom_test, &d)) - return FALSE; + return FALSE; bus_activation_unref (activation); _dbus_list_clear (&directories); @@ -2321,36 +2496,36 @@ bus_activation_service_reload_test (const DBusString *test_data_dir) if (!_dbus_string_init (&directory)) return FALSE; - + if (!_dbus_string_append (&directory, _dbus_get_tmpdir())) return FALSE; - + if (!_dbus_string_append (&directory, "/dbus-reload-test-") || !_dbus_generate_random_ascii (&directory, 6)) { return FALSE; } - + /* Do normal tests */ if (!init_service_reload_test (&directory)) _dbus_assert_not_reached ("could not initiate service reload test"); - + if (!do_service_reload_test (&directory, FALSE)) ; /* Do nothing? */ - + /* Do OOM tests */ if (!init_service_reload_test (&directory)) _dbus_assert_not_reached ("could not initiate service reload test"); - + if (!do_service_reload_test (&directory, TRUE)) ; /* Do nothing? */ - + /* Cleanup test directory */ if (!cleanup_service_reload_test (&directory)) return FALSE; - + _dbus_string_free (&directory); - + return TRUE; } diff --git a/bus/activation.h b/bus/activation.h index 03bfed28..97f25b1f 100644 --- a/bus/activation.h +++ b/bus/activation.h @@ -4,7 +4,7 @@ * Copyright (C) 2003 CodeFactory AB * * Licensed under the Academic Free License version 2.1 - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -14,7 +14,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -57,6 +57,8 @@ dbus_bool_t bus_activation_service_created (BusActivation *activation, dbus_bool_t bus_activation_list_services (BusActivation *registry, char ***listp, int *array_len); +dbus_bool_t dbus_activation_systemd_failure (BusActivation *activation, + DBusMessage *message); dbus_bool_t bus_activation_send_pending_auto_activation_messages (BusActivation *activation, BusService *service, @@ -64,5 +66,4 @@ dbus_bool_t bus_activation_send_pending_auto_activation_messages (BusActivati DBusError *error); - #endif /* BUS_ACTIVATION_H */ @@ -60,6 +60,7 @@ struct BusContext unsigned int syslog : 1; unsigned int keep_umask : 1; unsigned int allow_anonymous : 1; + unsigned int systemd_activation : 1; }; static dbus_int32_t server_data_slot = -1; @@ -276,6 +277,7 @@ static dbus_bool_t process_config_first_time_only (BusContext *context, BusConfigParser *parser, const DBusString *address, + dbus_bool_t systemd_activation, DBusError *error) { DBusString log_prefix; @@ -292,6 +294,8 @@ process_config_first_time_only (BusContext *context, retval = FALSE; auth_mechanisms = NULL; + context->systemd_activation = systemd_activation; + /* Check for an existing pid file. Of course this is a race; * we'd have to use fcntl() locks on the pid file to * avoid that. But we want to check for the pid file @@ -652,6 +656,7 @@ bus_context_new (const DBusString *config_file, DBusPipe *print_addr_pipe, DBusPipe *print_pid_pipe, const DBusString *address, + dbus_bool_t systemd_activation, DBusError *error) { DBusString log_prefix; @@ -706,7 +711,7 @@ bus_context_new (const DBusString *config_file, goto failed; } - if (!process_config_first_time_only (context, parser, address, error)) + if (!process_config_first_time_only (context, parser, address, systemd_activation, error)) { _DBUS_ASSERT_ERROR_IS_SET (error); goto failed; @@ -1084,6 +1089,12 @@ bus_context_get_servicehelper (BusContext *context) return context->servicehelper; } +dbus_bool_t +bus_context_get_systemd_activation (BusContext *context) +{ + return context->systemd_activation; +} + BusRegistry* bus_context_get_registry (BusContext *context) { @@ -76,6 +76,7 @@ BusContext* bus_context_new (const DBusStri DBusPipe *print_addr_pipe, DBusPipe *print_pid_pipe, const DBusString *address, + dbus_bool_t systemd_activation, DBusError *error); dbus_bool_t bus_context_reload_config (BusContext *context, DBusError *error); @@ -87,6 +88,7 @@ dbus_bool_t bus_context_get_id (BusContext const char* bus_context_get_type (BusContext *context); const char* bus_context_get_address (BusContext *context); const char* bus_context_get_servicehelper (BusContext *context); +dbus_bool_t bus_context_get_systemd_activation (BusContext *context); BusRegistry* bus_context_get_registry (BusContext *context); BusConnections* bus_context_get_connections (BusContext *context); BusActivation* bus_context_get_activation (BusContext *context); diff --git a/bus/desktop-file.h b/bus/desktop-file.h index 7f43458a..58e78e8f 100644 --- a/bus/desktop-file.h +++ b/bus/desktop-file.h @@ -4,7 +4,7 @@ * Copyright (C) 2003 CodeFactory AB * * Licensed under the Academic Free License version 2.1 - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -14,7 +14,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -35,6 +35,7 @@ #define DBUS_SERVICE_EXEC "Exec" #define DBUS_SERVICE_USER "User" #define DBUS_SERVICE_GROUP "Group" +#define DBUS_SERVICE_SYSTEMD_SERVICE "SystemdService" typedef struct BusDesktopFile BusDesktopFile; diff --git a/bus/dispatch.c b/bus/dispatch.c index cd3f2a2a..a80476cd 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -6,7 +6,7 @@ * Copyright (C) 2004 Imendio HB * * Licensed under the Academic Free License version 2.1 - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -16,7 +16,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -73,7 +73,7 @@ send_one_message (DBusConnection *connection, if (dbus_message_contains_unix_fds(message) && !dbus_connection_can_send_type(connection, DBUS_TYPE_UNIX_FD)) return TRUE; /* silently don't send it */ - + if (!bus_transaction_send (transaction, connection, message)) @@ -167,7 +167,7 @@ bus_dispatch_matches (BusTransaction *transaction, } _dbus_list_clear (&recipients); - + if (dbus_error_is_set (&tmp_error)) { dbus_move_error (&tmp_error, error); @@ -187,25 +187,25 @@ bus_dispatch (DBusConnection *connection, BusContext *context; DBusHandlerResult result; DBusConnection *addressed_recipient; - + result = DBUS_HANDLER_RESULT_HANDLED; - + transaction = NULL; addressed_recipient = NULL; dbus_error_init (&error); - + context = bus_connection_get_context (connection); _dbus_assert (context != NULL); - + /* If we can't even allocate an OOM error, we just go to sleep * until we can. */ while (!bus_connection_preallocate_oom_error (connection)) _dbus_wait_for_memory (); - + /* Ref connection in case we disconnect it at some point in here */ dbus_connection_ref (connection); - + service_name = dbus_message_get_destination (message); #ifdef DBUS_ENABLE_VERBOSE_MODE @@ -215,7 +215,7 @@ bus_dispatch (DBusConnection *connection, interface_name = dbus_message_get_interface (message); member_name = dbus_message_get_member (message); error_name = dbus_message_get_error_name (message); - + _dbus_verbose ("DISPATCH: %s %s %s to %s\n", interface_name ? interface_name : "(no interface)", member_name ? member_name : "(no member)", @@ -223,7 +223,7 @@ bus_dispatch (DBusConnection *connection, service_name ? service_name : "peer"); } #endif /* DBUS_ENABLE_VERBOSE_MODE */ - + /* If service_name is NULL, if it's a signal we send it to all * connections with a match rule. If it's not a signal, there * are some special cases here but mostly we just bail out. @@ -247,7 +247,7 @@ bus_dispatch (DBusConnection *connection, goto out; } } - + /* Create our transaction */ transaction = bus_transaction_new (context); if (transaction == NULL) @@ -255,7 +255,7 @@ bus_dispatch (DBusConnection *connection, BUS_SET_OOM (&error); goto out; } - + /* Assign a sender to the message */ if (bus_connection_is_active (connection)) { @@ -275,7 +275,7 @@ bus_dispatch (DBusConnection *connection, */ service_name = dbus_message_get_destination (message); } - + if (service_name && strcmp (service_name, DBUS_SERVICE_DBUS) == 0) /* to bus driver */ { @@ -303,9 +303,9 @@ bus_dispatch (DBusConnection *connection, BusRegistry *registry; _dbus_assert (service_name != NULL); - + registry = bus_connection_get_registry (connection); - + _dbus_string_init_const (&service_string, service_name); service = bus_registry_lookup (registry, &service_string); @@ -325,7 +325,7 @@ bus_dispatch (DBusConnection *connection, _dbus_verbose ("bus_activation_activate_service() failed: %s\n", error.name); goto out; } - + goto out; } else if (service == NULL) @@ -349,7 +349,7 @@ bus_dispatch (DBusConnection *connection, */ if (!bus_dispatch_matches (transaction, connection, addressed_recipient, message, &error)) goto out; - + out: if (dbus_error_is_set (&error)) { @@ -381,7 +381,7 @@ bus_dispatch (DBusConnection *connection, &error, message)) { bus_connection_send_oom_error (connection, message); - + /* cancel transaction due to OOM */ if (transaction != NULL) { @@ -390,8 +390,8 @@ bus_dispatch (DBusConnection *connection, } } } - - + + dbus_error_free (&error); } @@ -415,12 +415,12 @@ bus_dispatch_message_filter (DBusConnection *connection, dbus_bool_t bus_dispatch_add_connection (DBusConnection *connection) -{ +{ if (!dbus_connection_add_filter (connection, bus_dispatch_message_filter, NULL, NULL)) return FALSE; - + return TRUE; } @@ -457,7 +457,7 @@ block_connection_until_message_from_bus (BusContext *context, const char *what_is_expected) { _dbus_verbose ("expecting: %s\n", what_is_expected); - + while (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_COMPLETE && dbus_connection_get_is_connected (connection)) @@ -566,13 +566,13 @@ check_service_owner_changed_foreach (DBusConnection *connection, DBusError error; const char *service_name, *old_owner, *new_owner; - if (d->expected_kind == SERVICE_CREATED + if (d->expected_kind == SERVICE_CREATED && connection == d->skip_connection) return TRUE; dbus_error_init (&error); d->failed = TRUE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -606,7 +606,7 @@ check_service_owner_changed_foreach (DBusConnection *connection, if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { dbus_error_free (&error); - _dbus_wait_for_memory (); + _dbus_wait_for_memory (); goto reget_service_info_data; } else @@ -632,7 +632,7 @@ check_service_owner_changed_foreach (DBusConnection *connection, goto out; } - if (*service_name == ':' && new_owner[0] + if (*service_name == ':' && new_owner[0] && strcmp (service_name, new_owner) != 0) { _dbus_warn ("inconsistent ServiceOwnedChanged message (\"%s\" [ %s -> %s ])\n", @@ -642,10 +642,10 @@ check_service_owner_changed_foreach (DBusConnection *connection, } d->failed = FALSE; - + out: dbus_error_free (&error); - + if (message) dbus_message_unref (message); @@ -662,7 +662,7 @@ kill_client_connection (BusContext *context, CheckServiceOwnerChangedData socd; _dbus_verbose ("killing connection %p\n", connection); - + s = dbus_bus_get_unique_name (connection); _dbus_assert (s != NULL); @@ -670,36 +670,36 @@ kill_client_connection (BusContext *context, _dbus_wait_for_memory (); dbus_connection_ref (connection); - + /* kick in the disconnect handler that unrefs the connection */ dbus_connection_close (connection); bus_test_run_everything (context); - + _dbus_assert (bus_test_client_listed (connection)); - + /* Run disconnect handler in test.c */ if (bus_connection_dispatch_one_message (connection)) _dbus_assert_not_reached ("something received on connection being killed other than the disconnect"); - + _dbus_assert (!dbus_connection_get_is_connected (connection)); dbus_connection_unref (connection); connection = NULL; _dbus_assert (!bus_test_client_listed (connection)); - + socd.expected_kind = SERVICE_DELETED; socd.expected_service_name = base_service; socd.failed = FALSE; socd.skip_connection = NULL; - + bus_test_clients_foreach (check_service_owner_changed_foreach, &socd); dbus_free (base_service); - + if (socd.failed) _dbus_assert_not_reached ("didn't get the expected NameOwnerChanged (deletion) messages"); - + if (!check_no_leftovers (context)) _dbus_assert_not_reached ("stuff left in message queues after disconnecting a client"); } @@ -709,7 +709,7 @@ kill_client_connection_unchecked (DBusConnection *connection) { /* This kills the connection without expecting it to affect * the rest of the bus. - */ + */ _dbus_verbose ("Unchecked kill of connection %p\n", connection); dbus_connection_ref (connection); @@ -755,7 +755,7 @@ check_no_leftovers (BusContext *context) nmd.failed = FALSE; bus_test_clients_foreach (check_no_messages_foreach, &nmd); - + if (nmd.failed) { _dbus_verbose ("leftover message found\n"); @@ -788,7 +788,7 @@ check_hello_message (BusContext *context, name_message = NULL; _dbus_verbose ("check_hello_message for %p\n", connection); - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -798,7 +798,7 @@ check_hello_message (BusContext *context, return TRUE; dbus_connection_ref (connection); /* because we may get disconnected */ - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -807,44 +807,44 @@ check_hello_message (BusContext *context, } _dbus_assert (dbus_message_has_signature (message, "")); - + dbus_message_unref (message); message = NULL; if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected (presumably auth failed)\n"); - + dbus_connection_unref (connection); - + return TRUE; } - + /* send our message */ bus_test_run_clients_loop (SEND_PENDING (connection)); if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected (presumably auth failed)\n"); - + dbus_connection_unref (connection); - + return TRUE; } - + block_connection_until_message_from_bus (context, connection, "reply to Hello"); if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected (presumably auth failed)\n"); - + dbus_connection_unref (connection); - + return TRUE; } dbus_connection_unref (connection); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -862,7 +862,7 @@ check_hello_message (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) { if (dbus_message_is_error (message, @@ -880,7 +880,7 @@ check_hello_message (BusContext *context, else { CheckServiceOwnerChangedData socd; - + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) { ; /* good, expected */ @@ -916,14 +916,14 @@ check_hello_message (BusContext *context, while (!dbus_bus_set_unique_name (connection, name)) _dbus_wait_for_memory (); - + socd.expected_kind = SERVICE_CREATED; socd.expected_service_name = name; socd.failed = FALSE; socd.skip_connection = connection; /* we haven't done AddMatch so won't get it ourselves */ bus_test_clients_foreach (check_service_owner_changed_foreach, &socd); - + if (socd.failed) goto out; @@ -944,7 +944,7 @@ check_hello_message (BusContext *context, "NameAcquired"); goto out; } - + retry_get_acquired_name: if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &acquired, @@ -978,20 +978,20 @@ check_hello_message (BusContext *context, if (!check_no_leftovers (context)) goto out; - + retval = TRUE; - + out: _dbus_verbose ("ending - retval = %d\n", retval); - + dbus_error_free (&error); - + if (message) dbus_message_unref (message); if (name_message) dbus_message_unref (name_message); - + return retval; } @@ -1012,7 +1012,7 @@ check_double_hello_message (BusContext *context, message = NULL; _dbus_verbose ("check_double_hello_message for %p\n", connection); - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -1020,7 +1020,7 @@ check_double_hello_message (BusContext *context, if (message == NULL) return TRUE; - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -1039,14 +1039,14 @@ check_double_hello_message (BusContext *context, if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected\n"); - + dbus_connection_unref (connection); - + return TRUE; } dbus_connection_unref (connection); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -1064,7 +1064,7 @@ check_double_hello_message (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR) { warn_unexpected (connection, message, "method return for Hello"); @@ -1073,15 +1073,15 @@ check_double_hello_message (BusContext *context, if (!check_no_leftovers (context)) goto out; - + retval = TRUE; - + out: dbus_error_free (&error); - + if (message) dbus_message_unref (message); - + return retval; } @@ -1104,7 +1104,7 @@ check_get_connection_unix_user (BusContext *context, message = NULL; _dbus_verbose ("check_get_connection_unix_user for %p\n", connection); - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -1115,7 +1115,7 @@ check_get_connection_unix_user (BusContext *context, base_service_name = dbus_bus_get_unique_name (connection); - if (!dbus_message_append_args (message, + if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &base_service_name, DBUS_TYPE_INVALID)) { @@ -1141,9 +1141,9 @@ check_get_connection_unix_user (BusContext *context, if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected\n"); - + dbus_connection_unref (connection); - + return TRUE; } @@ -1215,10 +1215,10 @@ check_get_connection_unix_user (BusContext *context, out: dbus_error_free (&error); - + if (message) dbus_message_unref (message); - + return retval; } @@ -1241,7 +1241,7 @@ check_get_connection_unix_process_id (BusContext *context, message = NULL; _dbus_verbose ("check_get_connection_unix_process_id for %p\n", connection); - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -1252,7 +1252,7 @@ check_get_connection_unix_process_id (BusContext *context, base_service_name = dbus_bus_get_unique_name (connection); - if (!dbus_message_append_args (message, + if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &base_service_name, DBUS_TYPE_INVALID)) { @@ -1278,9 +1278,9 @@ check_get_connection_unix_process_id (BusContext *context, if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected\n"); - + dbus_connection_unref (connection); - + return TRUE; } @@ -1310,11 +1310,11 @@ check_get_connection_unix_process_id (BusContext *context, */ _dbus_verbose ("Windows correctly does not support GetConnectionUnixProcessID\n"); } -#endif +#endif else { warn_unexpected (connection, message, "not this error"); - + goto out; } } @@ -1323,7 +1323,7 @@ check_get_connection_unix_process_id (BusContext *context, #ifdef DBUS_WIN warn_unexpected (connection, message, "GetConnectionUnixProcessID to fail on Windows"); goto out; -#else +#else if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) { ; /* good, expected */ @@ -1382,10 +1382,10 @@ check_get_connection_unix_process_id (BusContext *context, out: dbus_error_free (&error); - + if (message) dbus_message_unref (message); - + return retval; } @@ -1407,7 +1407,7 @@ check_add_match_all (BusContext *context, message = NULL; _dbus_verbose ("check_add_match_all for %p\n", connection); - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -1423,7 +1423,7 @@ check_add_match_all (BusContext *context, dbus_message_unref (message); return TRUE; } - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -1434,32 +1434,32 @@ check_add_match_all (BusContext *context, message = NULL; dbus_connection_ref (connection); /* because we may get disconnected */ - + /* send our message */ bus_test_run_clients_loop (SEND_PENDING (connection)); if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected\n"); - + dbus_connection_unref (connection); - + return TRUE; } - + block_connection_until_message_from_bus (context, connection, "reply to AddMatch"); if (!dbus_connection_get_is_connected (connection)) { _dbus_verbose ("connection was disconnected\n"); - + dbus_connection_unref (connection); - + return TRUE; } dbus_connection_unref (connection); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -1477,7 +1477,7 @@ check_add_match_all (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) { if (dbus_message_is_error (message, @@ -1509,15 +1509,15 @@ check_add_match_all (BusContext *context, if (!check_no_leftovers (context)) goto out; - + retval = TRUE; - + out: dbus_error_free (&error); - + if (message) dbus_message_unref (message); - + return retval; } @@ -1548,10 +1548,10 @@ check_hello_connection (BusContext *context) } spin_connection_until_authenticated (context, connection); - + if (!check_hello_message (context, connection)) return FALSE; - + if (dbus_bus_get_unique_name (connection) == NULL) { /* We didn't successfully register, so we can't @@ -1563,7 +1563,7 @@ check_hello_connection (BusContext *context) { if (!check_add_match_all (context, connection)) return FALSE; - + kill_client_connection (context, connection); } @@ -1584,17 +1584,17 @@ check_nonexistent_service_no_auto_start (BusContext *context, dbus_bool_t retval; const char *nonexistent = NONEXISTENT_SERVICE_NAME; dbus_uint32_t flags; - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "StartServiceByName"); - + if (message == NULL) return TRUE; dbus_message_set_auto_start (message, FALSE); - + flags = 0; if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &nonexistent, @@ -1604,7 +1604,7 @@ check_nonexistent_service_no_auto_start (BusContext *context, dbus_message_unref (message); return TRUE; } - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -1623,9 +1623,9 @@ check_nonexistent_service_no_auto_start (BusContext *context, _dbus_verbose ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -1645,7 +1645,7 @@ check_nonexistent_service_no_auto_start (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -1670,11 +1670,11 @@ check_nonexistent_service_no_auto_start (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -1688,15 +1688,15 @@ check_nonexistent_service_auto_start (BusContext *context, DBusMessage *message; dbus_uint32_t serial; dbus_bool_t retval; - + message = dbus_message_new_method_call (NONEXISTENT_SERVICE_NAME, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Echo"); - + if (message == NULL) return TRUE; - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -1715,9 +1715,9 @@ check_nonexistent_service_auto_start (BusContext *context, _dbus_verbose ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) @@ -1738,7 +1738,7 @@ check_nonexistent_service_auto_start (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -1763,11 +1763,11 @@ check_nonexistent_service_auto_start (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -1781,16 +1781,16 @@ check_base_service_activated (BusContext *context, dbus_bool_t retval; DBusError error; const char *base_service, *base_service_from_bus, *old_owner; - + retval = FALSE; - + dbus_error_init (&error); base_service = NULL; old_owner = NULL; base_service_from_bus = NULL; message = initial_message; - dbus_message_ref (message); + dbus_message_ref (message); if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, @@ -1830,7 +1830,7 @@ check_base_service_activated (BusContext *context, base_service); goto out; } - + if (strcmp (base_service, base_service_from_bus) != 0) { _dbus_warn ("Expected base service activation, got \"%s\" instead with owner \"%s\"\n", @@ -1844,14 +1844,14 @@ check_base_service_activated (BusContext *context, old_owner); goto out; } - + socd.expected_kind = SERVICE_CREATED; socd.expected_service_name = base_service; socd.failed = FALSE; socd.skip_connection = connection; bus_test_clients_foreach (check_service_owner_changed_foreach, &socd); - + if (socd.failed) goto out; } @@ -1866,7 +1866,7 @@ check_base_service_activated (BusContext *context, *base_service_p = base_service; retval = TRUE; - + out: if (message) dbus_message_unref (message); @@ -1886,9 +1886,9 @@ check_service_activated (BusContext *context, dbus_bool_t retval; DBusError error; dbus_uint32_t activation_result; - + retval = FALSE; - + dbus_error_init (&error); message = initial_message; @@ -1955,15 +1955,15 @@ check_service_activated (BusContext *context, socd.expected_service_name = service_name; bus_test_clients_foreach (check_service_owner_changed_foreach, &socd); - + if (socd.failed) goto out; - + dbus_message_unref (message); service_name = NULL; old_owner = NULL; base_service_from_bus = NULL; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -1975,10 +1975,10 @@ check_service_activated (BusContext *context, else { warn_unexpected (connection, message, "NameOwnerChanged for the activated name"); - + goto out; } - + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_RETURN) { warn_unexpected (connection, message, "reply to StartServiceByName"); @@ -2016,7 +2016,7 @@ check_service_activated (BusContext *context, dbus_message_unref (message); message = NULL; - + if (!check_no_leftovers (context)) { _dbus_warn ("Messages were left over after verifying existent activation results\n"); @@ -2024,12 +2024,12 @@ check_service_activated (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); dbus_error_free (&error); - + return retval; } @@ -2043,9 +2043,9 @@ check_service_auto_activated (BusContext *context, DBusMessage *message; dbus_bool_t retval; DBusError error; - + retval = FALSE; - + dbus_error_init (&error); message = initial_message; @@ -2057,7 +2057,7 @@ check_service_auto_activated (BusContext *context, { const char *service_name; CheckServiceOwnerChangedData socd; - + reget_service_name_arg: if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service_name, @@ -2078,28 +2078,28 @@ check_service_auto_activated (BusContext *context, goto out; } } - + if (strcmp (service_name, activated_name) != 0) { _dbus_warn ("Expected to see service %s created, saw %s instead\n", activated_name, service_name); goto out; } - + socd.expected_kind = SERVICE_CREATED; socd.expected_service_name = service_name; socd.failed = FALSE; - socd.skip_connection = connection; + socd.skip_connection = connection; bus_test_clients_foreach (check_service_owner_changed_foreach, &socd); - + if (socd.failed) goto out; - + /* Note that this differs from regular activation in that we don't get a * reply to ActivateService here. */ - + dbus_message_unref (message); message = NULL; service_name = NULL; @@ -2107,16 +2107,16 @@ check_service_auto_activated (BusContext *context, else { warn_unexpected (connection, message, "NameOwnerChanged for the activated name"); - + goto out; } - + retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -2130,7 +2130,7 @@ check_service_deactivated (BusContext *context, CheckServiceOwnerChangedData socd; retval = FALSE; - + /* Now we are expecting ServiceOwnerChanged (deletion) messages for the base * service and the activated_name. The base service * notification is required to come last. @@ -2140,11 +2140,11 @@ check_service_deactivated (BusContext *context, socd.failed = FALSE; socd.skip_connection = NULL; bus_test_clients_foreach (check_service_owner_changed_foreach, - &socd); + &socd); if (socd.failed) goto out; - + socd.expected_kind = SERVICE_DELETED; socd.expected_service_name = base_service; socd.failed = FALSE; @@ -2156,7 +2156,7 @@ check_service_deactivated (BusContext *context, goto out; retval = TRUE; - + out: return retval; } @@ -2171,27 +2171,27 @@ check_send_exit_to_service (BusContext *context, DBusMessage *message; dbus_uint32_t serial; dbus_bool_t retval; - + _dbus_verbose ("Sending exit message to the test service\n"); retval = FALSE; - + /* Kill off the test service by sending it a quit message */ message = dbus_message_new_method_call (service_name, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Exit"); - + if (message == NULL) { /* Do this again; we still need the service to exit... */ if (!check_send_exit_to_service (context, connection, service_name, base_service)) goto out; - + return TRUE; } - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -2200,7 +2200,7 @@ check_send_exit_to_service (BusContext *context, if (!check_send_exit_to_service (context, connection, service_name, base_service)) goto out; - + return TRUE; } @@ -2222,12 +2222,12 @@ check_send_exit_to_service (BusContext *context, dbus_connection_return_message (connection, message); message = NULL; } - + if (!got_error) { /* If no error, wait for the test service to exit */ block_connection_until_message_from_bus (context, connection, "test service to exit"); - + bus_test_run_everything (context); } @@ -2242,7 +2242,7 @@ check_send_exit_to_service (BusContext *context, "error with the correct reply serial"); goto out; } - + if (!dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -2270,7 +2270,7 @@ check_send_exit_to_service (BusContext *context, * stuff. */ message = pop_message_waiting_for_memory (connection); - + if (message == NULL) { warn_unexpected (connection, NULL, @@ -2291,10 +2291,10 @@ check_send_exit_to_service (BusContext *context, "error with the correct reply serial"); goto out; } - + _dbus_verbose ("Got error %s after test service exited\n", dbus_message_get_error_name (message)); - + if (!check_no_leftovers (context)) { _dbus_warn ("Messages were left over after %s\n", @@ -2302,13 +2302,13 @@ check_send_exit_to_service (BusContext *context, goto out; } } - + retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -2323,9 +2323,9 @@ check_got_error (BusContext *context, va_list ap; dbus_bool_t error_found; const char *error_name; - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -2364,20 +2364,20 @@ check_got_error (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } - + typedef enum -{ +{ GOT_SERVICE_CREATED, GOT_SERVICE_DELETED, GOT_ERROR, - GOT_SOMETHING_ELSE + GOT_SOMETHING_ELSE } GotServiceInfo; static GotServiceInfo @@ -2451,7 +2451,7 @@ check_existent_service_no_auto_start (BusContext *context, dbus_uint32_t flags; base_service_message = NULL; - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -2461,7 +2461,7 @@ check_existent_service_no_auto_start (BusContext *context, return TRUE; dbus_message_set_auto_start (message, FALSE); - + flags = 0; if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &existent, @@ -2471,7 +2471,7 @@ check_existent_service_no_auto_start (BusContext *context, dbus_message_unref (message); return TRUE; } - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -2495,9 +2495,9 @@ check_existent_service_no_auto_start (BusContext *context, _dbus_verbose ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -2518,7 +2518,7 @@ check_existent_service_no_auto_start (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -2543,7 +2543,7 @@ check_existent_service_no_auto_start (BusContext *context, else { GotServiceInfo message_kind; - + if (!check_base_service_activated (context, connection, message, &base_service)) goto out; @@ -2553,7 +2553,7 @@ check_existent_service_no_auto_start (BusContext *context, /* We may need to block here for the test service to exit or finish up */ block_connection_until_message_from_bus (context, connection, "test service to exit or finish up"); - + message = dbus_connection_borrow_message (connection); if (message == NULL) { @@ -2596,7 +2596,7 @@ check_existent_service_no_auto_start (BusContext *context, socd.expected_service_name = base_service; socd.failed = FALSE; socd.skip_connection = NULL; - + bus_test_clients_foreach (check_service_owner_changed_foreach, &socd); @@ -2609,10 +2609,10 @@ check_existent_service_no_auto_start (BusContext *context, if (message_kind != GOT_ERROR) { block_connection_until_message_from_bus (context, connection, "error about service exiting"); - + /* and process everything again */ bus_test_run_everything (context); - + if (!check_got_error (context, connection, DBUS_ERROR_SPAWN_CHILD_EXITED, DBUS_ERROR_NO_MEMORY, @@ -2630,11 +2630,11 @@ check_existent_service_no_auto_start (BusContext *context, "should have been a NameOwnerChanged (creation)\n"); goto out; } - + if (!check_service_activated (context, connection, EXISTENT_SERVICE_NAME, base_service, message)) goto out; - + dbus_message_unref (message); message = NULL; @@ -2653,14 +2653,14 @@ check_existent_service_no_auto_start (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); if (base_service_message) dbus_message_unref (base_service_message); - + return retval; } @@ -2677,7 +2677,7 @@ check_segfault_service_no_auto_start (BusContext *context, dbus_bool_t retval; const char *segv_service; dbus_uint32_t flags; - + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -2687,7 +2687,7 @@ check_segfault_service_no_auto_start (BusContext *context, return TRUE; dbus_message_set_auto_start (message, FALSE); - + segv_service = "org.freedesktop.DBus.TestSuiteSegfaultService"; flags = 0; if (!dbus_message_append_args (message, @@ -2698,7 +2698,7 @@ check_segfault_service_no_auto_start (BusContext *context, dbus_message_unref (message); return TRUE; } - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -2717,9 +2717,9 @@ check_segfault_service_no_auto_start (BusContext *context, _dbus_verbose ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -2739,7 +2739,7 @@ check_segfault_service_no_auto_start (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -2772,11 +2772,11 @@ check_segfault_service_no_auto_start (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -2796,10 +2796,10 @@ check_segfault_service_auto_start (BusContext *context, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Echo"); - + if (message == NULL) return TRUE; - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -2818,9 +2818,9 @@ check_segfault_service_auto_start (BusContext *context, _dbus_verbose ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -2840,7 +2840,7 @@ check_segfault_service_auto_start (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -2865,11 +2865,11 @@ check_segfault_service_auto_start (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } #endif @@ -2892,7 +2892,7 @@ check_existent_hello_from_self (BusContext *context, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "RunHelloFromSelf"); - + if (message == NULL) return TRUE; @@ -2920,7 +2920,7 @@ check_existent_hello_from_self (BusContext *context, * doesn't send a reply due to OOM. */ block_connection_until_message_from_bus (context, connection, "reply from running hello from self"); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -2937,7 +2937,7 @@ check_existent_hello_from_self (BusContext *context, dbus_message_unref (message); message = NULL; - + return TRUE; } @@ -2954,7 +2954,7 @@ check_existent_ping (BusContext *context, "/org/freedesktop/TestSuite", "org.freedesktop.DBus.Peer", "Ping"); - + if (message == NULL) return TRUE; @@ -2973,7 +2973,7 @@ check_existent_ping (BusContext *context, * doesn't send a reply due to OOM. */ block_connection_until_message_from_bus (context, connection, "reply from running Ping"); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -2997,7 +2997,7 @@ check_existent_ping (BusContext *context, dbus_message_unref (message); message = NULL; - + return TRUE; } @@ -3011,12 +3011,12 @@ check_existent_get_machine_id (BusContext *context, DBusMessage *message; dbus_uint32_t serial; const char *machine_id; - + message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME, "/org/freedesktop/TestSuite", "org.freedesktop.DBus.Peer", "GetMachineId"); - + if (message == NULL) return TRUE; @@ -3035,7 +3035,7 @@ check_existent_get_machine_id (BusContext *context, * doesn't send a reply due to OOM. */ block_connection_until_message_from_bus (context, connection, "reply from running GetMachineId"); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3071,14 +3071,14 @@ check_existent_get_machine_id (BusContext *context, dbus_message_unref (message); return FALSE; } - + /* We can't check that the machine id is correct because during make check it is * just made up for each process separately */ - + dbus_message_unref (message); message = NULL; - + return TRUE; } @@ -3102,7 +3102,7 @@ check_existent_service_auto_start (BusContext *context, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Echo"); - + if (message == NULL) return TRUE; @@ -3139,7 +3139,7 @@ check_existent_service_auto_start (BusContext *context, } retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3184,7 +3184,7 @@ check_existent_service_auto_start (BusContext *context, dbus_connection_return_message (connection, message); message = NULL; - switch (message_kind) + switch (message_kind) { case GOT_SERVICE_CREATED: message = pop_message_waiting_for_memory (connection); @@ -3194,12 +3194,12 @@ check_existent_service_auto_start (BusContext *context, "should have been a NameOwnerChanged (creation)\n"); goto out; } - + /* Check that ServiceOwnerChanged (creation) was correctly received */ if (!check_service_auto_activated (context, connection, EXISTENT_SERVICE_NAME, base_service, message)) goto out; - + dbus_message_unref (message); message = NULL; @@ -3211,7 +3211,7 @@ check_existent_service_auto_start (BusContext *context, * failed to register under EXISTENT_SERVICE_NAME */ CheckServiceOwnerChangedData socd; - + socd.expected_kind = SERVICE_DELETED; socd.expected_service_name = base_service; socd.failed = FALSE; @@ -3240,7 +3240,7 @@ check_existent_service_auto_start (BusContext *context, * doesn't send a reply due to OOM. */ block_connection_until_message_from_bus (context, connection, "reply from echo message after auto-activation"); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3262,7 +3262,7 @@ check_existent_service_auto_start (BusContext *context, if (!check_existent_get_machine_id (context, connection)) goto out; - + if (!check_existent_hello_from_self (context, connection)) goto out; @@ -3270,7 +3270,7 @@ check_existent_service_auto_start (BusContext *context, EXISTENT_SERVICE_NAME, base_service)) goto out; - + retval = TRUE; out: @@ -3300,7 +3300,7 @@ check_launch_service_file_missing (BusContext *context, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Echo"); - + if (message == NULL) return TRUE; @@ -3322,9 +3322,9 @@ check_launch_service_file_missing (BusContext *context, _dbus_verbose ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3344,7 +3344,7 @@ check_launch_service_file_missing (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -3370,11 +3370,11 @@ check_launch_service_file_missing (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -3418,9 +3418,9 @@ check_launch_service_user_missing (BusContext *context, _dbus_warn ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3440,7 +3440,7 @@ check_launch_service_user_missing (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -3466,11 +3466,11 @@ check_launch_service_user_missing (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -3514,9 +3514,9 @@ check_launch_service_exec_missing (BusContext *context, _dbus_warn ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3536,7 +3536,7 @@ check_launch_service_exec_missing (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -3570,11 +3570,11 @@ check_launch_service_exec_missing (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -3618,9 +3618,9 @@ check_launch_service_service_missing (BusContext *context, _dbus_warn ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3640,7 +3640,7 @@ check_launch_service_service_missing (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -3674,11 +3674,11 @@ check_launch_service_service_missing (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -3699,10 +3699,10 @@ check_shell_fail_service_auto_start (BusContext *context, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Echo"); - + if (message == NULL) return TRUE; - + if (!dbus_connection_send (connection, message, &serial)) { dbus_message_unref (message); @@ -3721,9 +3721,9 @@ check_shell_fail_service_auto_start (BusContext *context, _dbus_verbose ("connection was disconnected\n"); return TRUE; } - + retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3743,7 +3743,7 @@ check_shell_fail_service_auto_start (BusContext *context, dbus_message_get_sender (message) : "(none)"); goto out; } - + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) { @@ -3769,11 +3769,11 @@ check_shell_fail_service_auto_start (BusContext *context, } retval = TRUE; - + out: if (message) dbus_message_unref (message); - + return retval; } @@ -3799,7 +3799,7 @@ check_shell_service_success_auto_start (BusContext *context, "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Echo"); - + if (message == NULL) return TRUE; @@ -3827,7 +3827,7 @@ check_shell_service_success_auto_start (BusContext *context, } retval = FALSE; - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3872,7 +3872,7 @@ check_shell_service_success_auto_start (BusContext *context, dbus_connection_return_message (connection, message); message = NULL; - switch (message_kind) + switch (message_kind) { case GOT_SERVICE_CREATED: message = pop_message_waiting_for_memory (connection); @@ -3882,12 +3882,12 @@ check_shell_service_success_auto_start (BusContext *context, "should have been a NameOwnerChanged (creation)\n"); goto out; } - + /* Check that ServiceOwnerChanged (creation) was correctly received */ if (!check_service_auto_activated (context, connection, SHELL_SUCCESS_SERVICE_NAME, base_service, message)) goto out; - + dbus_message_unref (message); message = NULL; @@ -3899,7 +3899,7 @@ check_shell_service_success_auto_start (BusContext *context, * failed to register under SHELL_SUCCESS_SERVICE_NAME */ CheckServiceOwnerChangedData socd; - + socd.expected_kind = SERVICE_DELETED; socd.expected_service_name = base_service; socd.failed = FALSE; @@ -3928,7 +3928,7 @@ check_shell_service_success_auto_start (BusContext *context, * doesn't send a reply due to OOM. */ block_connection_until_message_from_bus (context, connection, "reply from echo message after auto-activation"); - + message = pop_message_waiting_for_memory (connection); if (message == NULL) { @@ -3943,7 +3943,7 @@ check_shell_service_success_auto_start (BusContext *context, } if (!dbus_message_get_args (message, NULL, - DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[0], DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_STRING, &argv[2], DBUS_TYPE_STRING, &argv[3], @@ -3956,59 +3956,59 @@ check_shell_service_success_auto_start (BusContext *context, goto out; } - /* don't worry about arg[0] as it may be different + /* don't worry about arg[0] as it may be different depending on the path to the tests */ if (strcmp("-test", argv[1]) != 0) { - _dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)\n", + _dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)\n", "-test", argv[1]); goto out; - } + } if (strcmp("that", argv[2]) != 0) { - _dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)\n", + _dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)\n", "that", argv[2]); goto out; - } + } if (strcmp("we get", argv[3]) != 0) { - _dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)\n", + _dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)\n", "we get", argv[3]); goto out; - } - + } + if (strcmp("back", argv[4]) != 0) { - _dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)\n", + _dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)\n", "back", argv[4]); goto out; - } + } if (strcmp("--what", argv[5]) != 0) { - _dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)\n", + _dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)\n", "--what", argv[5]); goto out; - } + } if (strcmp("we put in", argv[6]) != 0) { - _dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)\n", + _dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)\n", "we put in", argv[6]); goto out; - } + } dbus_message_unref (message); message = NULL; - + if (!check_send_exit_to_service (context, connection, SHELL_SUCCESS_SERVICE_NAME, base_service)) goto out; - + retval = TRUE; out: @@ -4034,7 +4034,7 @@ check_oom_check1_func (void *data) if (! (* d->func) (d->context)) return FALSE; - + if (!check_no_leftovers (d->context)) { _dbus_warn ("Messages were left over, should be covered by test suite\n"); @@ -4174,15 +4174,15 @@ check_get_services (BusContext *context, *len = l; } } - + if (!check_no_leftovers (context)) goto out; - + retval = TRUE; - + out: dbus_error_free (&error); - + if (message) dbus_message_unref (message); @@ -4355,7 +4355,7 @@ check_list_services (BusContext *context, "should have been a NameOwnerChanged (creation)\n"); goto out; } - + if (!check_service_activated (context, connection, EXISTENT_SERVICE_NAME, base_service, message)) goto out; @@ -4372,7 +4372,7 @@ check_list_services (BusContext *context, break; } } - + if (!check_get_services (context, connection, "ListNames", &services, &len)) { return TRUE; @@ -4416,7 +4416,7 @@ check_oom_check2_func (void *data) if (! (* d->func) (d->context, d->connection)) return FALSE; - + if (!check_no_leftovers (d->context)) { _dbus_warn ("Messages were left over, should be covered by test suite\n"); @@ -4437,7 +4437,7 @@ check2_try_iterations (BusContext *context, d.func = func; d.context = context; d.connection = connection; - + if (!_dbus_test_oom_handling (description, check_oom_check2_func, &d)) { @@ -4460,19 +4460,19 @@ setenv_TEST_LAUNCH_HELPER_CONFIG(const DBusString *test_data_dir, { _dbus_string_free (&full); return FALSE; - } + } _dbus_string_init_const (&file, filename); - + if (!_dbus_concat_dir_and_file (&full, &file)) { _dbus_string_free (&full); return FALSE; } - _dbus_verbose ("Setting TEST_LAUNCH_HELPER_CONFIG to '%s'\n", + _dbus_verbose ("Setting TEST_LAUNCH_HELPER_CONFIG to '%s'\n", _dbus_string_get_const_data (&full)); - + _dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", _dbus_string_get_const_data (&full)); _dbus_string_free (&full); @@ -4496,11 +4496,11 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, _dbus_assert_not_reached ("no memory setting TEST_LAUNCH_HELPER_CONFIG"); dbus_error_init (&error); - + context = bus_context_new_test (test_data_dir, filename); if (context == NULL) return FALSE; - + foo = dbus_connection_open_private (TEST_CONNECTION, &error); if (foo == NULL) _dbus_assert_not_reached ("could not alloc connection"); @@ -4509,7 +4509,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, _dbus_assert_not_reached ("could not set up connection"); spin_connection_until_authenticated (context, foo); - + if (!check_hello_message (context, foo)) _dbus_assert_not_reached ("hello message failed"); @@ -4518,7 +4518,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, if (!check_add_match_all (context, foo)) _dbus_assert_not_reached ("AddMatch message failed"); - + bar = dbus_connection_open_private (TEST_CONNECTION, &error); if (bar == NULL) _dbus_assert_not_reached ("could not alloc connection"); @@ -4527,13 +4527,13 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, _dbus_assert_not_reached ("could not set up connection"); spin_connection_until_authenticated (context, bar); - + if (!check_hello_message (context, bar)) _dbus_assert_not_reached ("hello message failed"); if (!check_add_match_all (context, bar)) _dbus_assert_not_reached ("AddMatch message failed"); - + baz = dbus_connection_open_private (TEST_CONNECTION, &error); if (baz == NULL) _dbus_assert_not_reached ("could not alloc connection"); @@ -4542,7 +4542,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, _dbus_assert_not_reached ("could not set up connection"); spin_connection_until_authenticated (context, baz); - + if (!check_hello_message (context, baz)) _dbus_assert_not_reached ("hello message failed"); @@ -4562,16 +4562,16 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, if (!check_list_services (context, baz)) _dbus_assert_not_reached ("ListActivatableNames message failed"); - + if (!check_no_leftovers (context)) { _dbus_warn ("Messages were left over after setting up initial connections\n"); _dbus_assert_not_reached ("initial connection setup failed"); } - + check1_try_iterations (context, "create_and_hello", check_hello_connection); - + check2_try_iterations (context, foo, "nonexistent_service_no_auto_start", check_nonexistent_service_no_auto_start); @@ -4581,15 +4581,15 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, check2_try_iterations (context, foo, "segfault_service_no_auto_start", check_segfault_service_no_auto_start); #endif - + check2_try_iterations (context, foo, "existent_service_no_auto_start", check_existent_service_no_auto_start); - + check2_try_iterations (context, foo, "nonexistent_service_auto_start", check_nonexistent_service_auto_start); - -#ifdef DBUS_WIN_FIXME + +#ifdef DBUS_WIN_FIXME _dbus_warn("TODO: dispatch.c segfault_service_auto_start test\n"); #else /* only do the segfault test if we are not using the launcher */ @@ -4614,7 +4614,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, check2_try_iterations (context, foo, "existent_service_auto_auto_start", check_existent_service_auto_start); #endif - + if (!check_existent_service_auto_start (context, foo)) _dbus_assert_not_reached ("existent service auto start failed"); @@ -4628,7 +4628,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, kill_client_connection_unchecked (baz); bus_context_unref (context); - + return TRUE; } @@ -4643,13 +4643,13 @@ bus_dispatch_test_conf_fail (const DBusString *test_data_dir, /* save the config name for the activation helper */ if (!setenv_TEST_LAUNCH_HELPER_CONFIG (test_data_dir, filename)) _dbus_assert_not_reached ("no memory setting TEST_LAUNCH_HELPER_CONFIG"); - + dbus_error_init (&error); - + context = bus_context_new_test (test_data_dir, filename); if (context == NULL) return FALSE; - + foo = dbus_connection_open_private (TEST_CONNECTION, &error); if (foo == NULL) _dbus_assert_not_reached ("could not alloc connection"); @@ -4685,7 +4685,7 @@ bus_dispatch_test_conf_fail (const DBusString *test_data_dir, kill_client_connection_unchecked (foo); bus_context_unref (context); - + return TRUE; } @@ -4724,10 +4724,10 @@ bus_dispatch_sha1_test (const DBusString *test_data_dir) DBusError error; dbus_error_init (&error); - + /* Test SHA1 authentication */ _dbus_verbose ("Testing SHA1 context\n"); - + context = bus_context_new_test (test_data_dir, "valid-config-files/debug-allow-all-sha1.conf"); if (context == NULL) @@ -4741,19 +4741,19 @@ bus_dispatch_sha1_test (const DBusString *test_data_dir) _dbus_assert_not_reached ("could not set up connection"); spin_connection_until_authenticated (context, foo); - + if (!check_hello_message (context, foo)) _dbus_assert_not_reached ("hello message failed"); if (!check_add_match_all (context, foo)) _dbus_assert_not_reached ("addmatch message failed"); - + if (!check_no_leftovers (context)) { _dbus_warn ("Messages were left over after setting up initial SHA-1 connection\n"); _dbus_assert_not_reached ("initial connection setup failed"); } - + check1_try_iterations (context, "create_and_hello_sha1", check_hello_connection); diff --git a/bus/driver.c b/bus/driver.c index 0dcfdaa4..cc8d1f26 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -5,7 +5,7 @@ * Copyright (C) 2003, 2004, 2005 Red Hat, Inc. * * Licensed under the Academic Free License version 2.1 - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -15,7 +15,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -57,20 +57,20 @@ bus_driver_send_service_owner_changed (const char *service_name, null_service = ""; _dbus_verbose ("sending name owner changed: %s [%s -> %s]\n", - service_name, - old_owner ? old_owner : null_service, + service_name, + old_owner ? old_owner : null_service, new_owner ? new_owner : null_service); message = dbus_message_new_signal (DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameOwnerChanged"); - + if (message == NULL) { BUS_SET_OOM (error); return FALSE; } - + if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS)) goto oom; @@ -82,7 +82,7 @@ bus_driver_send_service_owner_changed (const char *service_name, goto oom; _dbus_assert (dbus_message_has_signature (message, "sss")); - + retval = bus_dispatch_matches (transaction, NULL, NULL, message, error); dbus_message_unref (message); @@ -103,17 +103,17 @@ bus_driver_send_service_lost (DBusConnection *connection, DBusMessage *message; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + message = dbus_message_new_signal (DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameLost"); - + if (message == NULL) { BUS_SET_OOM (error); return FALSE; } - + if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) || !dbus_message_append_args (message, DBUS_TYPE_STRING, &service_name, @@ -146,7 +146,7 @@ bus_driver_send_service_acquired (DBusConnection *connection, DBusMessage *message; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + message = dbus_message_new_signal (DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameAcquired"); @@ -156,7 +156,7 @@ bus_driver_send_service_acquired (DBusConnection *connection, BUS_SET_OOM (error); return FALSE; } - + if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) || !dbus_message_append_args (message, DBUS_TYPE_STRING, &service_name, @@ -194,9 +194,9 @@ create_unique_client_name (BusRegistry *registry, static int next_major_number = 0; static int next_minor_number = 0; int len; - + len = _dbus_string_get_length (str); - + while (TRUE) { /* start out with 1-0, go to 1-1, 1-2, 1-3, @@ -214,21 +214,21 @@ create_unique_client_name (BusRegistry *registry, _dbus_assert (next_minor_number >= 0); /* appname:MAJOR-MINOR */ - + if (!_dbus_string_append (str, ":")) return FALSE; - + if (!_dbus_string_append_int (str, next_major_number)) return FALSE; if (!_dbus_string_append (str, ".")) return FALSE; - + if (!_dbus_string_append_int (str, next_minor_number)) return FALSE; next_minor_number += 1; - + /* Check if a client with the name exists */ if (bus_registry_lookup (registry, str) == NULL) break; @@ -275,7 +275,7 @@ bus_driver_handle_hello (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); return FALSE; } - + if (!_dbus_string_init (&unique_name)) { BUS_SET_OOM (error); @@ -285,7 +285,7 @@ bus_driver_handle_hello (DBusConnection *connection, retval = FALSE; registry = bus_connection_get_registry (connection); - + if (!create_unique_client_name (registry, &unique_name)) { BUS_SET_OOM (error); @@ -297,14 +297,14 @@ bus_driver_handle_hello (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); goto out_0; } - + if (!dbus_message_set_sender (message, bus_connection_get_name (connection))) { BUS_SET_OOM (error); goto out_0; } - + if (!bus_driver_send_welcome_message (connection, message, transaction, error)) goto out_0; @@ -313,10 +313,10 @@ bus_driver_handle_hello (DBusConnection *connection, &unique_name, connection, 0, transaction, error); if (service == NULL) goto out_0; - + _dbus_assert (bus_connection_is_active (connection)); retval = TRUE; - + out_0: _dbus_string_free (&unique_name); return retval; @@ -332,17 +332,17 @@ bus_driver_send_welcome_message (DBusConnection *connection, const char *name; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + name = bus_connection_get_name (connection); _dbus_assert (name != NULL); - + welcome = dbus_message_new_method_return (hello_message); if (welcome == NULL) { BUS_SET_OOM (error); return FALSE; } - + if (!dbus_message_append_args (welcome, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) @@ -353,7 +353,7 @@ bus_driver_send_welcome_message (DBusConnection *connection, } _dbus_assert (dbus_message_has_signature (welcome, DBUS_TYPE_STRING_AS_STRING)); - + if (!bus_transaction_send_from_driver (transaction, connection, welcome)) { dbus_message_unref (welcome); @@ -382,9 +382,9 @@ bus_driver_handle_list_services (DBusConnection *connection, DBusMessageIter sub; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + registry = bus_connection_get_registry (connection); - + reply = dbus_message_new_method_return (message); if (reply == NULL) { @@ -400,7 +400,7 @@ bus_driver_handle_list_services (DBusConnection *connection, } dbus_message_iter_init_append (reply, &iter); - + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &sub)) @@ -423,7 +423,7 @@ bus_driver_handle_list_services (DBusConnection *connection, return FALSE; } } - + i = 0; while (i < len) { @@ -446,7 +446,7 @@ bus_driver_handle_list_services (DBusConnection *connection, BUS_SET_OOM (error); return FALSE; } - + if (!bus_transaction_send_from_driver (transaction, connection, reply)) { dbus_message_unref (reply); @@ -568,17 +568,17 @@ bus_driver_handle_acquire_service (DBusConnection *connection, BusRegistry *registry; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + registry = bus_connection_get_registry (connection); - + if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID)) return FALSE; - + _dbus_verbose ("Trying to own name %s with flags 0x%x\n", name, flags); - + retval = FALSE; reply = NULL; @@ -589,7 +589,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection, &service_reply, transaction, error)) goto out; - + reply = dbus_message_new_method_return (message); if (reply == NULL) { @@ -610,12 +610,12 @@ bus_driver_handle_acquire_service (DBusConnection *connection, } retval = TRUE; - + out: if (reply) dbus_message_unref (reply); return retval; -} +} static dbus_bool_t bus_driver_handle_release_service (DBusConnection *connection, @@ -693,9 +693,9 @@ bus_driver_handle_service_exists (DBusConnection *connection, BusRegistry *registry; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + registry = bus_connection_get_registry (connection); - + if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) @@ -713,7 +713,7 @@ bus_driver_handle_service_exists (DBusConnection *connection, service = bus_registry_lookup (registry, &service_name); service_exists = service != NULL; } - + reply = dbus_message_new_method_return (message); if (reply == NULL) { @@ -736,7 +736,7 @@ bus_driver_handle_service_exists (DBusConnection *connection, } retval = TRUE; - + out: if (reply) dbus_message_unref (reply); @@ -756,9 +756,9 @@ bus_driver_handle_activate_service (DBusConnection *connection, BusActivation *activation; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + activation = bus_connection_get_activation (connection); - + if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT32, &flags, @@ -780,7 +780,7 @@ bus_driver_handle_activate_service (DBusConnection *connection, } retval = TRUE; - + out: return retval; } @@ -811,7 +811,7 @@ send_ack_reply (DBusConnection *connection, } dbus_message_unref (reply); - + return TRUE; } @@ -952,7 +952,7 @@ bus_driver_handle_add_match (DBusConnection *connection, const char *text; DBusString str; BusMatchmaker *matchmaker; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); text = NULL; @@ -969,7 +969,7 @@ bus_driver_handle_add_match (DBusConnection *connection, "(inactive)"); goto failed; } - + if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID)) @@ -998,9 +998,9 @@ bus_driver_handle_add_match (DBusConnection *connection, bus_matchmaker_remove_rule (matchmaker, rule); goto failed; } - + bus_match_rule_unref (rule); - + return TRUE; failed: @@ -1020,12 +1020,12 @@ bus_driver_handle_remove_match (DBusConnection *connection, const char *text; DBusString str; BusMatchmaker *matchmaker; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); text = NULL; rule = NULL; - + if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID)) @@ -1046,14 +1046,14 @@ bus_driver_handle_remove_match (DBusConnection *connection, if (!send_ack_reply (connection, transaction, message, error)) goto failed; - + matchmaker = bus_connection_get_matchmaker (connection); if (!bus_matchmaker_remove_rule_by_value (matchmaker, rule, error)) goto failed; bus_match_rule_unref (rule); - + return TRUE; failed: @@ -1075,7 +1075,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, BusRegistry *registry; BusService *service; DBusMessage *reply; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); registry = bus_connection_get_registry (connection); @@ -1098,7 +1098,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, } else if (service == NULL) { - dbus_set_error (error, + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Could not get owner of name '%s': no such name", text); goto failed; @@ -1114,7 +1114,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, "Could not determine unique name for '%s'", text); goto failed; } - _dbus_assert (*base_name == ':'); + _dbus_assert (*base_name == ':'); } _dbus_assert (base_name != NULL); @@ -1123,11 +1123,11 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, if (reply == NULL) goto oom; - if (! dbus_message_append_args (reply, + if (! dbus_message_append_args (reply, DBUS_TYPE_STRING, &base_name, DBUS_TYPE_INVALID)) goto oom; - + if (! bus_transaction_send_from_driver (transaction, connection, reply)) goto oom; @@ -1160,7 +1160,7 @@ bus_driver_handle_list_queued_owners (DBusConnection *connection, DBusMessage *reply; DBusMessageIter iter, array_iter; char *dbus_service_name = DBUS_SERVICE_DBUS; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); registry = bus_connection_get_registry (connection); @@ -1185,14 +1185,14 @@ bus_driver_handle_list_queued_owners (DBusConnection *connection, } else if (service == NULL) { - dbus_set_error (error, + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Could not get owners of name '%s': no such name", text); goto failed; } else { - if (!bus_service_list_queued_owners (service, + if (!bus_service_list_queued_owners (service, &base_names, error)) goto failed; @@ -1210,7 +1210,7 @@ bus_driver_handle_list_queued_owners (DBusConnection *connection, DBUS_TYPE_STRING_AS_STRING, &array_iter)) goto oom; - + link = _dbus_list_get_first_link (&base_names); while (link != NULL) { @@ -1218,8 +1218,8 @@ bus_driver_handle_list_queued_owners (DBusConnection *connection, _dbus_assert (link->data != NULL); uname = (char *)link->data; - - if (!dbus_message_iter_append_basic (&array_iter, + + if (!dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &uname)) goto oom; @@ -1229,8 +1229,8 @@ bus_driver_handle_list_queued_owners (DBusConnection *connection, if (! dbus_message_iter_close_container (&iter, &array_iter)) goto oom; - - + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) goto oom; @@ -1285,7 +1285,7 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, serv = bus_registry_lookup (registry, &str); if (serv == NULL) { - dbus_set_error (error, + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Could not get UID of name '%s': no such name", service); goto failed; @@ -1361,7 +1361,7 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, serv = bus_registry_lookup (registry, &str); if (serv == NULL) { - dbus_set_error (error, + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Could not get PID of name '%s': no such name", service); goto failed; @@ -1437,7 +1437,7 @@ bus_driver_handle_get_adt_audit_session_data (DBusConnection *connection, serv = bus_registry_lookup (registry, &str); if (serv == NULL) { - dbus_set_error (error, + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Could not get audit session data for name '%s': no such name", service); goto failed; @@ -1511,7 +1511,7 @@ bus_driver_handle_get_connection_selinux_security_context (DBusConnection *conne serv = bus_registry_lookup (registry, &str); if (serv == NULL) { - dbus_set_error (error, + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Could not get security context of name '%s': no such name", service); goto failed; @@ -1564,7 +1564,7 @@ bus_driver_handle_reload_config (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_CLEAR (error); reply = NULL; - + context = bus_connection_get_context (connection); if (!bus_context_reload_config (context, error)) goto failed; @@ -1609,7 +1609,7 @@ bus_driver_handle_get_id (DBusConnection *connection, } reply = NULL; - + context = bus_connection_get_context (connection); if (!bus_context_get_id (context, &uuid)) goto oom; @@ -1623,24 +1623,24 @@ bus_driver_handle_get_id (DBusConnection *connection, DBUS_TYPE_STRING, &v_STRING, DBUS_TYPE_INVALID)) goto oom; - + _dbus_assert (dbus_message_has_signature (reply, "s")); - + if (! bus_transaction_send_from_driver (transaction, connection, reply)) goto oom; - _dbus_string_free (&uuid); + _dbus_string_free (&uuid); dbus_message_unref (reply); return TRUE; oom: _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + BUS_SET_OOM (error); if (reply) dbus_message_unref (reply); - _dbus_string_free (&uuid); + _dbus_string_free (&uuid); return FALSE; } @@ -1661,7 +1661,7 @@ static struct { "Hello", "", DBUS_TYPE_STRING_AS_STRING, - bus_driver_handle_hello }, + bus_driver_handle_hello }, { "RequestName", DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING, DBUS_TYPE_UINT32_AS_STRING, @@ -1740,10 +1740,10 @@ write_args_for_direction (DBusString *xml, DBusTypeReader typereader; DBusString sigstr; int current_type; - + _dbus_string_init_const (&sigstr, signature); _dbus_type_reader_init_types_only (&typereader, &sigstr, 0); - + while ((current_type = _dbus_type_reader_get_current_type (&typereader)) != DBUS_TYPE_INVALID) { const DBusString *subsig; @@ -1794,7 +1794,7 @@ bus_driver_generate_introspect_string (DBusString *xml) i = 0; while (i < _DBUS_N_ELEMENTS (message_handlers)) { - + if (!_dbus_string_append_printf (xml, " <method name=\"%s\">\n", message_handlers[i].name)) return FALSE; @@ -1807,22 +1807,22 @@ bus_driver_generate_introspect_string (DBusString *xml) if (!_dbus_string_append (xml, " </method>\n")) return FALSE; - + ++i; } if (!_dbus_string_append_printf (xml, " <signal name=\"NameOwnerChanged\">\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " </signal>\n")) return FALSE; @@ -1830,10 +1830,10 @@ bus_driver_generate_introspect_string (DBusString *xml) if (!_dbus_string_append_printf (xml, " <signal name=\"NameLost\">\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " </signal>\n")) return FALSE; @@ -1841,16 +1841,16 @@ bus_driver_generate_introspect_string (DBusString *xml) if (!_dbus_string_append_printf (xml, " <signal name=\"NameAcquired\">\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) return FALSE; - + if (!_dbus_string_append_printf (xml, " </signal>\n")) return FALSE; if (!_dbus_string_append (xml, " </interface>\n")) return FALSE; - + if (!_dbus_string_append (xml, "</node>\n")) return FALSE; @@ -1868,7 +1868,7 @@ bus_driver_handle_introspect (DBusConnection *connection, const char *v_STRING; _dbus_verbose ("Introspect() on bus driver\n"); - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); reply = NULL; @@ -1915,7 +1915,7 @@ bus_driver_handle_introspect (DBusConnection *connection, dbus_message_unref (reply); _dbus_string_free (&xml); - + return FALSE; } @@ -1930,6 +1930,14 @@ bus_driver_handle_message (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_CLEAR (error); + if (dbus_message_is_signal (message, "org.freedesktop.systemd1.Activator", "ActivationFailure")) + { + BusContext *context; + + context = bus_connection_get_context (connection); + return dbus_activation_systemd_failure(bus_context_get_activation(context), message); + } + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL) { _dbus_verbose ("Driver got a non-method-call message, ignoring\n"); @@ -1940,16 +1948,16 @@ bus_driver_handle_message (DBusConnection *connection, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) return bus_driver_handle_introspect (connection, transaction, message, error); - + interface = dbus_message_get_interface (message); if (interface == NULL) interface = DBUS_INTERFACE_DBUS; - + _dbus_assert (dbus_message_get_member (message) != NULL); - + name = dbus_message_get_member (message); sender = dbus_message_get_sender (message); - + if (strcmp (interface, DBUS_INTERFACE_DBUS) != 0) { @@ -1957,13 +1965,13 @@ bus_driver_handle_message (DBusConnection *connection, interface); goto unknown; } - + _dbus_verbose ("Driver got a method call: %s\n", dbus_message_get_member (message)); - + /* security checks should have kept this from getting here */ _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0); - + i = 0; while (i < _DBUS_N_ELEMENTS (message_handlers)) { @@ -1977,7 +1985,7 @@ bus_driver_handle_message (DBusConnection *connection, _dbus_verbose ("Call to %s has wrong args (%s, expected %s)\n", name, dbus_message_get_signature (message), message_handlers[i].in_args); - + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, "Call to %s has wrong args (%s, expected %s)\n", name, dbus_message_get_signature (message), @@ -1985,7 +1993,7 @@ bus_driver_handle_message (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); return FALSE; } - + if ((* message_handlers[i].handler) (connection, transaction, message, error)) { _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -1999,7 +2007,7 @@ bus_driver_handle_message (DBusConnection *connection, return FALSE; } } - + ++i; } @@ -2010,7 +2018,7 @@ bus_driver_handle_message (DBusConnection *connection, dbus_set_error (error, DBUS_ERROR_UNKNOWN_METHOD, "%s does not understand message %s", DBUS_SERVICE_DBUS, name); - + return FALSE; } @@ -75,7 +75,7 @@ signal_handler (int sig) static void usage (void) { - fprintf (stderr, DBUS_DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect] [--address=ADDRESS]\n"); + fprintf (stderr, DBUS_DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect] [--address=ADDRESS] [--systemd-activation]\n"); exit (1); } @@ -274,6 +274,7 @@ main (int argc, char **argv) dbus_bool_t print_pid; dbus_bool_t is_session_bus; int force_fork; + dbus_bool_t systemd_activation; if (!_dbus_string_init (&config_file)) return 1; @@ -291,6 +292,7 @@ main (int argc, char **argv) print_pid = FALSE; is_session_bus = FALSE; force_fork = FORK_FOLLOW_CONFIG_FILE; + systemd_activation = FALSE; prev_arg = NULL; i = 1; @@ -310,6 +312,8 @@ main (int argc, char **argv) force_fork = FORK_NEVER; else if (strcmp (arg, "--fork") == 0) force_fork = FORK_ALWAYS; + else if (strcmp (arg, "--systemd-activation") == 0) + systemd_activation = TRUE; else if (strcmp (arg, "--system") == 0) { check_two_config_files (&config_file, "system"); @@ -488,6 +492,7 @@ main (int argc, char **argv) context = bus_context_new (&config_file, force_fork, &print_addr_pipe, &print_pid_pipe, _dbus_string_get_length(&address) > 0 ? &address : NULL, + systemd_activation, &error); _dbus_string_free (&config_file); if (context == NULL) @@ -323,7 +323,7 @@ bus_context_new_test (const DBusString *test_data_dir, } dbus_error_init (&error); - context = bus_context_new (&config_file, FALSE, NULL, NULL, NULL, &error); + context = bus_context_new (&config_file, FALSE, NULL, NULL, NULL, FALSE, &error); if (context == NULL) { _DBUS_ASSERT_ERROR_IS_SET (&error); |