Call sd_notify(0, "STOPPING=1") when exiting 28/250228/1 submit/tizen/20210105.091325
authorINSUN PYO <insun.pyo@samsung.com>
Tue, 22 Dec 2020 07:47:51 +0000 (16:47 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Tue, 22 Dec 2020 07:54:34 +0000 (16:54 +0900)
When well-known name disappears,
systemd sends SIGTERM to the service associated with the well-known name.

To prevent this, call sd_notify(0, "STOPPING=1") before unowing the name.

Journal log
===================================================================================================
sh-3.2# systemctl status stc-iptables.service
● stc-iptables.service - Smart Traffic Control Iptables
     Loaded: loaded (/usr/lib/systemd/system/stc-iptables.service; disabled; vendor preset: enabled)
     Active: inactive (dead) since Thu 2015-01-01 09:35:58 KST; 6s ago
    Process: 367 ExecStart=/usr/bin/stc-iptables (code=killed, signal=TERM)
   Main PID: 367 (code=killed, signal=TERM)

Jan 01 09:35:36 localhost systemd[1]: Starting Smart Traffic Control Iptables...
Jan 01 09:35:38 localhost systemd[1]: Started Smart Traffic Control Iptables.
Jan 01 09:35:58 localhost systemd[1]: stc-iptables.service: Succeeded.
===================================================================================================

Change-Id: I43434c79d8b3474917c9d96b6bd6ef0fa7b8571a

packaging/stc-iptables.spec
resources/systemd/stc-iptables.service
src/CMakeLists.txt
src/stc-iptables-gdbus.c

index 8514b96a0537e923b20ede6ffe9fce41c8be5712..2f61e39a0c260c15de470e103a4115a8329cbcc5 100644 (file)
@@ -13,6 +13,7 @@ BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(gio-unix-2.0)
 BuildRequires:  pkgconfig(libiptc)
 BuildRequires:  pkgconfig(libip6tc)
+BuildRequires:  pkgconfig(libsystemd)
 
 %if 0%{?gtests:1}
 BuildRequires:  pkgconfig(dlog)
index 093db75ac209ee5c5e259c9d541952ef9d467e11..1393b170a39945d3c7a542b180620e6540dc5afa 100755 (executable)
@@ -11,6 +11,7 @@ SmackProcessLabel=System
 ExecStart=/usr/bin/stc-iptables
 Capabilities=cap_net_bind_service,cap_net_raw,cap_net_admin=i
 SecureBits=keep-caps
+NotifyAccess=main
 
 [Install]
 WantedBy=multi-user.target
index 75197c2bc8f341382dc52c701bb2628a22a3423d..aa9400120f036839d2e6f9ad9b99f43f0110a795 100755 (executable)
@@ -4,6 +4,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        ${COMMON_DEPS}
        libiptc
        libip6tc
+       libsystemd
        )
 
 INCLUDE(FindPkgConfig)
index b966726543245e557671056cfdf22bdc662a4733..e95da6fe70860e674f17a616d9c5299ad0ed99a1 100755 (executable)
@@ -18,6 +18,7 @@
 #include "stc-iptables.h"
 #include "stc-iptables-gdbus.h"
 #include "stc-iptables-util.h"
+#include <systemd/sd-daemon.h>
 
 static gboolean __stc_iptables_gdbus_manager_init(stc_iptables_s *stc_iptables)
 {
@@ -245,6 +246,7 @@ void stc_iptables_gdbus_deinit(gpointer stc_data)
 
        stc_iptables_s *stc_iptables = (stc_iptables_s *)stc_data;
 
+       sd_notify(0, "STOPPING=1");
        g_bus_unown_name(stc_iptables->gdbus_owner_id);
 
        stc_iptables->manager_obj = NULL;