1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* main.c main() for message bus
4 * Copyright (C) 2003 Red Hat, Inc.
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <dbus/dbus-internals.h>
33 fprintf (stderr, "dbus-daemon-1 [--session] [--system] [--config-file=FILE] [--version]\n");
40 printf ("D-BUS Message Bus Daemon %s\n"
41 "Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others\n"
42 "This is free software; see the source for copying conditions.\n"
43 "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
49 check_two_config_files (const DBusString *config_file,
50 const char *extra_arg)
52 if (_dbus_string_get_length (config_file) > 0)
55 _dbus_string_get_const_data (config_file, &s);
56 fprintf (stderr, "--%s specified but configuration file %s already requested\n",
63 main (int argc, char **argv)
67 DBusString config_file;
71 if (!_dbus_string_init (&config_file, _DBUS_INT_MAX))
78 const char *arg = argv[i];
80 if (strcmp (arg, "--help") == 0 ||
81 strcmp (arg, "-h") == 0 ||
82 strcmp (arg, "-?") == 0)
84 else if (strcmp (arg, "--version") == 0)
86 else if (strcmp (arg, "--system") == 0)
88 check_two_config_files (&config_file, "system");
90 if (!_dbus_string_append (&config_file, DBUS_SYSTEM_CONFIG_FILE))
93 else if (strcmp (arg, "--session") == 0)
95 check_two_config_files (&config_file, "session");
97 if (!_dbus_string_append (&config_file, DBUS_SESSION_CONFIG_FILE))
100 else if (strstr (arg, "--config-file=") == arg)
104 check_two_config_files (&config_file, "config-file");
106 file = strchr (arg, '=');
109 if (!_dbus_string_append (&config_file, file))
113 strcmp (prev_arg, "--config-file") == 0)
115 check_two_config_files (&config_file, "config-file");
117 if (!_dbus_string_append (&config_file, arg))
120 else if (strcmp (arg, "--config-file") == 0)
121 ; /* wait for next arg */
130 if (_dbus_string_get_length (&config_file) == 0)
132 fprintf (stderr, "No configuration file specified.\n");
136 dbus_error_init (&error);
137 context = bus_context_new (&config_file, &error);
138 _dbus_string_free (&config_file);
141 _dbus_warn ("Failed to start message bus: %s\n",
143 dbus_error_free (&error);
147 _dbus_verbose ("We are on D-Bus...\n");
150 bus_context_shutdown (context);
151 bus_context_unref (context);