From 4ceb86d29a68ebe52b20c8c090bc90c68a58f8c8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 3 Mar 2007 10:36:46 +0000 Subject: * dbus/dbus-sysdeps-unix.c: capture the dbus-launch stderr output and add it to the DBusError message we return. * tools/dbus-launch.1: * tools/dbus-launch.c: Add option --close-stderr to, well, close stderr before starting dbus-daemon. --- tools/dbus-launch.1 | 7 +++++++ tools/dbus-launch.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/dbus-launch.1 b/tools/dbus-launch.1 index 68adb2ca..0ea19495 100644 --- a/tools/dbus-launch.1 +++ b/tools/dbus-launch.1 @@ -135,6 +135,13 @@ binary integer of size sizeof(pid_t), then the bus X window ID as a binary integer of size sizeof(long). Integers are in the machine's byte order, not network byte order or any other canonical byte order. +.TP +.I "--close-stderr" +Close the standard error output stream before starting the D-Bus +daemon. This is useful if you want to capture dbus-launch error +messages but you don't want dbus-daemon to keep the stream open to +your application. + .TP .I "--config-file=FILENAME" Pass \-\-config-file=FILENAME to the bus daemon, instead of passing it diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 7e53e7e2..d3072782 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -596,6 +596,27 @@ babysit (int exit_with_session, exit (0); } +static void do_close_stderr (void) +{ + fflush (stderr); + + /* dbus-launch is a Unix-only program, so we can rely on /dev/null being there. + * We're including unistd.h and we're dealing with sh/csh launch sequences... + */ + int fd = open ("/dev/null", O_RDWR); + if (fd == -1) + { + fprintf (stderr, "Internal error: cannot open /dev/null: %s", strerror (errno)); + exit (1); + } + + close (2); + if (dup2 (fd, 2) == -1) + // error; we can't report an error anymore... + exit (1); + close (fd); +} + #define READ_END 0 #define WRITE_END 1 @@ -613,7 +634,8 @@ main (int argc, char **argv) int auto_shell_syntax = FALSE; int autolaunch = FALSE; int requires_arg = FALSE; - int i; + int close_stderr = FALSE; + int i; int ret; int bus_pid_to_launcher_pipe[2]; int bus_pid_to_babysitter_pipe[2]; @@ -647,6 +669,8 @@ main (int argc, char **argv) version (); else if (strcmp (arg, "--exit-with-session") == 0) exit_with_session = TRUE; + else if (strcmp (arg, "--close-stderr") == 0) + close_stderr = TRUE; else if (strstr (arg, "--autolaunch=") == arg) { const char *s; @@ -837,6 +861,9 @@ main (int argc, char **argv) char write_pid_fd_as_string[MAX_FD_LEN]; char write_address_fd_as_string[MAX_FD_LEN]; + if (close_stderr) + do_close_stderr (); + verbose ("=== Babysitter's intermediate parent created\n"); /* Fork once more to create babysitter */ @@ -859,7 +886,7 @@ main (int argc, char **argv) close (bus_address_to_launcher_pipe[READ_END]); close (bus_address_to_launcher_pipe[WRITE_END]); close (bus_pid_to_babysitter_pipe[WRITE_END]); - + /* babysit() will fork *again* * and will also reap the pre-forked bus * daemon -- cgit