[patch] make dbus-launch export vars, usage bits

Colin Walters walters@debian.org
16 May 2003 13:16:37 -0400


--=-kKMqYOEtSTu7x559ITqE
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

The attached patch makes dbus-launch export the variables it prints.  I
made it able to emit either Bourne syntax or csh syntax, like q-agent
and ssh-agent.  This is so you can just say:

eval `dbus-launch` in your ~/.xsession or whatever.

Also, I know this is minor, but I think when you pass --help to a
program, it shouldn't exit with an error.  So I fixed dbus-send.

Ok to commit?

--=-kKMqYOEtSTu7x559ITqE
Content-Disposition: attachment; filename=dbus-launch-and-usage.patch
Content-Type: text/x-patch; name=dbus-launch-and-usage.patch; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Index: ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/ChangeLog,v
retrieving revision 1.360
diff -u -d -r1.360 ChangeLog
--- ChangeLog	16 May 2003 16:48:07 -0000	1.360
+++ ChangeLog	16 May 2003 17:05:48 -0000
@@ -1,3 +1,16 @@
+2003-05-16  Colin Walters  <walters@verbum.org>
+
+	* tools/dbus-send.c: Don't exit with an error code if --help was
+	passed.
+
+	* tools/dbus-launch.c: Ditto.=20
+
+	* 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.
+=09
+	* tools/dbus-launch.1: Update with new arguments.
+
 2003-05-16  Havoc Pennington  <hp@redhat.com>
=20
 	* bus/policy.c (free_rule_list_func): avoid a crash when passed
Index: tools/dbus-send.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/tools/dbus-send.c,v
retrieving revision 1.2
diff -u -d -r1.2 dbus-send.c
--- tools/dbus-send.c	24 Apr 2003 19:18:23 -0000	1.2
+++ tools/dbus-send.c	16 May 2003 17:05:42 -0000
@@ -26,10 +26,10 @@
 #include <dbus/dbus.h>
=20
 static void
-usage (char *name)
+usage (char *name, int ecode)
 {
-  fprintf (stderr, "Usage: %s [--session] [--dest=3DSERVICE] <message type=
> [contents ...]\n", name);
-  exit (1);
+  fprintf (stderr, "Usage: %s [--help] [--session] [--dest=3DSERVICE] <mes=
sage type> [contents ...]\n", name);
+  exit (ecode);
 }
=20
 int
@@ -45,7 +45,7 @@
   char *name =3D NULL;
=20
   if (argc < 2)
-    usage (argv[0]);
+    usage (argv[0], 1);
=20
   for (i =3D 1; i < argc && name =3D=3D NULL; i++)
     {
@@ -55,14 +55,16 @@
 	type =3D DBUS_BUS_SESSION;
       else if (strstr (arg, "--dest=3D") =3D=3D arg)
 	dest =3D strchr (arg, '=3D') + 1;
+      else if (!strcmp(arg, "--help"))
+	usage (argv[0], 0);
       else if (arg[0] =3D=3D '-')
-	usage (argv[0]);
+	usage (argv[0], 1);
       else
 	name =3D arg;
     }
=20
   if (name =3D=3D NULL)
-    usage (argv[0]);
+    usage (argv[0], 1);
=20
   dbus_error_init (&error);
   connection =3D dbus_bus_get (type, &error);
Index: tools/dbus-launch.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/tools/dbus-launch.c,v
retrieving revision 1.2
diff -u -d -r1.2 dbus-launch.c
--- tools/dbus-launch.c	4 May 2003 08:54:24 -0000	1.2
+++ tools/dbus-launch.c	16 May 2003 17:05:42 -0000
@@ -77,10 +77,10 @@
 }
=20
 static void
-usage (void)
+usage (int ecode)
 {
-  fprintf (stderr, "dbus-launch [--version] [--exit-with-session]\n");
-  exit (1);
+  fprintf (stderr, "dbus-launch [--version] [--help] [-s] [-c] [--exit-wit=
h-session]\n");
+  exit (ecode);
 }
=20
 static void
@@ -543,7 +543,10 @@
 main (int argc, char **argv)
 {
   const char *prev_arg;
+  const char *shname;
   int exit_with_session;
+  int c_shell_syntax =3D FALSE;
+  int bourne_shell_syntax =3D FALSE;
   int i; =20
   int ret;
   int bus_pid_to_launcher_pipe[2];
@@ -561,20 +564,40 @@
       if (strcmp (arg, "--help") =3D=3D 0 ||
           strcmp (arg, "-h") =3D=3D 0 ||
           strcmp (arg, "-?") =3D=3D 0)
-        usage ();
+        usage (0);
+      else if (strcmp (arg, "-c") =3D=3D 0
+	       || strcmp (arg, "--csh-syntax") =3D=3D 0)
+        c_shell_syntax =3D TRUE;
+      else if (strcmp (arg, "-s") =3D=3D 0
+	       || strcmp (arg, "--sh-syntax") =3D=3D 0)
+        bourne_shell_syntax =3D TRUE;
       else if (strcmp (arg, "--version") =3D=3D 0)
         version ();
       else if (strcmp (arg, "--exit-with-session") =3D=3D 0)
         exit_with_session =3D TRUE;
       else
-        usage ();
+        usage (1);
      =20
       prev_arg =3D arg;
      =20
       ++i;
     }
=20
-  verbose ("--exit-with-session provided\n");
+  if (!c_shell_syntax && !bourne_shell_syntax)
+    {
+      if ((shname =3D getenv ("SHELL")) !=3D NULL)
+	{
+	  if (!strncmp (shname + strlen(shname) -3, "csh", 3))
+	    c_shell_syntax =3D TRUE;
+	  else
+	    bourne_shell_syntax =3D TRUE;
+	}
+      else
+	bourne_shell_syntax =3D TRUE;
+    }
+
+  if (exit_with_session)
+    verbose ("--exit-with-session enabled\n");
=20
   if (pipe (bus_pid_to_launcher_pipe) < 0 ||
       pipe (bus_address_to_launcher_pipe) < 0)
@@ -738,11 +761,22 @@
=20
       close (bus_pid_to_launcher_pipe[READ_END]);
=20
-      printf ("DBUS_SESSION_BUS_ADDRESS=3D'%s'\n",
-              bus_address);
-
-      printf ("DBUS_SESSION_BUS_PID=3D%ld\n",
-              (long) bus_pid);
+      if (bourne_shell_syntax)
+	{
+	  printf ("DBUS_SESSION_BUS_ADDRESS=3D'%s'; export DBUS_SESSION_BUS_ADDRE=
SS\n",
+		  bus_address);
+	 =20
+	  printf ("DBUS_SESSION_BUS_PID=3D%ld; export DBUS_SESSION_BUS_PID\n",
+		  (long) bus_pid);
+	}
+      else
+	{
+	  printf ("setenv DBUS_SESSION_BUS_ADDRESS '%s'\n",
+		  bus_address);
+	 =20
+	  printf ("setenv DBUS_SESSION_BUS_PID %ld\n",
+		  (long) bus_pid);
+	}
=20
       verbose ("dbus-launch exiting\n");
      =20
Index: tools/dbus-launch.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/tools/dbus-launch.1,v
retrieving revision 1.2
diff -u -d -r1.2 dbus-launch.1
--- tools/dbus-launch.1	4 May 2003 08:54:24 -0000	1.2
+++ tools/dbus-launch.1	16 May 2003 17:05:42 -0000
@@ -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] [\-c] [\-s] [\-\-exit-with-session]
=20
 .SH DESCRIPTION
=20
@@ -15,8 +15,13 @@
 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=3DVALUE format.
+\fIdbus-launch\fP.
+
+By default, \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.  You may override this default by
+specifying \-s\ for Bourne syntax, or \-c for csh syntax.
=20
 .PP
 See http://www.freedesktop.org/software/dbus/ for more information

--=-kKMqYOEtSTu7x559ITqE--