summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-11-14 16:41:23 +0000
committerSimon McVittie <smcv@collabora.com>2017-11-15 12:12:27 +0000
commitfc30e312ea98b3765983be03fcb08ae64ee48b2d (patch)
tree3f2a0d8ac91610242cb381d85dae3cdb1e1a26c8
parent39ef65d07d2475c43ae6d46e251cc62010d4c27f (diff)
bus: Silence the output of the test services when doing OOM testing
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
-rw-r--r--bus/activation.c5
-rw-r--r--bus/bus.c6
-rw-r--r--bus/bus.h1
-rw-r--r--dbus/dbus-spawn.c38
-rw-r--r--dbus/dbus-spawn.h1
5 files changed, 38 insertions, 13 deletions
diff --git a/bus/activation.c b/bus/activation.c
index 8f3aab86e..edf96a2cc 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -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;
diff --git a/bus/bus.c b/bus/bus.c
index bd2ab8bda..295dc7b50 100644
--- 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
diff --git a/bus/bus.h b/bus/bus.h
index 31af363b8..647f9988d 100644
--- 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 */
diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c
index b2bcc2260..4fc67b6df 100644
--- a/dbus/dbus-spawn.c
+++ b/dbus/dbus-spawn.c
@@ -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);
diff --git a/dbus/dbus-spawn.h b/dbus/dbus-spawn.h
index b34324def..a5450d6e9 100644
--- a/dbus/dbus-spawn.h
+++ b/dbus/dbus-spawn.h
@@ -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;