summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--bus/Makefile.am10
-rw-r--r--bus/main.c112
-rw-r--r--doc/TODO6
4 files changed, 117 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index d977b6b1..7b6d6fc0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
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
define DBUS_SYSTEM_BUS_PATH as we want to compile in the same
final location that lands in the config file
diff --git a/bus/Makefile.am b/bus/Makefile.am
index ece0aa55..7eca57ea 100644
--- a/bus/Makefile.am
+++ b/bus/Makefile.am
@@ -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 \
diff --git a/bus/main.c b/bus/main.c
index 905e4ba0..ae625489 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -23,6 +23,41 @@
#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;
}
diff --git a/doc/TODO b/doc/TODO
index ae07add8..ebbff3ac 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -39,6 +39,12 @@
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.