Add logging infrastructure
[connman] / src / main.c
index a54eaf6..a4962b2 100644 (file)
@@ -27,7 +27,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include <syslog.h>
 #include <signal.h>
 #include <getopt.h>
 #include <sys/stat.h>
@@ -61,6 +60,7 @@ static void usage(void)
 static struct option options[] = {
        { "nodaemon", 0, 0, 'n' },
        { "compat",   0, 0, 'c' },
+       { "debug",    0, 0, 'd' },
        { "help",     0, 0, 'h' },
        { }
 };
@@ -68,18 +68,21 @@ static struct option options[] = {
 int main(int argc, char *argv[])
 {
        DBusConnection *conn;
+       DBusError err;
        struct sigaction sa;
-       int log_option = LOG_NDELAY | LOG_PID;
-       int opt, detach = 1, compat = 0;
+       int opt, detach = 1, compat = 0, debug = 0;
 
-       while ((opt = getopt_long(argc, argv, "+nch", options, NULL)) != EOF) {
-               switch(opt) {
+       while ((opt = getopt_long(argc, argv, "+ncdh", options, NULL)) != EOF) {
+               switch (opt) {
                case 'n':
                        detach = 0;
                        break;
                case 'c':
                        compat = 1;
                        break;
+               case 'd':
+                       debug = 1;
+                       break;
                case 'h':
                default:
                        usage();
@@ -96,10 +99,7 @@ int main(int argc, char *argv[])
                        perror("Can't start daemon");
                        exit(1);
                }
-       } else
-               log_option |= LOG_PERROR;
-
-       openlog("connmand", log_option, LOG_DAEMON);
+       }
 
        mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
                        S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
@@ -109,17 +109,25 @@ int main(int argc, char *argv[])
 
        main_loop = g_main_loop_new(NULL, FALSE);
 
-       conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE);
+       dbus_error_init(&err);
+
+       conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
        if (conn == NULL) {
-               fprintf(stderr, "Can't register with system bus\n");
+               if (dbus_error_is_set(&err) == TRUE) {
+                       fprintf(stderr, "%s\n", err.message);
+                       dbus_error_free(&err);
+               } else
+                       fprintf(stderr, "Can't register with system bus\n");
                exit(1);
        }
 
        if (compat) {
-               if (g_dbus_request_name(conn, NM_SERVICE) == FALSE)
+               if (g_dbus_request_name(conn, NM_SERVICE, NULL) == FALSE)
                        compat = 0;
        }
 
+       __connman_log_init(detach, debug);
+
        __connman_agent_init(conn);
 
        __connman_manager_init(conn, compat);
@@ -147,6 +155,8 @@ int main(int argc, char *argv[])
 
        __connman_agent_cleanup();
 
+       __connman_log_cleanup();
+
        g_dbus_cleanup_connection(conn);
 
        g_main_loop_unref(main_loop);
@@ -155,7 +165,5 @@ int main(int argc, char *argv[])
 
        rmdir(STATEDIR);
 
-       closelog();
-
        return 0;
 }