]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
bus: Silence the output of the test services when doing OOM testing
authorSimon McVittie <smcv@collabora.com>
Tue, 14 Nov 2017 16:41:23 +0000 (16:41 +0000)
committerSimon McVittie <smcv@collabora.com>
Wed, 15 Nov 2017 12:12:27 +0000 (12:12 +0000)
The echo service frequently fails to connect to the bus when we are
testing OOM code paths, again causing a lot of noise in the log.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601

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

index 8f3aab86e7084e9d0ac4de634c27e7894af652e6..edf96a2ccbfee33be8766e200cf3c98412daa021 100644 (file)
@@ -2220,6 +2220,11 @@ bus_activation_activate_service (BusActivation  *activation,
 
   dbus_error_init (&tmp_error);
 
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+  if (bus_context_get_quiet_log (activation->context))
+    flags |= DBUS_SPAWN_SILENCE_OUTPUT;
+#endif
+
   if (bus_context_get_using_syslog (activation->context))
     flags |= DBUS_SPAWN_REDIRECT_OUTPUT;
 
index bd2ab8bda054941b81e0a6f6ba6e936e7798734d..295dc7b50ce434bd33ed0f2d86dfe84416aefb7f 100644 (file)
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -1848,4 +1848,10 @@ bus_context_quiet_log_end (BusContext *context)
 {
   context->quiet_log = FALSE;
 }
+
+dbus_bool_t
+bus_context_get_quiet_log (BusContext *context)
+{
+  return context->quiet_log;
+}
 #endif
index 31af363b82e4d1f4d40f3d631445de7d62aa7b9f..647f9988d6bce3737be357265a4b8a2cbac571db 100644 (file)
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -149,6 +149,7 @@ void              bus_context_check_all_watches                  (BusContext
 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
 void              bus_context_quiet_log_begin                    (BusContext *context);
 void              bus_context_quiet_log_end                      (BusContext *context);
+dbus_bool_t       bus_context_get_quiet_log                      (BusContext *context);
 #endif
 
 #endif /* BUS_BUS_H */
index b2bcc2260382e02bf00b9f4c012f539834550775..4fc67b6df9dd538dc45f88913527863bf65dc2de 100644 (file)
@@ -1260,11 +1260,9 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
   int child_err_report_pipe[2] = { -1, -1 };
   DBusSocket babysitter_pipe[2] = { DBUS_SOCKET_INIT, DBUS_SOCKET_INIT };
   pid_t pid;
-#ifdef HAVE_SYSTEMD
   int fd_out = -1;
   int fd_err = -1;
-#endif
-  
+
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   _dbus_assert (argv[0] != NULL);
 
@@ -1351,8 +1349,27 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
+  if (flags & DBUS_SPAWN_SILENCE_OUTPUT)
+    {
+      fd_out = open ("/dev/null", O_RDONLY);
+
+      if (fd_out < 0)
+        {
+          dbus_set_error (error, _dbus_error_from_errno (errno),
+                          "Failed to open /dev/null: %s",
+                          _dbus_strerror (errno));
+          goto cleanup_and_fail;
+        }
+
+      _dbus_fd_set_close_on_exec (fd_out);
+
+      fd_err = _dbus_dup (fd_out, error);
+
+      if (fd_err < 0)
+        goto cleanup_and_fail;
+    }
 #ifdef HAVE_SYSTEMD
-  if (flags & DBUS_SPAWN_REDIRECT_OUTPUT)
+  else 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
@@ -1431,15 +1448,16 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
           signal (SIGPIPE, SIG_IGN);
 
           close_and_invalidate (&babysitter_pipe[1].fd);
-#ifdef HAVE_SYSTEMD
-         /* log to systemd journal if possible */
+
+          /* Redirect stdout, stderr to systemd Journal or /dev/null
+           * as requested, if possible */
          if (fd_out >= 0)
             dup2 (fd_out, STDOUT_FILENO);
          if (fd_err >= 0)
             dup2 (fd_err, STDERR_FILENO);
           close_and_invalidate (&fd_out);
           close_and_invalidate (&fd_err);
-#endif
+
          do_exec (child_err_report_pipe[WRITE_END],
                   argv,
                   env,
@@ -1449,10 +1467,8 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
       else
        {
           close_and_invalidate (&child_err_report_pipe[WRITE_END]);
-#ifdef HAVE_SYSTEMD
           close_and_invalidate (&fd_out);
           close_and_invalidate (&fd_err);
-#endif
           babysit (grandchild_pid, babysitter_pipe[1].fd);
           _dbus_assert_not_reached ("Got to code after babysit()");
        }
@@ -1462,10 +1478,8 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
       /* Close the uncared-about ends of the pipes */
       close_and_invalidate (&child_err_report_pipe[WRITE_END]);
       close_and_invalidate (&babysitter_pipe[1].fd);
-#ifdef HAVE_SYSTEMD
       close_and_invalidate (&fd_out);
       close_and_invalidate (&fd_err);
-#endif
 
       sitter->socket_to_babysitter = babysitter_pipe[0];
       babysitter_pipe[0].fd = -1;
@@ -1495,10 +1509,8 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
   close_and_invalidate (&child_err_report_pipe[WRITE_END]);
   close_and_invalidate (&babysitter_pipe[0].fd);
   close_and_invalidate (&babysitter_pipe[1].fd);
-#ifdef HAVE_SYSTEMD
   close_and_invalidate (&fd_out);
   close_and_invalidate (&fd_err);
-#endif
 
   if (sitter != NULL)
     _dbus_babysitter_unref (sitter);
index b34324def4cc5d07cf06601e7bde6f5ecd0232e9..a5450d6e91513144569826f17310ba62806b77ee 100644 (file)
@@ -40,6 +40,7 @@ typedef void (* DBusBabysitterFinishedFunc) (DBusBabysitter *sitter,
 
 typedef enum {
   DBUS_SPAWN_REDIRECT_OUTPUT = (1 << 0),
+  DBUS_SPAWN_SILENCE_OUTPUT = (1 << 1),
   DBUS_SPAWN_NONE = 0
 } DBusSpawnFlags;