2003-01-04 20:29:46 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* main.c main() for message bus
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 1.2
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
2003-03-13 03:52:58 +00:00
|
|
|
#include "bus.h"
|
2003-01-04 20:29:46 +00:00
|
|
|
#include "loop.h"
|
2003-03-13 03:52:58 +00:00
|
|
|
#include <dbus/dbus-internals.h>
|
2003-03-31 18:58:14 +00:00
|
|
|
#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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-11-21 16:41:33 +00:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
2003-03-13 03:52:58 +00:00
|
|
|
BusContext *context;
|
|
|
|
|
DBusError error;
|
2003-03-31 08:19:50 +00:00
|
|
|
DBusString config_file;
|
2003-03-31 18:58:14 +00:00
|
|
|
const char *prev_arg;
|
|
|
|
|
int i;
|
2003-03-31 08:19:50 +00:00
|
|
|
|
2003-03-31 18:58:14 +00:00
|
|
|
if (!_dbus_string_init (&config_file, _DBUS_INT_MAX))
|
|
|
|
|
return 1;
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-03-31 18:58:14 +00:00
|
|
|
prev_arg = NULL;
|
|
|
|
|
i = 1;
|
|
|
|
|
while (i < argc)
|
2003-01-04 20:29:46 +00:00
|
|
|
{
|
2003-03-31 18:58:14 +00:00
|
|
|
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 ();
|
2003-01-04 20:29:46 +00:00
|
|
|
}
|
2003-02-17 09:59:23 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
dbus_error_init (&error);
|
2003-03-31 08:19:50 +00:00
|
|
|
context = bus_context_new (&config_file, &error);
|
2003-03-31 18:58:14 +00:00
|
|
|
_dbus_string_free (&config_file);
|
2003-03-13 03:52:58 +00:00
|
|
|
if (context == NULL)
|
2003-02-17 09:59:23 +00:00
|
|
|
{
|
2003-03-13 03:52:58 +00:00
|
|
|
_dbus_warn ("Failed to start message bus: %s\n",
|
|
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
2003-02-17 09:59:23 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2003-03-31 18:58:14 +00:00
|
|
|
|
2003-01-14 11:19:06 +00:00
|
|
|
_dbus_verbose ("We are on D-Bus...\n");
|
2003-01-04 20:29:46 +00:00
|
|
|
bus_loop_run ();
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
bus_context_shutdown (context);
|
|
|
|
|
bus_context_unref (context);
|
2003-03-31 18:58:14 +00:00
|
|
|
|
2002-11-21 16:41:33 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|