From ea3bdfba1023a9977e8da7a06541bb879f59c846 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 24 Jul 2007 12:22:43 +0000 Subject: 2007-07-24 Richard Hughes * bus/activation.c: (handle_activation_exit_error), (babysitter_watch_callback): Map the child exit status integer to a proper dbus error. --- ChangeLog | 6 ++++++ bus/activation.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0f83d791..006d3348 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-07-24 Richard Hughes + + * bus/activation.c: (handle_activation_exit_error), + (babysitter_watch_callback): + Map the child exit status integer to a proper dbus error. + 2007-07-24 Richard Hughes * bus/bus.c: (process_config_first_time_only), diff --git a/bus/activation.c b/bus/activation.c index 41671d3d..b0ca14c4 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -1118,6 +1118,49 @@ pending_activation_failed (BusPendingActivation *pending_activation, pending_activation->service_name); } +/** + * Depending on the exit code of the helper, set the error accordingly + */ +static void +handle_activation_exit_error (int exit_code, DBusError *error) +{ + switch (exit_code) + { + case BUS_SPAWN_EXIT_CODE_NO_MEMORY: + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "Launcher could not run as out of memory"); + break; + case BUS_SPAWN_EXIT_CODE_SETUP_FAILED: + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "Failed to setup environment correctly"); + break; + case BUS_SPAWN_EXIT_CODE_NAME_INVALID: + dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_INVALID, + "Bus name is not valid or missing"); + break; + case BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND: + dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND, + "Bus name not found in system service directory"); + break; + case BUS_SPAWN_EXIT_CODE_PERMISSIONS_INVALID: + dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID, + "The permission of the setuid helper is not correct"); + break; + case BUS_SPAWN_EXIT_CODE_FILE_INVALID: + dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID, + "The service file is incorrect or does not have all required attributes"); + break; + case BUS_SPAWN_EXIT_CODE_EXEC_FAILED: + dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED, + "Cannot launch daemon, file not found or permissions invalid"); + break; + default: + dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED, + "Launch helper exited with unknown return code %i", exit_code); + break; + } +} + static dbus_bool_t babysitter_watch_callback (DBusWatch *watch, unsigned int condition, @@ -1151,6 +1194,17 @@ babysitter_watch_callback (DBusWatch *watch, dbus_error_init (&error); _dbus_babysitter_set_child_exit_error (babysitter, &error); + /* refine the error code if we got an exit code */ + if (dbus_error_has_name (&error, DBUS_ERROR_SPAWN_CHILD_EXITED)) + { + int exit_code = 0; + if (_dbus_babysitter_get_child_exit_status (babysitter, &exit_code)) + { + dbus_error_free (&error); + handle_activation_exit_error (exit_code, &error); + } + } + /* Destroy all pending activations with the same exec */ _dbus_hash_iter_init (pending_activation->activation->pending_activations, &iter); -- cgit v1.2.3