5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39 static GMainLoop *main_loop = NULL;
41 static void sig_term(int sig)
43 g_main_loop_quit(main_loop);
46 static void usage(void)
48 printf("Connection Manager version %s\n\n", VERSION);
51 "\tconnmand [-i <interface>] [options]\n"
55 "\t-c, --compat Enable Network Manager compatibility\n"
56 "\t-n, --nodaemon Don't fork daemon to background\n"
57 "\t-h, --help Display help\n"
61 static struct option options[] = {
62 { "interface", 1, 0, 'i' },
63 { "nodaemon", 0, 0, 'n' },
64 { "compat", 0, 0, 'c' },
65 { "debug", 0, 0, 'd' },
66 { "help", 0, 0, 'h' },
70 int main(int argc, char *argv[])
75 char interface[IFNAMSIZ];
76 int opt, detach = 1, compat = 0, debug = 0;
78 memset(interface, 0, IFNAMSIZ);
80 while ((opt = getopt_long(argc, argv, "+i:ncdh", options, NULL)) != EOF) {
83 snprintf(interface, IFNAMSIZ, "%s", optarg);
107 perror("Can't start daemon");
112 mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
113 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
115 mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
116 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
118 if (g_thread_supported() == FALSE)
121 main_loop = g_main_loop_new(NULL, FALSE);
123 if (dbus_threads_init_default() == FALSE) {
124 fprintf(stderr, "Can't init usage of threads\n");
128 dbus_error_init(&err);
130 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
132 if (dbus_error_is_set(&err) == TRUE) {
133 fprintf(stderr, "%s\n", err.message);
134 dbus_error_free(&err);
136 fprintf(stderr, "Can't register with system bus\n");
141 if (g_dbus_request_name(conn, NM_SERVICE, NULL) == FALSE) {
142 fprintf(stderr, "Can't register compat service\n");
147 __connman_log_init(detach, debug);
149 __connman_agent_init(conn);
151 __connman_manager_init(conn, compat);
153 __connman_plugin_init();
155 __connman_rtnl_init();
157 __connman_network_init(conn);
159 __connman_iface_init(conn, interface);
161 memset(&sa, 0, sizeof(sa));
162 sa.sa_handler = sig_term;
163 sigaction(SIGINT, &sa, NULL);
164 sigaction(SIGTERM, &sa, NULL);
166 g_main_loop_run(main_loop);
168 __connman_iface_cleanup();
170 __connman_network_cleanup();
172 __connman_rtnl_cleanup();
174 __connman_plugin_cleanup();
176 __connman_manager_cleanup();
178 __connman_agent_cleanup();
180 __connman_log_cleanup();
182 g_dbus_cleanup_connection(conn);
184 g_main_loop_unref(main_loop);