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)
54 fprintf (stderr, "--%s specified but configuration file %s already requested\n",
55 extra_arg, _dbus_string_get_const_data (config_file));
61 main (int argc, char **argv)
65 DBusString config_file;
69 if (!_dbus_string_init (&config_file))
76 const char *arg = argv[i];
78 if (strcmp (arg, "--help") == 0 ||
79 strcmp (arg, "-h") == 0 ||
80 strcmp (arg, "-?") == 0)
82 else if (strcmp (arg, "--version") == 0)
84 else if (strcmp (arg, "--system") == 0)
86 check_two_config_files (&config_file, "system");
88 if (!_dbus_string_append (&config_file, DBUS_SYSTEM_CONFIG_FILE))
91 else if (strcmp (arg, "--session") == 0)
93 check_two_config_files (&config_file, "session");
95 if (!_dbus_string_append (&config_file, DBUS_SESSION_CONFIG_FILE))
98 else if (strstr (arg, "--config-file=") == arg)
102 check_two_config_files (&config_file, "config-file");
104 file = strchr (arg, '=');
107 if (!_dbus_string_append (&config_file, file))
111 strcmp (prev_arg, "--config-file") == 0)
113 check_two_config_files (&config_file, "config-file");
115 if (!_dbus_string_append (&config_file, arg))
118 else if (strcmp (arg, "--config-file") == 0)
119 ; /* wait for next arg */
128 if (_dbus_string_get_length (&config_file) == 0)
130 fprintf (stderr, "No configuration file specified.\n");
134 dbus_error_init (&error);
135 context = bus_context_new (&config_file, &error);
136 _dbus_string_free (&config_file);
139 _dbus_warn ("Failed to start message bus: %s\n",
141 dbus_error_free (&error);
145 _dbus_verbose ("We are on D-Bus...\n");
148 bus_context_shutdown (context);
149 bus_context_unref (context);