5 * Copyright (C) 2007 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 [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 { "nodaemon", 0, 0, 'n' },
63 { "compat", 0, 0, 'c' },
64 { "help", 0, 0, 'h' },
68 int main(int argc, char *argv[])
73 int log_option = LOG_NDELAY | LOG_PID;
74 int opt, detach = 1, compat = 0;
76 while ((opt = getopt_long(argc, argv, "+nch", options, NULL)) != EOF) {
97 perror("Can't start daemon");
101 log_option |= LOG_PERROR;
103 openlog("connmand", log_option, LOG_DAEMON);
105 mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
106 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
108 mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
109 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
111 main_loop = g_main_loop_new(NULL, FALSE);
113 dbus_error_init(&err);
115 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
117 if (dbus_error_is_set(&err) == TRUE) {
118 fprintf(stderr, "%s\n", err.message);
119 dbus_error_free(&err);
121 fprintf(stderr, "Can't register with system bus\n");
126 if (g_dbus_request_name(conn, NM_SERVICE, NULL) == FALSE)
130 __connman_agent_init(conn);
132 __connman_manager_init(conn, compat);
134 __connman_plugin_init();
136 __connman_rtnl_init();
138 __connman_iface_init(conn);
140 memset(&sa, 0, sizeof(sa));
141 sa.sa_handler = sig_term;
142 sigaction(SIGINT, &sa, NULL);
143 sigaction(SIGTERM, &sa, NULL);
145 g_main_loop_run(main_loop);
147 __connman_iface_cleanup();
149 __connman_rtnl_cleanup();
151 __connman_plugin_cleanup();
153 __connman_manager_cleanup();
155 __connman_agent_cleanup();
157 g_dbus_cleanup_connection(conn);
159 g_main_loop_unref(main_loop);