core: Change to register signal handler with glib 52/293052/1 accepted/tizen/7.0/unified/20230531.153704
authorTaeminYeom <taemin.yeom@samsung.com>
Thu, 18 May 2023 07:33:32 +0000 (16:33 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Thu, 18 May 2023 07:50:17 +0000 (16:50 +0900)
Using standard signal handler can make deadlock in terminating progress.
When standard signal handler is called dispatching g_main_context,
glib attempts to lock g_main_context again.
To prevent this situation, it is needed to use glib signal handler function.

Change-Id: If2e2fa1c3ebc4bbc7a00b11b3c7f42a9e4fd36ee
Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
src/core/main.c

index 1f77e48..1011053 100644 (file)
@@ -56,16 +56,22 @@ static void writepid(char *pidpath)
        }
 }
 
-static void sig_quit(int signo)
+static gboolean handle_sigterm(gpointer data)
 {
-       _D("Received SIGTERM signal(%d).", signo);
+       long signo = (long) data;
+       _D("Received SIGTERM signal(%ld).", signo);
+
+       return G_SOURCE_REMOVE;
 }
 
-static void sig_usr1(int signo)
+static gboolean handle_sigusr1(gpointer data)
 {
-       CRITICAL_LOG("Received SIGUSR1 signal(%d), deviced'll be finished.", signo);
+       long signo = (long) data;
+       CRITICAL_LOG("Received SIGUSR1 signal(%ld), deviced'll be finished.", signo);
        if (mainloop && g_main_loop_is_running(mainloop))
                g_main_loop_quit(mainloop);
+
+       return G_SOURCE_REMOVE;
 }
 
 void watchdog_notify(void)
@@ -133,8 +139,8 @@ static int deviced_main(int argc, char **argv)
                gdbus_check_name_owner(NULL, DEVICED_BUS_NAME);
        }
 
-       signal(SIGTERM, sig_quit);
-       signal(SIGUSR1, sig_usr1);
+       g_unix_signal_add(SIGTERM, handle_sigterm, (gpointer) SIGTERM);
+       g_unix_signal_add(SIGUSR1, handle_sigusr1, (gpointer) SIGUSR1);
 
        timer = g_timeout_add_seconds_full(G_PRIORITY_HIGH, WATCHDOG_REFRESH_TIME, watchdog_cb, NULL, NULL);
        if (timer) {