summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorThiago Macieira <thiago@kde.org>2007-03-03 10:36:46 +0000
committerThiago Macieira <thiago@kde.org>2007-03-03 10:36:46 +0000
commit4ceb86d29a68ebe52b20c8c090bc90c68a58f8c8 (patch)
tree78657dc8500feea09a71e25688fc14b073a68b14 /tools
parentaa2f74f551b00158baaaf2031a986639f593942b (diff)
* 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.
Diffstat (limited to 'tools')
-rw-r--r--tools/dbus-launch.17
-rw-r--r--tools/dbus-launch.c31
2 files changed, 36 insertions, 2 deletions
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
@@ -136,6 +136,13 @@ 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
the \-\-session argument. See the man page for dbus-daemon
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