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[])
72 int log_option = LOG_NDELAY | LOG_PID;
73 int opt, detach = 1, compat = 0;
75 while ((opt = getopt_long(argc, argv, "+nch", options, NULL)) != EOF) {
96 perror("Can't start daemon");
100 log_option |= LOG_PERROR;
102 openlog("connmand", log_option, LOG_DAEMON);
104 mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
105 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
107 mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
108 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
110 main_loop = g_main_loop_new(NULL, FALSE);
112 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE);
114 fprintf(stderr, "Can't register with system bus\n");
119 if (g_dbus_request_name(conn, NM_SERVICE) == FALSE)
123 __connman_agent_init();
125 __connman_manager_init(conn, compat);
127 __connman_plugin_init();
129 __connman_rtnl_init();
131 __connman_iface_init(conn);
133 memset(&sa, 0, sizeof(sa));
134 sa.sa_handler = sig_term;
135 sigaction(SIGINT, &sa, NULL);
136 sigaction(SIGTERM, &sa, NULL);
138 g_main_loop_run(main_loop);
140 __connman_iface_cleanup();
142 __connman_rtnl_cleanup();
144 __connman_plugin_cleanup();
146 __connman_manager_cleanup();
148 __connman_agent_cleanup();
150 g_dbus_cleanup_connection(conn);
152 g_main_loop_unref(main_loop);