summaryrefslogtreecommitdiff
path: root/tools/dbus-run-session.c
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-11-14 15:30:03 +0000
committerSimon McVittie <smcv@collabora.com>2017-11-15 12:12:18 +0000
commit13b640544dae99cfa851f3bbe9338ca58844aea8 (patch)
treebf08965b2182f5082b1179cbd26672b282c1cf5b /tools/dbus-run-session.c
parent3d2300efc3584d9b5aabe2b9c2130b0eedd381bc (diff)
downloaddbus-13b640544dae99cfa851f3bbe9338ca58844aea8.tar.gz
Unix: Flush stdout and stderr streams before forking
stdout and stderr are close-on-exec and buffered, so we can't rely on their buffers being empty. If we continue to execute application code after forking (as opposed to immediately exec()ing), then the child process might later flush the libc stdio buffers, resulting in output that is printed by the parent also being printed by the child. In particular, test-bus.log sometimes grows extremely large for this reason, because this test repeatedly attempts to carry out legacy activation. 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
Diffstat (limited to 'tools/dbus-run-session.c')
-rw-r--r--tools/dbus-run-session.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/dbus-run-session.c b/tools/dbus-run-session.c
index 0adb5ad1..6b93997e 100644
--- a/tools/dbus-run-session.c
+++ b/tools/dbus-run-session.c
@@ -354,6 +354,11 @@ main (int argc, char **argv)
return 127;
}
+ /* Make sure our output buffers aren't redundantly printed by both the
+ * parent and the child */
+ fflush (stdout);
+ fflush (stderr);
+
bus_pid = fork ();
if (bus_pid < 0)
@@ -401,6 +406,9 @@ main (int argc, char **argv)
!dbus_setenv ("DBUS_STARTER_BUS_TYPE", NULL))
oom ();
+ fflush (stdout);
+ fflush (stderr);
+
app_pid = fork ();
if (app_pid < 0)