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 main_loop = g_main_loop_new(NULL, FALSE);
120 dbus_error_init(&err);
122 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
124 if (dbus_error_is_set(&err) == TRUE) {
125 fprintf(stderr, "%s\n", err.message);
126 dbus_error_free(&err);
128 fprintf(stderr, "Can't register with system bus\n");
133 if (g_dbus_request_name(conn, NM_SERVICE, NULL) == FALSE) {
134 fprintf(stderr, "Can't register compat service\n");
139 __connman_log_init(detach, debug);
141 __connman_agent_init(conn);
143 __connman_manager_init(conn, compat);
145 __connman_plugin_init();
147 __connman_rtnl_init();
149 __connman_network_init(conn);
151 __connman_iface_init(conn, interface);
153 memset(&sa, 0, sizeof(sa));
154 sa.sa_handler = sig_term;
155 sigaction(SIGINT, &sa, NULL);
156 sigaction(SIGTERM, &sa, NULL);
158 g_main_loop_run(main_loop);
160 __connman_iface_cleanup();
162 __connman_network_cleanup();
164 __connman_rtnl_cleanup();
166 __connman_plugin_cleanup();
168 __connman_manager_cleanup();
170 __connman_agent_cleanup();
172 __connman_log_cleanup();
174 g_dbus_cleanup_connection(conn);
176 g_main_loop_unref(main_loop);