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