daemon/espp_service: Avoid assigning local variable to global
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 20 Sep 2023 08:56:33 +0000 (17:56 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Thu, 21 Sep 2023 06:04:03 +0000 (15:04 +0900)
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
src/daemon/espp_service.c

index 9ec3e6c89b7832cf558dcfcb688e1304e3be7ace..a0e8c4abb754f9aa1106b6c66903f2ea989ec3ac 100644 (file)
 #include <sys/stat.h>
 #ifdef USE_SERVICE_APP
 #include <service_app.h>
+static espp_service_s g_svc = { -1, 0, NULL };
 #else
+static espp_service_s g_svc = { false, NULL, -1, 0, NULL };
 static struct sigaction g_int_old_action;
 static struct sigaction g_abrt_old_action;
 static struct sigaction g_segv_old_action;
 static struct sigaction g_term_old_action;
 static struct sigaction g_sys_old_action;
 static struct sigaction g_xcpu_old_action;
-
-espp_service_s *g_svc;
 #endif
 
 #ifndef USE_SERVICE_APP
@@ -82,8 +82,8 @@ static void __sa_handler(int signal)
        sigfillset(&all_mask);
        sigprocmask(SIG_BLOCK, &all_mask, &old_mask);
 
-       g_hash_table_destroy(g_svc->fd_table);
-       espp_service_deinit_socket(g_svc);
+       g_hash_table_destroy(g_svc.fd_table);
+       espp_service_deinit_socket(&g_svc);
 
        sigprocmask(SIG_SETMASK, &old_mask, NULL);
        /* signal unblock ------------ */
@@ -225,40 +225,32 @@ exit:
 
 int main(int argc, char *argv[])
 {
-#ifndef USE_SERVICE_APP
-       espp_service_s svc = { false, NULL, -1, 0, NULL };
-#else
-       espp_service_s svc = { -1, 0, NULL };
-#endif
-
        LOG_WARNING("launched, version[%s]", ESPP_SVC_VERSION);
 
 #ifndef USE_SERVICE_APP
-       if (get_option(argc, argv, &svc))
+       if (get_option(argc, argv, &g_svc))
                return 1;
 
-       if (!svc.start_service) {
+       if (!g_svc.start_service) {
                LOG_DEBUG("Use 'espp-service -s' to start the service");
                goto exit;
        }
 
-       g_svc = &svc;
-
        initialize_signals();
 
        signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE */
 
        umask(0); /* change the file mode mask */
 
-       if (espp_service_init_socket(&svc) != 0)
+       if (espp_service_init_socket(&g_svc) != 0)
                goto exit;
 
-       svc.fd_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, espp_service_handle_destroy_cb);
+       g_svc.fd_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, espp_service_handle_destroy_cb);
 
-       run(&svc);
+       run(&g_svc);
 
-       g_hash_table_destroy(svc.fd_table);
-       espp_service_deinit_socket(&svc);
+       g_hash_table_destroy(g_svc.fd_table);
+       espp_service_deinit_socket(&g_svc);
        deinitialize_signals();
 
 exit:
@@ -272,6 +264,6 @@ exit:
        event_cb.app_control = svc_app_control_cb;
 
        LOG_WARNING("Use service_app_main()");
-       return service_app_main(argc, argv, &event_cb, &svc);
+       return service_app_main(argc, argv, &event_cb, &g_svc);
 #endif
 }