summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog22
-rw-r--r--tools/dbus-launch.148
-rw-r--r--tools/dbus-launch.c126
-rw-r--r--tools/dbus-monitor.110
-rw-r--r--tools/dbus-monitor.c6
-rw-r--r--tools/dbus-send.110
-rw-r--r--tools/dbus-send.c20
7 files changed, 203 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index 1a411832..f362de9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2003-05-17 Colin Walters <walters@gnu.org>
+
+ * tools/dbus-send.c: Don't exit with an error code if --help was
+ passed. Default to using the session bus instead of the system
+ one.
+
+ * tools/dbus-launch.c: Ditto.
+
+ * tools/dbus-monitor.c: Ditto.
+
+ * tools/dbus-send.1: Update with new arguments.
+
+ * tools/dbus-launch.c: Emit code to export variables. New
+ arguments -s and -c to specify shell syntax, and a bit of code to
+ autodetect syntax. Also, allow specifying a program to run.
+
+ * tools/dbus-launch.1: Update with new arguments.
+
+ * tools/dbus-send.1: Ditto.
+
+ * tools/dbus-monitor.1: Ditto.
+
2003-05-17 Havoc Pennington <hp@pobox.com>
* bus/config-parser.c (merge_included): merge in policies from
diff --git a/tools/dbus-launch.1 b/tools/dbus-launch.1
index c0fb03f6..95708c77 100644
--- a/tools/dbus-launch.1
+++ b/tools/dbus-launch.1
@@ -7,7 +7,7 @@
dbus-launch \- Utility to start a message bus from a shell script
.SH SYNOPSIS
.PP
-.B dbus-launch [\-\-version] [\-\-exit-with-session]
+.B dbus-launch [\-\-version] [\-\-sh-syntax] [\-\-csh-syntax] [\-\-auto-syntax] [\-\-exit-with-session] [PROGRAM] [ARGS...]
.SH DESCRIPTION
@@ -15,8 +15,25 @@ The \fIdbus-launch\fP command is used to start \fIdbus-daemon-1\fP
from a shell script. It would normally be called from a user's login
scripts. Unlike the daemon itself, \fIdbus-launch\fP exits, so
backticks or the $() construct can be used to read information from
-\fIdbus-launch\fP. \fIdbus-launch\fP prints information about the
-launched daemon in KEY=VALUE format.
+\fIdbus-launch\fP.
+
+With no arguments, \fIdbus-launch\fP will simply print the values of
+DBUS_SESSION_BUS_ADDRESS and DBUS_SESSION_BUS_PID.
+
+You may specify a program to be run; in this case, \fIdbus-launch\fP
+will then set the appropriate environment variables and execute the
+specified program, with the specified arguments. See below for
+examples.
+
+Finally, you may use the \-\-auto-syntax command to cause
+\fIdbus-launch\fP to emit shell code to set up the environment. This
+is useful in shell scripts. With this option, \fIdbus-launch\fP looks
+at the value of the SHELL environment variable to determine which
+shell syntax should be used. If SHELL ends in "csh", then
+csh-compatible code is emitted; otherwise Bourne shell code is
+emitted. Instead of passing \-\-auto-syntax, you may explicity
+specify a particular one by using \-\-sh-syntax for Bourne syntax, or
+\-\-csh-syntax for csh syntax.
.PP
See http://www.freedesktop.org/software/dbus/ for more information
@@ -30,17 +47,34 @@ sh-compatible shell to start the per-session bus daemon:
## test for an existing bus daemon, just to be safe
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
## if not found, launch a new one
- eval `dbus-launch --exit-with-session`
+ eval `dbus-launch --auto-syntax --exit-with-session`
echo "D-BUS per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
- export DBUS_SESSION_BUS_ADDRESS
fi
.fi
You might run something like that in your login scripts.
+.PP
+Another way to use \fIdbus-launch\fP is to run your main session
+program, like so:
+.nf
+
+dbus-launch gnome-session
+
+.fi
+The above would likely be appropriate for ~/.xsession.
+
.SH OPTIONS
The following options are supported:
.TP
+.I "--auto-syntax"
+Attempt to detect the shell in use, and emit compatible code.
+
+.TP
+.I "--csh-syntax"
+Emit csh compatible code.
+
+.TP
.I "--exit-with-session"
If this option is provided, a persistent "babysitter" process will be
created that watches stdin for HUP and tries to connect to the X
@@ -48,6 +82,10 @@ server. If this process gets a HUP on stdin or loses its X connection,
it kills the message bus daemon.
.TP
+.I "--sh-syntax"
+Emit Bourne-shell compatible code.
+
+.TP
.I "--version"
Print the version of dbus-launch
diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c
index f0b9e589..4d21d105 100644
--- a/tools/dbus-launch.c
+++ b/tools/dbus-launch.c
@@ -77,10 +77,10 @@ verbose (const char *format,
}
static void
-usage (void)
+usage (int ecode)
{
- fprintf (stderr, "dbus-launch [--version] [--exit-with-session]\n");
- exit (1);
+ fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session]\n");
+ exit (ecode);
}
static void
@@ -94,6 +94,26 @@ version (void)
exit (0);
}
+static char *
+xstrdup (const char *str)
+{
+ int len;
+ char *copy;
+
+ if (str == NULL)
+ return NULL;
+
+ len = strlen (str);
+
+ copy = malloc (len + 1);
+ if (copy == NULL)
+ return NULL;
+
+ memcpy (copy, str, len + 1);
+
+ return copy;
+}
+
typedef enum
{
READ_STATUS_OK, /**< Read succeeded */
@@ -277,6 +297,7 @@ x_io_error_handler (Display *xdisplay)
{
verbose ("X IO error\n");
kill_bus_and_exit ();
+ return 0;
}
#endif
@@ -543,7 +564,13 @@ int
main (int argc, char **argv)
{
const char *prev_arg;
+ const char *shname;
+ const char *runprog = NULL;
+ int remaining_args = 0;
int exit_with_session;
+ int c_shell_syntax = FALSE;
+ int bourne_shell_syntax = FALSE;
+ int auto_shell_syntax = FALSE;
int i;
int ret;
int bus_pid_to_launcher_pipe[2];
@@ -561,20 +588,48 @@ main (int argc, char **argv)
if (strcmp (arg, "--help") == 0 ||
strcmp (arg, "-h") == 0 ||
strcmp (arg, "-?") == 0)
- usage ();
+ usage (0);
+ else if (strcmp (arg, "--auto-syntax") == 0)
+ auto_shell_syntax = TRUE;
+ else if (strcmp (arg, "-c") == 0 ||
+ strcmp (arg, "--csh-syntax") == 0)
+ c_shell_syntax = TRUE;
+ else if (strcmp (arg, "-s") == 0 ||
+ strcmp (arg, "--sh-syntax") == 0)
+ bourne_shell_syntax = TRUE;
else if (strcmp (arg, "--version") == 0)
version ();
else if (strcmp (arg, "--exit-with-session") == 0)
exit_with_session = TRUE;
+ else if (runprog)
+ usage (1);
else
- usage ();
+ {
+ runprog = arg;
+ remaining_args = i+1;
+ break;
+ }
prev_arg = arg;
++i;
}
- verbose ("--exit-with-session provided\n");
+ if (exit_with_session)
+ verbose ("--exit-with-session enabled\n");
+
+ if (auto_shell_syntax)
+ {
+ if ((shname = getenv ("SHELL")) != NULL)
+ {
+ if (!strncmp (shname + strlen (shname) - 3, "csh", 3))
+ c_shell_syntax = TRUE;
+ else
+ bourne_shell_syntax = TRUE;
+ }
+ else
+ bourne_shell_syntax = TRUE;
+ }
if (pipe (bus_pid_to_launcher_pipe) < 0 ||
pipe (bus_address_to_launcher_pipe) < 0)
@@ -737,17 +792,62 @@ main (int argc, char **argv)
}
close (bus_pid_to_launcher_pipe[READ_END]);
-
- printf ("DBUS_SESSION_BUS_ADDRESS='%s'\n",
- bus_address);
-
- printf ("DBUS_SESSION_BUS_PID=%ld\n",
- (long) bus_pid);
-
+
+ if (runprog)
+ {
+ char *envvar;
+ char **args;
+
+ envvar = malloc (strlen ("DBUS_SESSION_BUS_ADDRESS=") + strlen (bus_address) + 1);
+ args = malloc (sizeof (char *) * ((argc-remaining_args)+2));
+
+ if (envvar == NULL || args == NULL)
+ goto oom;
+
+ args[0] = xstrdup (runprog);
+ if (!args[0])
+ goto oom;
+ for (i = 1; i <= (argc-remaining_args); i++)
+ {
+ size_t len = strlen (argv[remaining_args+i-1])+1;
+ args[i] = malloc (len);
+ if (!args[i])
+ goto oom;
+ strncpy (args[i], argv[remaining_args+i-1], len);
+ }
+ args[i] = NULL;
+
+ strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS=");
+ strcat (envvar, bus_address);
+ putenv (envvar);
+
+ execvp (runprog, args);
+ fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno));
+ exit (1);
+ }
+ else
+ {
+ if (c_shell_syntax)
+ printf ("setenv DBUS_SESSION_BUS_ADDRESS '%s'\n", bus_address);
+ else
+ {
+ printf ("DBUS_SESSION_BUS_ADDRESS='%s'\n", bus_address);
+ if (bourne_shell_syntax)
+ printf ("export DBUS_SESSION_BUS_ADDRESS\n");
+ }
+ if (c_shell_syntax)
+ printf ("set DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid);
+ else
+ printf ("DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid);
+ }
+
verbose ("dbus-launch exiting\n");
exit (0);
}
return 0;
+ oom:
+ fprintf (stderr, "Out of memory!");
+ exit (1);
}
diff --git a/tools/dbus-monitor.1 b/tools/dbus-monitor.1
index ff4172ec..fd741144 100644
--- a/tools/dbus-monitor.1
+++ b/tools/dbus-monitor.1
@@ -8,7 +8,7 @@ dbus-monitor \- debug probe to print message bus messages
.SH SYNOPSIS
.PP
.B dbus-monitor
-[\-\-session]
+[\-\-system]
.SH DESCRIPTION
@@ -21,15 +21,17 @@ the big picture.
There are two well-known message buses: the systemwide message bus
(installed on many systems as the "messagebus" service) and the
per-user-login-session message bus (started each time a user logs in).
-\fIdbus-monitor\fP by default monitors the systemwide bus; to monitor the
-session bus, specify \-\-session.
+\fIdbus-monitor\fP by default monitors the session bus; to monitor the
+system bus, specify \-\-system.
.PP
The message bus configuration may keep \fIdbus-monitor\fP from seeing
all messages, especially if you run the monitor as a non-root user.
.SH OPTIONS
-No options are currently supported.
+.TP
+.I "--system"
+Use the system message bus instead of the session bus.
.SH AUTHOR
dbus-monitor was written by Philip Blundell.
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index 465515ba..9628c422 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -46,7 +46,7 @@ handler_func (DBusMessageHandler *handler,
static void
usage (char *name, int ecode)
{
- fprintf (stderr, "Usage: %s [--session]\n", name);
+ fprintf (stderr, "Usage: %s [--system]\n", name);
exit (ecode);
}
@@ -55,7 +55,7 @@ main (int argc, char *argv[])
{
DBusConnection *connection;
DBusError error;
- DBusBusType type = DBUS_BUS_SYSTEM;
+ DBusBusType type = DBUS_BUS_SESSION;
DBusMessageHandler *handler;
GMainLoop *loop;
int i;
@@ -65,7 +65,7 @@ main (int argc, char *argv[])
char *arg = argv[i];
if (!strcmp (arg, "--session"))
- type = DBUS_BUS_SESSION;
+ type = DBUS_BUS_SYSTEM;
else if (!strcmp (arg, "--help"))
usage (argv[0], 0);
else if (!strcmp (arg, "--"))
diff --git a/tools/dbus-send.1 b/tools/dbus-send.1
index 6f125c35..87aea49d 100644
--- a/tools/dbus-send.1
+++ b/tools/dbus-send.1
@@ -8,7 +8,7 @@ dbus-send \- Send a message to a message bus
.SH SYNOPSIS
.PP
.B dbus-send
-[\-\-session] [\-\-dest=SERVICE] [\-\-print-reply] <message name> [contents ...]
+[\-\-system] [\-\-dest=SERVICE] [\-\-print-reply] <message name> [contents ...]
.SH DESCRIPTION
@@ -20,8 +20,8 @@ information about the big picture.
There are two well-known message buses: the systemwide message bus
(installed on many systems as the "messagebus" service) and the
per-user-login-session message bus (started each time a user logs in).
-\fIdbus-send\fP sends messages to the system bus by default, and
-to the per-session bus if you specify \-\-session.
+\fIdbus-send\fP sends messages to the session bus by default, and
+to the system bus if you specify \-\-system.
.PP
Nearly all uses of \fIdbus-send\fP must provide the \-\-dest
@@ -56,8 +56,8 @@ Specify the service to receive the message.
.I "--print-reply"
Block for a reply to the message sent, and print any reply received.
.TP
-.I "--session"
-Use the per-login-session message bus instead of the systemwide bus.
+.I "--system"
+Use the system message bus instead of the session bus.
.SH AUTHOR
dbus-send was written by Philip Blundell.
diff --git a/tools/dbus-send.c b/tools/dbus-send.c
index ea00a836..cada26a4 100644
--- a/tools/dbus-send.c
+++ b/tools/dbus-send.c
@@ -28,10 +28,10 @@
#include "dbus-print-message.h"
static void
-usage (char *name)
+usage (char *name, int ecode)
{
- fprintf (stderr, "Usage: %s [--session] [--dest=SERVICE] [--print-reply] <message type> [contents ...]\n", name);
- exit (1);
+ fprintf (stderr, "Usage: %s [--help] [--session] [--dest=SERVICE] [--print-reply] <message type> [contents ...]\n", name);
+ exit (ecode);
}
int
@@ -43,12 +43,12 @@ main (int argc, char *argv[])
int print_reply;
DBusMessageIter iter;
int i;
- DBusBusType type = DBUS_BUS_SYSTEM;
+ DBusBusType type = DBUS_BUS_SESSION;
char *dest = DBUS_SERVICE_BROADCAST;
char *name = NULL;
if (argc < 2)
- usage (argv[0]);
+ usage (argv[0], 1);
print_reply = FALSE;
@@ -56,20 +56,22 @@ main (int argc, char *argv[])
{
char *arg = argv[i];
- if (strcmp (arg, "--session") == 0)
- type = DBUS_BUS_SESSION;
+ if (strcmp (arg, "--system") == 0)
+ type = DBUS_BUS_SYSTEM;
else if (strcmp (arg, "--print-reply") == 0)
print_reply = TRUE;
else if (strstr (arg, "--dest=") == arg)
dest = strchr (arg, '=') + 1;
+ else if (!strcmp(arg, "--help"))
+ usage (argv[0], 0);
else if (arg[0] == '-')
- usage (argv[0]);
+ usage (argv[0], 1);
else
name = arg;
}
if (name == NULL)
- usage (argv[0]);
+ usage (argv[0], 1);
dbus_error_init (&error);
connection = dbus_bus_get (type, &error);