Merge "[connman]: Fixed: ConnMan keep trying connection infintely" into tizen
[platform/upstream/connman.git] / src / main.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <signal.h>
32 #include <sys/signalfd.h>
33 #include <sys/types.h>
34 #include <sys/resource.h>
35 #include <getopt.h>
36 #include <sys/stat.h>
37 #include <net/if.h>
38 #include <netdb.h>
39
40 #include <gdbus.h>
41
42 #include "connman.h"
43
44 #define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
45 #define DEFAULT_BROWSER_LAUNCH_TIMEOUT (300 * 1000)
46
47 #define MAINFILE "main.conf"
48 #define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
49
50 static char *default_auto_connect[] = {
51         "wifi",
52         "ethernet",
53         "cellular",
54         NULL
55 };
56
57 static char *default_blacklist[] = {
58         "vmnet",
59         "vboxnet",
60         "virbr",
61         "ifb",
62         NULL
63 };
64
65 static struct {
66         bool bg_scan;
67         char **pref_timeservers;
68         unsigned int *auto_connect;
69         unsigned int *preferred_techs;
70         char **fallback_nameservers;
71         unsigned int timeout_inputreq;
72         unsigned int timeout_browserlaunch;
73         char **blacklisted_interfaces;
74         bool allow_hostname_updates;
75         bool single_tech;
76         char **tethering_technologies;
77         bool persistent_tethering_mode;
78         bool enable_6to4;
79 #if defined TIZEN_EXT
80         char **cellular_interfaces;
81         bool tizen_tv_extension;
82 #endif
83 } connman_settings  = {
84         .bg_scan = true,
85         .pref_timeservers = NULL,
86         .auto_connect = NULL,
87         .preferred_techs = NULL,
88         .fallback_nameservers = NULL,
89         .timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
90         .timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
91         .blacklisted_interfaces = NULL,
92         .allow_hostname_updates = true,
93         .single_tech = false,
94         .tethering_technologies = NULL,
95         .persistent_tethering_mode = false,
96         .enable_6to4 = false,
97 #if defined TIZEN_EXT
98         .cellular_interfaces = NULL,
99         .tizen_tv_extension = false,
100 #endif
101 };
102
103 #define CONF_BG_SCAN                    "BackgroundScanning"
104 #define CONF_PREF_TIMESERVERS           "FallbackTimeservers"
105 #define CONF_AUTO_CONNECT               "DefaultAutoConnectTechnologies"
106 #define CONF_PREFERRED_TECHS            "PreferredTechnologies"
107 #define CONF_FALLBACK_NAMESERVERS       "FallbackNameservers"
108 #define CONF_TIMEOUT_INPUTREQ           "InputRequestTimeout"
109 #define CONF_TIMEOUT_BROWSERLAUNCH      "BrowserLaunchTimeout"
110 #define CONF_BLACKLISTED_INTERFACES     "NetworkInterfaceBlacklist"
111 #define CONF_ALLOW_HOSTNAME_UPDATES     "AllowHostnameUpdates"
112 #define CONF_SINGLE_TECH                "SingleConnectedTechnology"
113 #define CONF_TETHERING_TECHNOLOGIES      "TetheringTechnologies"
114 #define CONF_PERSISTENT_TETHERING_MODE  "PersistentTetheringMode"
115 #define CONF_ENABLE_6TO4                "Enable6to4"
116 #if defined TIZEN_EXT
117 #define CONF_CELLULAR_INTERFACE         "NetworkCellularInterfaceList"
118 #define CONF_TIZEN_TV_EXT               "TizenTVExtension"
119 #endif
120
121 static const char *supported_options[] = {
122         CONF_BG_SCAN,
123         CONF_PREF_TIMESERVERS,
124         CONF_AUTO_CONNECT,
125         CONF_PREFERRED_TECHS,
126         CONF_FALLBACK_NAMESERVERS,
127         CONF_TIMEOUT_INPUTREQ,
128         CONF_TIMEOUT_BROWSERLAUNCH,
129         CONF_BLACKLISTED_INTERFACES,
130         CONF_ALLOW_HOSTNAME_UPDATES,
131         CONF_SINGLE_TECH,
132         CONF_TETHERING_TECHNOLOGIES,
133         CONF_PERSISTENT_TETHERING_MODE,
134         CONF_ENABLE_6TO4,
135 #if defined TIZEN_EXT
136         CONF_CELLULAR_INTERFACE,
137         CONF_TIZEN_TV_EXT,
138 #endif
139         NULL
140 };
141
142 static GKeyFile *load_config(const char *file)
143 {
144         GError *err = NULL;
145         GKeyFile *keyfile;
146
147         keyfile = g_key_file_new();
148
149         g_key_file_set_list_separator(keyfile, ',');
150
151         if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
152                 if (err->code != G_FILE_ERROR_NOENT) {
153                         connman_error("Parsing %s failed: %s", file,
154                                                                 err->message);
155                 }
156
157                 g_error_free(err);
158                 g_key_file_free(keyfile);
159                 return NULL;
160         }
161
162         return keyfile;
163 }
164
165 static uint *parse_service_types(char **str_list, gsize len)
166 {
167         unsigned int *type_list;
168         int i, j;
169         enum connman_service_type type;
170
171         type_list = g_try_new0(unsigned int, len + 1);
172         if (!type_list)
173                 return NULL;
174
175         i = 0;
176         j = 0;
177         while (str_list[i]) {
178                 type = __connman_service_string2type(str_list[i]);
179
180                 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
181                         type_list[j] = type;
182                         j += 1;
183                 }
184                 i += 1;
185         }
186
187         type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
188
189         return type_list;
190 }
191
192 static char **parse_fallback_nameservers(char **nameservers, gsize len)
193 {
194         char **servers;
195         int i, j;
196
197         servers = g_try_new0(char *, len + 1);
198         if (!servers)
199                 return NULL;
200
201         i = 0;
202         j = 0;
203         while (nameservers[i]) {
204                 if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
205                         servers[j] = g_strdup(nameservers[i]);
206                         j += 1;
207                 }
208                 i += 1;
209         }
210
211         return servers;
212 }
213
214 static void check_config(GKeyFile *config)
215 {
216         char **keys;
217         int j;
218
219         if (!config)
220                 return;
221
222         keys = g_key_file_get_groups(config, NULL);
223
224         for (j = 0; keys && keys[j]; j++) {
225                 if (g_strcmp0(keys[j], "General") != 0)
226                         connman_warn("Unknown group %s in %s",
227                                                 keys[j], MAINFILE);
228         }
229
230         g_strfreev(keys);
231
232         keys = g_key_file_get_keys(config, "General", NULL, NULL);
233
234         for (j = 0; keys && keys[j]; j++) {
235                 bool found;
236                 int i;
237
238                 found = false;
239                 for (i = 0; supported_options[i]; i++) {
240                         if (g_strcmp0(keys[j], supported_options[i]) == 0) {
241                                 found = true;
242                                 break;
243                         }
244                 }
245                 if (!found && !supported_options[i])
246                         connman_warn("Unknown option %s in %s",
247                                                 keys[j], MAINFILE);
248         }
249
250         g_strfreev(keys);
251 }
252
253 #if defined TIZEN_EXT
254 static void check_Tizen_configuration(GKeyFile *config)
255 {
256         GError *error = NULL;
257         char **cellular_interfaces;
258         bool boolean;
259         gsize len;
260
261         cellular_interfaces = g_key_file_get_string_list(config, "General",
262                         CONF_CELLULAR_INTERFACE, &len, &error);
263
264         if (error == NULL)
265                 connman_settings.cellular_interfaces = cellular_interfaces;
266
267         g_clear_error(&error);
268
269         boolean = __connman_config_get_bool(config, "General",
270                         CONF_TIZEN_TV_EXT, &error);
271         if (!error)
272                 connman_settings.tizen_tv_extension = boolean;
273
274         g_clear_error(&error);
275 }
276
277 static void set_nofile_inc(void)
278 {
279         int err;
280         struct rlimit rlim;
281
282         rlim.rlim_cur = 8192;
283         rlim.rlim_max = 8192;
284
285         err = setrlimit(RLIMIT_NOFILE, &rlim);
286         if (err)
287                 DBG("fail to increase FILENO err(%d)", err);
288
289         return;
290 }
291 #endif
292
293 static void parse_config(GKeyFile *config)
294 {
295         GError *error = NULL;
296         bool boolean;
297         char **timeservers;
298         char **interfaces;
299         char **str_list;
300         char **tethering;
301         gsize len;
302         int timeout;
303
304         if (!config) {
305                 connman_settings.auto_connect =
306                         parse_service_types(default_auto_connect, 3);
307                 connman_settings.blacklisted_interfaces =
308                         g_strdupv(default_blacklist);
309                 return;
310         }
311
312         DBG("parsing %s", MAINFILE);
313
314         boolean = g_key_file_get_boolean(config, "General",
315                                                 CONF_BG_SCAN, &error);
316         if (!error)
317                 connman_settings.bg_scan = boolean;
318
319         g_clear_error(&error);
320
321         timeservers = __connman_config_get_string_list(config, "General",
322                                         CONF_PREF_TIMESERVERS, NULL, &error);
323         if (!error)
324                 connman_settings.pref_timeservers = timeservers;
325
326         g_clear_error(&error);
327
328         str_list = __connman_config_get_string_list(config, "General",
329                         CONF_AUTO_CONNECT, &len, &error);
330
331         if (!error)
332                 connman_settings.auto_connect =
333                         parse_service_types(str_list, len);
334         else
335                 connman_settings.auto_connect =
336                         parse_service_types(default_auto_connect, 3);
337
338         g_strfreev(str_list);
339
340         g_clear_error(&error);
341
342         str_list = __connman_config_get_string_list(config, "General",
343                         CONF_PREFERRED_TECHS, &len, &error);
344
345         if (!error)
346                 connman_settings.preferred_techs =
347                         parse_service_types(str_list, len);
348
349         g_strfreev(str_list);
350
351         g_clear_error(&error);
352
353         str_list = __connman_config_get_string_list(config, "General",
354                         CONF_FALLBACK_NAMESERVERS, &len, &error);
355
356         if (!error)
357                 connman_settings.fallback_nameservers =
358                         parse_fallback_nameservers(str_list, len);
359
360         g_strfreev(str_list);
361
362         g_clear_error(&error);
363
364         timeout = g_key_file_get_integer(config, "General",
365                         CONF_TIMEOUT_INPUTREQ, &error);
366         if (!error && timeout >= 0)
367                 connman_settings.timeout_inputreq = timeout * 1000;
368
369         g_clear_error(&error);
370
371         timeout = g_key_file_get_integer(config, "General",
372                         CONF_TIMEOUT_BROWSERLAUNCH, &error);
373         if (!error && timeout >= 0)
374                 connman_settings.timeout_browserlaunch = timeout * 1000;
375
376         g_clear_error(&error);
377
378         interfaces = __connman_config_get_string_list(config, "General",
379                         CONF_BLACKLISTED_INTERFACES, &len, &error);
380
381         if (!error)
382                 connman_settings.blacklisted_interfaces = interfaces;
383         else
384                 connman_settings.blacklisted_interfaces =
385                         g_strdupv(default_blacklist);
386
387         g_clear_error(&error);
388
389         boolean = __connman_config_get_bool(config, "General",
390                                         CONF_ALLOW_HOSTNAME_UPDATES,
391                                         &error);
392         if (!error)
393                 connman_settings.allow_hostname_updates = boolean;
394
395         g_clear_error(&error);
396
397         boolean = __connman_config_get_bool(config, "General",
398                         CONF_SINGLE_TECH, &error);
399         if (!error)
400                 connman_settings.single_tech = boolean;
401
402         g_clear_error(&error);
403
404         tethering = __connman_config_get_string_list(config, "General",
405                         CONF_TETHERING_TECHNOLOGIES, &len, &error);
406
407         if (!error)
408                 connman_settings.tethering_technologies = tethering;
409
410         g_clear_error(&error);
411
412         boolean = __connman_config_get_bool(config, "General",
413                                         CONF_PERSISTENT_TETHERING_MODE,
414                                         &error);
415         if (!error)
416                 connman_settings.persistent_tethering_mode = boolean;
417
418         g_clear_error(&error);
419
420         boolean = __connman_config_get_bool(config, "General",
421                                         CONF_ENABLE_6TO4, &error);
422         if (!error)
423                 connman_settings.enable_6to4 = boolean;
424
425         g_clear_error(&error);
426
427 #if defined TIZEN_EXT
428         check_Tizen_configuration(config);
429 #endif
430 }
431
432 static int config_init(const char *file)
433 {
434         GKeyFile *config;
435
436 #if defined TIZEN_EXT
437         set_nofile_inc();
438 #endif
439         config = load_config(file);
440         check_config(config);
441         parse_config(config);
442         if (config)
443                 g_key_file_free(config);
444
445         return 0;
446 }
447
448 static GMainLoop *main_loop = NULL;
449
450 static unsigned int __terminated = 0;
451
452 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
453                                                         gpointer user_data)
454 {
455         struct signalfd_siginfo si;
456         ssize_t result;
457         int fd;
458
459         if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
460                 return FALSE;
461
462         fd = g_io_channel_unix_get_fd(channel);
463
464         result = read(fd, &si, sizeof(si));
465         if (result != sizeof(si))
466                 return FALSE;
467
468         switch (si.ssi_signo) {
469         case SIGINT:
470         case SIGTERM:
471                 if (__terminated == 0) {
472                         connman_info("Terminating");
473                         g_main_loop_quit(main_loop);
474                 }
475
476                 __terminated = 1;
477                 break;
478         }
479
480         return TRUE;
481 }
482
483 static guint setup_signalfd(void)
484 {
485         GIOChannel *channel;
486         guint source;
487         sigset_t mask;
488         int fd;
489
490         sigemptyset(&mask);
491         sigaddset(&mask, SIGINT);
492         sigaddset(&mask, SIGTERM);
493
494         if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
495                 perror("Failed to set signal mask");
496                 return 0;
497         }
498
499         fd = signalfd(-1, &mask, 0);
500         if (fd < 0) {
501                 perror("Failed to create signal descriptor");
502                 return 0;
503         }
504
505         channel = g_io_channel_unix_new(fd);
506
507         g_io_channel_set_close_on_unref(channel, TRUE);
508         g_io_channel_set_encoding(channel, NULL, NULL);
509         g_io_channel_set_buffered(channel, FALSE);
510
511         source = g_io_add_watch(channel,
512                                 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
513                                 signal_handler, NULL);
514
515         g_io_channel_unref(channel);
516
517         return source;
518 }
519
520 static void disconnect_callback(DBusConnection *conn, void *user_data)
521 {
522         connman_error("D-Bus disconnect");
523
524         g_main_loop_quit(main_loop);
525 }
526
527 static gchar *option_config = NULL;
528 static gchar *option_debug = NULL;
529 static gchar *option_device = NULL;
530 static gchar *option_plugin = NULL;
531 static gchar *option_nodevice = NULL;
532 static gchar *option_noplugin = NULL;
533 static gchar *option_wifi = NULL;
534 static gboolean option_detach = TRUE;
535 static gboolean option_dnsproxy = TRUE;
536 static gboolean option_backtrace = TRUE;
537 static gboolean option_version = FALSE;
538
539 static bool parse_debug(const char *key, const char *value,
540                                         gpointer user_data, GError **error)
541 {
542         if (value)
543                 option_debug = g_strdup(value);
544         else
545                 option_debug = g_strdup("*");
546
547         return true;
548 }
549
550 static GOptionEntry options[] = {
551         { "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
552                                 "Load the specified configuration file "
553                                 "instead of " CONFIGMAINFILE, "FILE" },
554         { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
555                                 G_OPTION_ARG_CALLBACK, parse_debug,
556                                 "Specify debug options to enable", "DEBUG" },
557         { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
558                         "Specify networking device or interface", "DEV" },
559         { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
560                         "Specify networking interface to ignore", "DEV" },
561         { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
562                                 "Specify plugins to load", "NAME,..." },
563         { "noplugin", 'P', 0, G_OPTION_ARG_STRING, &option_noplugin,
564                                 "Specify plugins not to load", "NAME,..." },
565         { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
566                                 "Specify driver for WiFi/Supplicant", "NAME" },
567         { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
568                                 G_OPTION_ARG_NONE, &option_detach,
569                                 "Don't fork daemon to background" },
570         { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
571                                 G_OPTION_ARG_NONE, &option_dnsproxy,
572                                 "Don't enable DNS Proxy" },
573         { "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
574                                 G_OPTION_ARG_NONE, &option_backtrace,
575                                 "Don't print out backtrace information" },
576         { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
577                                 "Show version information and exit" },
578         { NULL },
579 };
580
581 const char *connman_option_get_string(const char *key)
582 {
583         if (g_strcmp0(key, "wifi") == 0) {
584                 if (!option_wifi)
585                         return "nl80211,wext";
586                 else
587                         return option_wifi;
588         }
589
590         return NULL;
591 }
592
593 bool connman_setting_get_bool(const char *key)
594 {
595         if (g_str_equal(key, CONF_BG_SCAN))
596                 return connman_settings.bg_scan;
597
598         if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
599                 return connman_settings.allow_hostname_updates;
600
601         if (g_str_equal(key, CONF_SINGLE_TECH))
602                 return connman_settings.single_tech;
603
604         if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
605                 return connman_settings.persistent_tethering_mode;
606
607         if (g_str_equal(key, CONF_ENABLE_6TO4))
608                 return connman_settings.enable_6to4;
609
610         return false;
611 }
612
613 char **connman_setting_get_string_list(const char *key)
614 {
615         if (g_str_equal(key, CONF_PREF_TIMESERVERS))
616                 return connman_settings.pref_timeservers;
617
618         if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
619                 return connman_settings.fallback_nameservers;
620
621         if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
622                 return connman_settings.blacklisted_interfaces;
623
624         if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
625                 return connman_settings.tethering_technologies;
626
627 #if defined TIZEN_EXT
628         if (g_str_equal(key, CONF_CELLULAR_INTERFACE))
629                 return connman_settings.cellular_interfaces;
630 #endif
631
632         return NULL;
633 }
634
635 unsigned int *connman_setting_get_uint_list(const char *key)
636 {
637         if (g_str_equal(key, CONF_AUTO_CONNECT))
638                 return connman_settings.auto_connect;
639
640         if (g_str_equal(key, CONF_PREFERRED_TECHS))
641                 return connman_settings.preferred_techs;
642
643         return NULL;
644 }
645
646 unsigned int connman_timeout_input_request(void)
647 {
648         return connman_settings.timeout_inputreq;
649 }
650
651 unsigned int connman_timeout_browser_launch(void)
652 {
653         return connman_settings.timeout_browserlaunch;
654 }
655
656 int main(int argc, char *argv[])
657 {
658         GOptionContext *context;
659         GError *error = NULL;
660         DBusConnection *conn;
661         DBusError err;
662         guint signal;
663
664         context = g_option_context_new(NULL);
665         g_option_context_add_main_entries(context, options, NULL);
666
667         if (!g_option_context_parse(context, &argc, &argv, &error)) {
668                 if (error) {
669                         g_printerr("%s\n", error->message);
670                         g_error_free(error);
671                 } else
672                         g_printerr("An unknown error occurred\n");
673                 exit(1);
674         }
675
676         g_option_context_free(context);
677
678         if (option_version) {
679                 printf("%s\n", VERSION);
680                 exit(0);
681         }
682
683         if (option_detach) {
684                 if (daemon(0, 0)) {
685                         perror("Can't start daemon");
686                         exit(1);
687                 }
688         }
689
690         if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
691                                 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
692                 if (errno != EEXIST)
693                         perror("Failed to create storage directory");
694         }
695
696         umask(0077);
697
698         main_loop = g_main_loop_new(NULL, FALSE);
699
700         signal = setup_signalfd();
701
702         dbus_error_init(&err);
703
704         conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
705         if (!conn) {
706                 if (dbus_error_is_set(&err)) {
707                         fprintf(stderr, "%s\n", err.message);
708                         dbus_error_free(&err);
709                 } else
710                         fprintf(stderr, "Can't register with system bus\n");
711                 exit(1);
712         }
713
714         g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
715
716         __connman_log_init(argv[0], option_debug, option_detach,
717                         option_backtrace, "Connection Manager", VERSION);
718
719         __connman_dbus_init(conn);
720
721         if (!option_config)
722                 config_init(CONFIGMAINFILE);
723         else
724                 config_init(option_config);
725
726         __connman_util_init();
727         __connman_inotify_init();
728         __connman_technology_init();
729         __connman_notifier_init();
730         __connman_agent_init();
731         __connman_service_init();
732         __connman_peer_service_init();
733         __connman_peer_init();
734         __connman_provider_init();
735         __connman_network_init();
736         __connman_config_init();
737         __connman_device_init(option_device, option_nodevice);
738
739         __connman_ippool_init();
740         __connman_iptables_init();
741         __connman_firewall_init();
742         __connman_nat_init();
743         __connman_tethering_init();
744         __connman_counter_init();
745         __connman_manager_init();
746         __connman_stats_init();
747         __connman_clock_init();
748
749         __connman_resolver_init(option_dnsproxy);
750         __connman_ipconfig_init();
751         __connman_rtnl_init();
752         __connman_task_init();
753         __connman_proxy_init();
754         __connman_detect_init();
755         __connman_session_init();
756         __connman_timeserver_init();
757         __connman_connection_init();
758
759         __connman_plugin_init(option_plugin, option_noplugin);
760
761         __connman_rtnl_start();
762         __connman_dhcp_init();
763         __connman_dhcpv6_init();
764         __connman_wpad_init();
765         __connman_wispr_init();
766 #if !defined TIZEN_EXT
767         __connman_rfkill_init();
768 #endif
769         __connman_machine_init();
770
771         g_free(option_config);
772         g_free(option_device);
773         g_free(option_plugin);
774         g_free(option_nodevice);
775         g_free(option_noplugin);
776
777         g_main_loop_run(main_loop);
778
779         g_source_remove(signal);
780
781         __connman_machine_cleanup();
782 #if !defined TIZEN_EXT
783         __connman_rfkill_cleanup();
784 #endif
785         __connman_wispr_cleanup();
786         __connman_wpad_cleanup();
787         __connman_dhcpv6_cleanup();
788         __connman_session_cleanup();
789         __connman_plugin_cleanup();
790         __connman_provider_cleanup();
791         __connman_connection_cleanup();
792         __connman_timeserver_cleanup();
793         __connman_detect_cleanup();
794         __connman_proxy_cleanup();
795         __connman_task_cleanup();
796         __connman_rtnl_cleanup();
797         __connman_resolver_cleanup();
798
799         __connman_clock_cleanup();
800         __connman_stats_cleanup();
801         __connman_config_cleanup();
802         __connman_manager_cleanup();
803         __connman_counter_cleanup();
804         __connman_tethering_cleanup();
805         __connman_nat_cleanup();
806         __connman_firewall_cleanup();
807         __connman_iptables_cleanup();
808         __connman_peer_service_cleanup();
809         __connman_peer_cleanup();
810         __connman_ippool_cleanup();
811         __connman_device_cleanup();
812         __connman_network_cleanup();
813         __connman_dhcp_cleanup();
814         __connman_service_cleanup();
815         __connman_agent_cleanup();
816         __connman_ipconfig_cleanup();
817         __connman_notifier_cleanup();
818         __connman_technology_cleanup();
819         __connman_inotify_cleanup();
820
821         __connman_util_cleanup();
822         __connman_dbus_cleanup();
823
824         __connman_log_cleanup(option_backtrace);
825
826         dbus_connection_unref(conn);
827
828         g_main_loop_unref(main_loop);
829
830         if (connman_settings.pref_timeservers)
831                 g_strfreev(connman_settings.pref_timeservers);
832
833         g_free(connman_settings.auto_connect);
834         g_free(connman_settings.preferred_techs);
835         g_strfreev(connman_settings.fallback_nameservers);
836         g_strfreev(connman_settings.blacklisted_interfaces);
837         g_strfreev(connman_settings.tethering_technologies);
838
839         g_free(option_debug);
840         g_free(option_wifi);
841
842         return 0;
843 }