Add support for systemd 48/13248/3
authortaesub.kim <taesub.kim@samsung.com>
Mon, 2 Dec 2013 01:33:07 +0000 (10:33 +0900)
committertaesub.kim <taesub.kim@samsung.com>
Mon, 30 Dec 2013 04:06:05 +0000 (13:06 +0900)
The Following changes have been implemented:
  1. --nofork - a new call parameter has been added to disable start service as clasic unix daemon
  2. sending notyfication to systemd by calling sd_notify()

Change-Id: I4f66775880e4f5c047c7b07d1a6590af23fb573b
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
CMakeLists.txt
packaging/net-config.spec
resources/usr/lib/systemd/system/net-config.service
src/main.c

index df45207..26b1b0b 100644 (file)
@@ -42,7 +42,8 @@ PKG_CHECK_MODULES(pkgs REQUIRED
        vconf
        wifi-direct
        tapi
-       syspopup-caller)
+       syspopup-caller
+       libsystemd-daemon)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index c0e82bd..c19d099 100644 (file)
@@ -1,6 +1,6 @@
 Name:       net-config
 Summary:    TIZEN Network Configuration Module
-Version:    0.1.90_26
+Version:    0.1.90_27
 Release:    1
 Group:      System/Network
 License:    Apache License Version 2.0
@@ -16,10 +16,8 @@ BuildRequires:  pkgconfig(wifi-direct)
 BuildRequires:  pkgconfig(tapi)
 BuildRequires:  pkgconfig(syspopup-caller)
 Requires(post): /usr/bin/vconftool
-Requires:         systemd
-Requires(post):   systemd
-Requires(preun):  systemd
-Requires(postun): systemd
+BuildRequires:    pkgconfig(libsystemd-daemon)
+%{?systemd_requires}
 
 %description
 TIZEN Network Configuration Module
index 5a564b6..63d2c1b 100644 (file)
@@ -3,8 +3,8 @@ Description=net config service
 After=syslog.target
 
 [Service]
-Type=forking
-ExecStart=/usr/sbin/net-config
+Type=notify
+ExecStart=/usr/sbin/net-config --nofork
 
 [Install]
 WantedBy=multi-user.target
index f64b694..1f9fcfc 100644 (file)
  *
  */
 
+#include <systemd/sd-daemon.h>
+#include <getopt.h>
 #include <unistd.h>
+#include <signal.h>
+#include <errno.h>
 
 #include "log.h"
 #include "wifi.h"
 
 static GMainLoop *main_loop = NULL;
 
+static int no_fork = FALSE;
+
+int netconfig_test_input_parameters(int argc, char* argv[])
+{
+        struct option tab[] = {
+                { "nofork", no_argument, 0, 0 },
+                { NULL, 0, NULL, 0 }
+        };
+        int idx = 0;
+
+        while (getopt_long(argc, argv, "", tab, &idx) >= 0) {
+
+               if (idx == 0)
+                       no_fork = TRUE;
+               idx = 0;
+       }
+       return 0;
+}
+
 int main(int argc, char* argv[])
 {
        DBusGConnection *connection;
 
        DBG("Network Configuration Module");
 
-       if (daemon(0, 0) != 0)
-               DBG("Cannot start daemon");
+       /*
+        * Call parameters veryfication
+        */
+       netconfig_test_input_parameters(argc, argv);
+
+       if (!no_fork) {
+               if (daemon(0, 0) != 0)
+                       DBG("Cannot start daemon");
+       }
 
        netconfig_set_wifi_mac_address();
 
@@ -68,6 +98,9 @@ int main(int argc, char* argv[])
        /* If its environment uses Emulator, network configuration is set by emulator default */
        netconfig_emulator_test_and_start();
 
+       // Notyfication to systemd
+       sd_notify(0, "READY=1");
+
        g_main_loop_run(main_loop);
 
        netconfig_deregister_signal();