summaryrefslogtreecommitdiff
path: root/test/test-service.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-12-14 18:12:24 -0500
committerColin Walters <walters@verbum.org>2009-12-15 13:08:02 -0500
commit949a64b127a32a3e5a4ce4278773f18e290c44c2 (patch)
tree5cd952cd8a0d671b2aeb1aabcaaa2f8f6993dd84 /test/test-service.c
parentaab383a63e994f40ddf8d8341b8b75c19e6c1a0f (diff)
downloaddbus-949a64b127a32a3e5a4ce4278773f18e290c44c2.tar.gz
Ignore exit code zero from activated services
A variety of system components have migrated from legacy init into DBus service activation. Many of these system components "daemonize", which involves forking. The DBus activation system treated an exit as an activation failure, assuming that the child process which grabbed the DBus name didn't run first. While we're in here, also differentiate in this code path between the servicehelper (system) versus direct activation (session) paths. In the session activation path our error message mentioned a helper process which was confusing, since none was involved. Based on a patch and debugging research from Ray Strode <rstrode@redhat.com>
Diffstat (limited to 'test/test-service.c')
-rw-r--r--test/test-service.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/test/test-service.c b/test/test-service.c
index c9f58390..a57bf9c2 100644
--- a/test/test-service.c
+++ b/test/test-service.c
@@ -398,7 +398,33 @@ main (int argc,
DBusError error;
int result;
DBusConnection *connection;
-
+ const char *name;
+ dbus_bool_t do_fork;
+
+ if (argc != 3)
+ {
+ name = "org.freedesktop.DBus.TestSuiteEchoService";
+ do_fork = FALSE;
+ }
+ else
+ {
+ name = argv[1];
+ do_fork = strcmp (argv[2], "fork") == 0;
+ }
+
+ /* The bare minimum for simulating a program "daemonizing"; the intent
+ * is to test services which move from being legacy init scripts to
+ * activated services.
+ * https://bugzilla.redhat.com/show_bug.cgi?id=545267
+ */
+ if (do_fork)
+ {
+ pid_t pid = fork ();
+ if (pid != 0)
+ exit (0);
+ sleep (1);
+ }
+
dbus_error_init (&error);
connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
if (connection == NULL)
@@ -433,8 +459,8 @@ main (int argc,
if (d != (void*) 0xdeadbeef)
die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
}
-
- result = dbus_bus_request_name (connection, "org.freedesktop.DBus.TestSuiteEchoService",
+
+ result = dbus_bus_request_name (connection, name,
0, &error);
if (dbus_error_is_set (&error))
{