mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-26 00:30:09 +01:00
2003-03-31 Havoc Pennington <hp@redhat.com>
* bus/main.c (main): fix up the command line arguments to be nicer
This commit is contained in:
parent
e6809d1a69
commit
7af5933433
4 changed files with 118 additions and 16 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
|
||||
INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS) \
|
||||
-DDAEMON_NAME=\"dbus-daemon-1\" -DDBUS_COMPILATION
|
||||
|
||||
EFENCE=
|
||||
|
||||
configdir=$(sysconfdir)/dbus-1
|
||||
|
||||
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"\"
|
||||
|
||||
EFENCE=
|
||||
|
||||
config_DATA= \
|
||||
system.conf \
|
||||
session.conf
|
||||
|
|
|
|||
112
bus/main.c
112
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;
|
||||
}
|
||||
|
|
|
|||
6
doc/TODO
6
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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue