]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2003-03-31 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Mon, 31 Mar 2003 18:58:14 +0000 (18:58 +0000)
committerHavoc Pennington <hp@redhat.com>
Mon, 31 Mar 2003 18:58:14 +0000 (18:58 +0000)
* bus/main.c (main): fix up the command line arguments to be nicer

ChangeLog
bus/Makefile.am
bus/main.c
doc/TODO

index d977b6b1551f1d1924757c5209a9c64916c0bc91..7b6d6fc0a4de4f7334125b15ea4db1a53d339257 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2003-03-31  Havoc Pennington  <hp@redhat.com>
+
+       * bus/main.c (main): fix up the command line arguments to be nicer
+
 2003-03-31  Havoc Pennington  <hp@redhat.com>
 
        * dbus/Makefile.am (INCLUDES): use EXPANDED_LOCALSTATEDIR to
index ece0aa558d5114abfbfe29f89e98ad039f6ed256..7eca57eac2ba2f64ca50d23c916691d01c1b2ea1 100644 (file)
@@ -1,10 +1,12 @@
 
-INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS) \
-       -DDAEMON_NAME=\"dbus-daemon-1\"  -DDBUS_COMPILATION
+configdir=$(sysconfdir)/dbus-1
 
-EFENCE=
+INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS)                            \
+       -DDAEMON_NAME=\"dbus-daemon-1\"  -DDBUS_COMPILATION             \
+       -DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\"        \
+       -DDBUS_SESSION_CONFIG_FILE=\""$(configdir)/session.conf"\"
 
-configdir=$(sysconfdir)/dbus-1
+EFENCE=
 
 config_DATA=                                   \
        system.conf                             \
index 905e4ba09f7af87e319591f9f78b4515c87a8eab..ae625489e98a5a3b4cc9d22155a736a24952f451 100644 (file)
 #include "bus.h"
 #include "loop.h"
 #include <dbus/dbus-internals.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+usage (void)
+{
+  fprintf (stderr, "dbus-daemon-1 [--session] [--system] [--config-file=FILE] [--version]\n");
+  exit (1);
+}
+
+static void
+version (void)
+{
+  printf ("D-BUS Message Bus Daemon %s\n"
+          "Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others\n"
+          "This is free software; see the source for copying conditions.\n"
+          "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+          VERSION);
+  exit (0);
+}
+
+static void
+check_two_config_files (const DBusString *config_file,
+                        const char       *extra_arg)
+{
+  if (_dbus_string_get_length (config_file) > 0)
+    {
+      const char *s;
+      _dbus_string_get_const_data (config_file, &s);
+      fprintf (stderr, "--%s specified but configuration file %s already requested\n",
+               extra_arg, s);
+      exit (1);
+    }
+}
 
 int
 main (int argc, char **argv)
@@ -30,22 +65,77 @@ main (int argc, char **argv)
   BusContext *context;
   DBusError error;
   DBusString config_file;
+  const char *prev_arg;
+  int i;
 
-  /* FIXME I think the arguments should be like:
-   * --system    use standard system config file
-   * --session   use standard session config file
-   * --config-file=foo.conf  use some other file
-   */
+  if (!_dbus_string_init (&config_file, _DBUS_INT_MAX))
+    return 1;
   
-  if (argc != 2)
+  prev_arg = NULL;
+  i = 1;
+  while (i < argc)
     {
-      _dbus_warn ("The message bus configuration file must be given as the only argument\n");
-      return 1;
+      const char *arg = argv[i];
+      
+      if (strcmp (arg, "--help") == 0 ||
+          strcmp (arg, "-h") == 0 ||
+          strcmp (arg, "-?") == 0)
+        usage ();
+      else if (strcmp (arg, "--version") == 0)
+        version ();
+      else if (strcmp (arg, "--system") == 0)
+        {
+          check_two_config_files (&config_file, "system");
+
+          if (!_dbus_string_append (&config_file, DBUS_SYSTEM_CONFIG_FILE))
+            exit (1);
+        }
+      else if (strcmp (arg, "--session") == 0)
+        {
+          check_two_config_files (&config_file, "session");
+
+          if (!_dbus_string_append (&config_file, DBUS_SESSION_CONFIG_FILE))
+            exit (1);
+        }
+      else if (strstr (arg, "--config-file=") == arg)
+        {
+          const char *file;
+
+          check_two_config_files (&config_file, "config-file");
+          
+          file = strchr (arg, '=');
+          ++file;
+
+          if (!_dbus_string_append (&config_file, file))
+            exit (1);
+        }
+      else if (prev_arg &&
+               strcmp (prev_arg, "--config-file") == 0)
+        {
+          check_two_config_files (&config_file, "config-file");
+          
+          if (!_dbus_string_append (&config_file, arg))
+            exit (1);
+        }
+      else if (strcmp (arg, "--config-file") == 0)
+        ; /* wait for next arg */
+      else
+        usage ();
+      
+      prev_arg = arg;
+      
+      ++i;
+    }
+
+  if (_dbus_string_get_length (&config_file) == 0)
+    {
+      fprintf (stderr, "No configuration file specified.\n");
+      usage ();
     }
   
   dbus_error_init (&error);
-  _dbus_string_init_const (&config_file, argv[1]);
   context = bus_context_new (&config_file, &error);
+  _dbus_string_free (&config_file);
   if (context == NULL)
     {
       _dbus_warn ("Failed to start message bus: %s\n",
@@ -53,12 +143,12 @@ main (int argc, char **argv)
       dbus_error_free (&error);
       return 1;
     }
-
+  
   _dbus_verbose ("We are on D-Bus...\n");
   bus_loop_run ();
   
   bus_context_shutdown (context);
   bus_context_unref (context);
+  
   return 0;
 }
index ae07add85d94b222fefc554d7c875e326bcfb74e..ebbff3acad8fff4d333c444b9c6bcdacd7722fee 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
    idea. The definitiion of "valid" is slightly fuzzy. I think it might 
    be better to just silently "fix" the UTF-8, or perhaps return an error.
 
+   Owen says we should only validate the UTF-8 on dbus_message_get_string()
+   (changing get_string to have an error return, and allowing a type error 
+   as a possible return)
+
  - We might consider returning a "no such operation" error in dbus-connection.c 
    for unhandled messages.
 
+ - Abstract the user database, so you can use something other than the system password 
+   database.