]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Only redirect child processes to systemd Journal if using syslog
authorSimon McVittie <smcv@debian.org>
Thu, 21 Jul 2016 09:21:35 +0000 (10:21 +0100)
committerSimon McVittie <smcv@debian.org>
Fri, 30 Sep 2016 18:36:50 +0000 (19:36 +0100)
In particular this means the test suite won't spam the Journal
any more.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009

bus/activation.c
bus/bus.c
bus/bus.h
dbus/dbus-spawn-test.c
dbus/dbus-spawn-win.c
dbus/dbus-spawn.c
dbus/dbus-spawn.h
test/spawn-test.c

index 3bddb35db38303d5cb492f72ec31dc573fba9f1e..c614d520d94fe40e22aea65e01e226242d78a564 100644 (file)
@@ -1661,6 +1661,7 @@ bus_activation_activate_service (BusActivation  *activation,
   dbus_bool_t was_pending_activation;
   DBusString command;
   int limit;
+  DBusSpawnFlags flags = DBUS_SPAWN_NONE;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
@@ -2097,10 +2098,14 @@ bus_activation_activate_service (BusActivation  *activation,
 
   dbus_error_init (&tmp_error);
 
+  if (bus_context_get_using_syslog (activation->context))
+    flags |= DBUS_SPAWN_REDIRECT_OUTPUT;
+
   if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter,
                                           service_name,
                                           argv,
                                           envp,
+                                          flags,
                                           child_setup,
                                           activation,
                                           &tmp_error))
index 8856dab3bedd295f302e83c4ac68a0ff86eb40f7..df8239fff00b772d27884d91b5294315f4f954ac 100644 (file)
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -1366,6 +1366,12 @@ bus_context_get_initial_fd_limit (BusContext *context)
   return context->initial_fd_limit;
 }
 
+dbus_bool_t
+bus_context_get_using_syslog (BusContext *context)
+{
+  return context->syslog;
+}
+
 void
 bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
 {
index b7869b20a529c7a579b66bc26317f96090d15ec8..ca425336a02c057d22086cd56c579ec7d6dbdfc8 100644 (file)
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -121,6 +121,7 @@ int               bus_context_get_max_match_rules_per_connection (BusContext
 int               bus_context_get_max_replies_per_connection     (BusContext       *context);
 int               bus_context_get_reply_timeout                  (BusContext       *context);
 DBusRLimit *      bus_context_get_initial_fd_limit               (BusContext       *context);
+dbus_bool_t       bus_context_get_using_syslog                   (BusContext       *context);
 void              bus_context_log                                (BusContext       *context,
                                                                   DBusSystemLogSeverity severity,
                                                                   const char       *msg,
index 8c90fcc154f49a08745180e4add326f829cb07d9..01a26256f061391f1c16d206286a9b7873296daa 100644 (file)
@@ -64,7 +64,7 @@ check_spawn_nonexistent (void *data)
 
   argv[0] = "/this/does/not/exist/32542sdgafgafdg";
   if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv,
-                                         NULL, NULL, NULL,
+                                         NULL, DBUS_SPAWN_NONE, NULL, NULL,
                                          &error))
     {
       _dbus_babysitter_block_for_child_exit (sitter);
@@ -113,7 +113,7 @@ check_spawn_segfault (void *data)
     }
 
   if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_segfault", argv,
-                                         NULL, NULL, NULL,
+                                         NULL, DBUS_SPAWN_NONE, NULL, NULL,
                                          &error))
     {
       _dbus_babysitter_block_for_child_exit (sitter);
@@ -168,7 +168,7 @@ check_spawn_exit (void *data)
     }
 
   if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv,
-                                         NULL, NULL, NULL,
+                                         NULL, DBUS_SPAWN_NONE, NULL, NULL,
                                          &error))
     {
       _dbus_babysitter_block_for_child_exit (sitter);
@@ -219,7 +219,7 @@ check_spawn_and_kill (void *data)
     }
 
   if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv,
-                                         NULL, NULL, NULL,
+                                         NULL, DBUS_SPAWN_NONE, NULL, NULL,
                                          &error))
     {
       _dbus_babysitter_kill_child (sitter);
index 5cb3044e659969cc39f89f7a212adb61fe0c15f4..564f61d744a10cd29bf2d2c3bfc789854fdfbabf 100644 (file)
@@ -645,6 +645,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter           **sitter_p,
                                    const char                *log_name,
                                    char                     **argv,
                                    char                     **envp,
+                                   DBusSpawnFlags             flags _DBUS_GNUC_UNUSED,
                                    DBusSpawnChildSetupFunc    child_setup _DBUS_GNUC_UNUSED,
                                    void                      *user_data _DBUS_GNUC_UNUSED,
                                    DBusError                 *error)
index e810ad542ef060674a44cee8816238a27d02a2a8..70664cdfaa2b7926f20cd9669e45fb51710a240e 100644 (file)
@@ -1216,6 +1216,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
                                    const char               *log_name,
                                    char                    **argv,
                                    char                    **env,
+                                   DBusSpawnFlags            flags,
                                    DBusSpawnChildSetupFunc   child_setup,
                                    void                     *user_data,
                                    DBusError                *error)
@@ -1316,12 +1317,15 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
 #ifdef HAVE_SYSTEMD
-  /* This may fail, but it's not critical.
-   * In particular, if we were compiled with journald support but are now
-   * running on a non-systemd system, this is going to fail, so we
-   * have to cope gracefully. */
-  fd_out = sd_journal_stream_fd (sitter->log_name, LOG_INFO, FALSE);
-  fd_err = sd_journal_stream_fd (sitter->log_name, LOG_WARNING, FALSE);
+  if (flags & DBUS_SPAWN_REDIRECT_OUTPUT)
+    {
+      /* This may fail, but it's not critical.
+       * In particular, if we were compiled with journald support but are now
+       * running on a non-systemd system, this is going to fail, so we
+       * have to cope gracefully. */
+      fd_out = sd_journal_stream_fd (sitter->log_name, LOG_INFO, FALSE);
+      fd_err = sd_journal_stream_fd (sitter->log_name, LOG_WARNING, FALSE);
+    }
 #endif
 
   pid = fork ();
index 12ea5862aa2420eda831ca6ac5671254b9415f25..dc04dc7ca64450f7677cc11ba178b0f185464dd0 100644 (file)
@@ -38,10 +38,16 @@ typedef struct DBusBabysitter DBusBabysitter;
 typedef void (* DBusBabysitterFinishedFunc) (DBusBabysitter *sitter,
                                              void           *user_data);
 
+typedef enum {
+  DBUS_SPAWN_REDIRECT_OUTPUT = (1 << 0),
+  DBUS_SPAWN_NONE = 0
+} DBusSpawnFlags;
+
 dbus_bool_t _dbus_spawn_async_with_babysitter     (DBusBabysitter           **sitter_p,
                                                    const char                *log_name,
                                                    char                     **argv,
                                                    char                     **env,
+                                                   DBusSpawnFlags             flags,
                                                    DBusSpawnChildSetupFunc    child_setup,
                                                    void                      *user_data,
                                                    DBusError                 *error);
index 12d37c80dcdcaff2c9d4658bd3e4b65b35cdbd62..a12c869fcd4e8e9c9d6480201accd9aba7241594 100644 (file)
@@ -30,7 +30,9 @@ 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[0], argv_copy, NULL, setup_func, NULL, &error))
+  if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy[0], argv_copy, NULL,
+                                          DBUS_SPAWN_NONE, setup_func, NULL,
+                                          &error))
     {
       fprintf (stderr, "Could not launch application: \"%s\"\n",
               error.message);