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