From 37776c8f07a0b780fbfce5daab745dca31b04305 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Mon, 9 Sep 2013 11:16:55 +0800 Subject: [PATCH 1/3] DBusBabysitter: use service_name as error msg identifier DBusBabysitter->executable is defined as executable name to use in error messages. However, if servicehelper used, then the executable name is servicehelper. It's not much help because we couldn't figure out which service we're trying to activated if error happens. So this patch change executable from argv[0] to service_name. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68559 --- bus/activation.c | 4 +++- dbus/dbus-spawn-win.c | 13 +++++++------ dbus/dbus-spawn.c | 14 ++++++++------ dbus/dbus-spawn.h | 1 + test/spawn-test.c | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bus/activation.c b/bus/activation.c index e03b6fe..8a17f9c 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -2099,7 +2099,9 @@ bus_activation_activate_service (BusActivation *activation, dbus_error_init (&tmp_error); - if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter, argv, + if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter, + service_name, + argv, envp, NULL, activation, &tmp_error)) diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index cd8ca66..3cc0656 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -642,6 +642,7 @@ babysitter (void *parameter) dbus_bool_t _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, + const char *service_name, char **argv, char **envp, DBusSpawnChildSetupFunc child_setup, @@ -667,8 +668,8 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, sitter->child_setup = child_setup; sitter->user_data = user_data; - sitter->executable = _dbus_strdup (argv[0]); - if (sitter->executable == NULL) + sitter->executable = _dbus_strdup (service_name); + if (sitter->executable == NULL && service_name != NULL) { _DBUS_SET_OOM (error); goto out0; @@ -804,7 +805,7 @@ check_spawn_nonexistent (void *data) /*** Test launching nonexistent binary */ argv[0] = "/this/does/not/exist/32542sdgafgafdg"; - if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, + if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv, NULL, NULL, NULL, &error)) { @@ -857,7 +858,7 @@ check_spawn_segfault (void *data) return TRUE; } - if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, + if (_dbus_spawn_async_with_babysitter (&sitter, , "spawn_segfault", argv, NULL, NULL, NULL, &error)) { @@ -912,7 +913,7 @@ check_spawn_exit (void *data) return TRUE; } - if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, + if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv, NULL, NULL, NULL, &error)) { @@ -967,7 +968,7 @@ check_spawn_and_kill (void *data) return TRUE; } - if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, + if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv, NULL, NULL, NULL, &error)) { diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index f8d5fd1..6200d21 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -1126,6 +1126,7 @@ babysit (pid_t grandchild_pid, * If sitter_p is #NULL, no babysitter is kept. * * @param sitter_p return location for babysitter or #NULL + * @service_name the service will be activated * @param argv the executable and arguments * @param env the environment (not used on unix yet) * @param child_setup function to call in child pre-exec() @@ -1135,6 +1136,7 @@ babysit (pid_t grandchild_pid, */ dbus_bool_t _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, + const char *service_name, char **argv, char **env, DBusSpawnChildSetupFunc child_setup, @@ -1160,8 +1162,8 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, return FALSE; } - sitter->executable = _dbus_strdup (argv[0]); - if (sitter->executable == NULL) + sitter->executable = _dbus_strdup (service_name); + if (sitter->executable == NULL && service_name != NULL) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); goto cleanup_and_fail; @@ -1368,7 +1370,7 @@ check_spawn_nonexistent (void *data) /*** Test launching nonexistent binary */ argv[0] = "/this/does/not/exist/32542sdgafgafdg"; - if (_dbus_spawn_async_with_babysitter (&sitter, argv, + if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv, NULL, NULL, NULL, &error)) { @@ -1417,7 +1419,7 @@ check_spawn_segfault (void *data) return TRUE; } - if (_dbus_spawn_async_with_babysitter (&sitter, argv, + if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_segfault", argv, NULL, NULL, NULL, &error)) { @@ -1468,7 +1470,7 @@ check_spawn_exit (void *data) return TRUE; } - if (_dbus_spawn_async_with_babysitter (&sitter, argv, + if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv, NULL, NULL, NULL, &error)) { @@ -1519,7 +1521,7 @@ check_spawn_and_kill (void *data) return TRUE; } - if (_dbus_spawn_async_with_babysitter (&sitter, argv, + if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv, NULL, NULL, NULL, &error)) { diff --git a/dbus/dbus-spawn.h b/dbus/dbus-spawn.h index a8814fb..2bb329e 100644 --- a/dbus/dbus-spawn.h +++ b/dbus/dbus-spawn.h @@ -39,6 +39,7 @@ typedef void (* DBusBabysitterFinishedFunc) (DBusBabysitter *sitter, void *user_data); dbus_bool_t _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, + const char *service_name, char **argv, char **env, DBusSpawnChildSetupFunc child_setup, diff --git a/test/spawn-test.c b/test/spawn-test.c index e6513fa..c156969 100644 --- a/test/spawn-test.c +++ b/test/spawn-test.c @@ -30,7 +30,7 @@ main (int argc, char **argv) argv_copy [i] = argv[i + 1]; argv_copy[argc - 1] = NULL; - if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy, NULL, setup_func, NULL, &error)) + if (!_dbus_spawn_async_with_babysitter (NULL, NULL, argv_copy, NULL, setup_func, NULL, &error)) { fprintf (stderr, "Could not launch application: \"%s\"\n", error.message); -- 1.7.9.5