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