From ad8dcab6d0af2df372544599c1e000169ec86ec2 Mon Sep 17 00:00:00 2001 From: "taesub.kim" Date: Mon, 2 Dec 2013 10:33:07 +0900 Subject: [PATCH] Add support for systemd 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 --- CMakeLists.txt | 3 +- packaging/net-config.spec | 8 ++-- .../usr/lib/systemd/system/net-config.service | 4 +- src/main.c | 37 ++++++++++++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df45207..26b1b0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/packaging/net-config.spec b/packaging/net-config.spec index c0e82bd..c19d099 100644 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -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 diff --git a/resources/usr/lib/systemd/system/net-config.service b/resources/usr/lib/systemd/system/net-config.service index 5a564b6..63d2c1b 100644 --- a/resources/usr/lib/systemd/system/net-config.service +++ b/resources/usr/lib/systemd/system/net-config.service @@ -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 diff --git a/src/main.c b/src/main.c index f64b694..1f9fcfc 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,11 @@ * */ +#include +#include #include +#include +#include #include "log.h" #include "wifi.h" @@ -32,14 +36,40 @@ 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(); -- 2.34.1