Commit 7af59334 authored by Havoc Pennington's avatar Havoc Pennington

2003-03-31 Havoc Pennington <hp@redhat.com>

	* bus/main.c (main): fix up the command line arguments to be nicer
parent e6809d1a
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> 2003-03-31 Havoc Pennington <hp@redhat.com>
* dbus/Makefile.am (INCLUDES): use EXPANDED_LOCALSTATEDIR to * dbus/Makefile.am (INCLUDES): use EXPANDED_LOCALSTATEDIR to
......
INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS) \ configdir=$(sysconfdir)/dbus-1
-DDAEMON_NAME=\"dbus-daemon-1\" -DDBUS_COMPILATION
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= \ config_DATA= \
system.conf \ system.conf \
......
...@@ -23,6 +23,41 @@ ...@@ -23,6 +23,41 @@
#include "bus.h" #include "bus.h"
#include "loop.h" #include "loop.h"
#include <dbus/dbus-internals.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 int
main (int argc, char **argv) main (int argc, char **argv)
...@@ -30,22 +65,77 @@ main (int argc, char **argv) ...@@ -30,22 +65,77 @@ main (int argc, char **argv)
BusContext *context; BusContext *context;
DBusError error; DBusError error;
DBusString config_file; DBusString config_file;
const char *prev_arg;
int i;
/* FIXME I think the arguments should be like: if (!_dbus_string_init (&config_file, _DBUS_INT_MAX))
* --system use standard system config file return 1;
* --session use standard session config file
* --config-file=foo.conf use some other file
*/
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"); const char *arg = argv[i];
return 1;
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_error_init (&error);
_dbus_string_init_const (&config_file, argv[1]);
context = bus_context_new (&config_file, &error); context = bus_context_new (&config_file, &error);
_dbus_string_free (&config_file);
if (context == NULL) if (context == NULL)
{ {
_dbus_warn ("Failed to start message bus: %s\n", _dbus_warn ("Failed to start message bus: %s\n",
...@@ -53,12 +143,12 @@ main (int argc, char **argv) ...@@ -53,12 +143,12 @@ main (int argc, char **argv)
dbus_error_free (&error); dbus_error_free (&error);
return 1; return 1;
} }
_dbus_verbose ("We are on D-Bus...\n"); _dbus_verbose ("We are on D-Bus...\n");
bus_loop_run (); bus_loop_run ();
bus_context_shutdown (context); bus_context_shutdown (context);
bus_context_unref (context); bus_context_unref (context);
return 0; return 0;
} }
...@@ -39,6 +39,12 @@ ...@@ -39,6 +39,12 @@
idea. The definitiion of "valid" is slightly fuzzy. I think it might 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. 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 - We might consider returning a "no such operation" error in dbus-connection.c
for unhandled messages. for unhandled messages.
- Abstract the user database, so you can use something other than the system password
database.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment