Set simple type at tv service 79/290579/2
authorYoungHun Kim <yh8004.kim@samsung.com>
Tue, 14 Mar 2023 16:20:57 +0000 (01:20 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Wed, 29 Mar 2023 07:58:10 +0000 (16:58 +0900)
 - Avoid netlink event delay issue of parent or child process by daemonzing
 - UPdate dlog

Change-Id: I91a9d22eddd893d94d12cac3873d87f73da06e7b

packaging/muse-server-vd_product_tv.service
packaging/muse-server.service
packaging/mused.spec
server/include/muse_server_private.h
server/src/muse_server.c
server/src/muse_server_private.c
server/src/muse_server_system.c

index e8c1e8c..b5424fe 100644 (file)
@@ -3,13 +3,12 @@ Description=muse server of vd product (tv)
 ConditionPathExists=!/run/.standalone
 
 [Service]
-Type=forking
+Type=simple
 User=multimedia_fw
 Group=multimedia_fw
 SmackProcessLabel=System
 ExecStart=/usr/bin/muse-server
 ExecStopPost=/usr/bin/ewaiter -r "/run/mused/muse_server_ready"
-PIDFile=/run/mused/muse-server.pid
 Restart=always
 MemoryLimit=300M
 EnvironmentFile=/run/tizen-system-env
index 178a0e2..928fa99 100644 (file)
@@ -8,7 +8,7 @@ Type=forking
 User=multimedia_fw
 Group=multimedia_fw
 SmackProcessLabel=System
-ExecStart=/usr/bin/muse-server
+ExecStart=/usr/bin/muse-server -D
 PIDFile=/run/mused/muse-server.pid
 Restart=always
 MemoryLimit=300M
index b7cd5fd..65ea6b8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.164
+Version:    0.3.166
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index e0e6aaa..a734b97 100644 (file)
@@ -81,6 +81,7 @@ typedef struct _muse_server {
        int stop;
        int retval;
        int pid;
+       gboolean daemonize;
        tbm_bufmgr bufmgr;
        GMainLoop *main_loop;
        ms_diag_t diag;
index a387d0d..384f366 100644 (file)
@@ -319,9 +319,6 @@ int main(int argc, char **argv)
        trace_begin("MUSE:START");
 #endif
 
-       if (argc > 1)
-               ms_parse_params(argc, argv);
-
        ms_init(argv);
 
        ms_run();
index 7f439d6..1765591 100644 (file)
@@ -76,12 +76,16 @@ static gpointer _ms_diag_check_connection_event_thread(gpointer data);
 static void _ms_lock_state(void);
 static void _ms_unlock_state(void);
 static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition condition, gpointer data);
-#ifdef MUSE_USE_LWIPC
-static void _ms_wait_event(void);
 static void _ms_diag_init(void);
 static void _ms_diag_deinit(void);
 static gboolean _ms_idle_cb(gpointer data);
 static int _ms_open_lockfile(void);
+static void _ms_process_init(void);
+static void _ms_launch_foreground(void);
+static void _ms_daemonize(void);
+
+#ifdef MUSE_USE_LWIPC
+static void _ms_wait_event(void);
 
 static void _ms_wait_event(void)
 {
@@ -158,6 +162,7 @@ static void _ms_create_new_server_from_fd(int fd[], int type)
 static int _ms_new(muse_channel_e channel)
 {
        int fd, errsv;
+       mode_t m = 0;
        struct sockaddr_un addr_un;
        socklen_t address_len;
        char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
@@ -181,6 +186,9 @@ static int _ms_new(muse_channel_e channel)
        strncpy(addr_un.sun_path, UDS_files[channel], sizeof(addr_un.sun_path) - 1);
        address_len = (socklen_t)sizeof(addr_un);
 
+       if (!muse_server->daemonize)
+               m = umask(0);
+
        /* Bind to filename */
        if (bind(fd, (struct sockaddr *)&addr_un, address_len) < 0) {
                errsv = errno;
@@ -207,6 +215,9 @@ static int _ms_new(muse_channel_e channel)
        if (muse_core_set_nonblocking(fd, false) < 0) /* blocking */
                LOGE("failed to set server socket to blocking");
 
+       if (!muse_server->daemonize)
+               umask(m);
+
        return fd;
 }
 
@@ -702,6 +713,43 @@ static int _ms_open_lockfile(void)
        return MM_ERROR_NONE;
 }
 
+static void _ms_process_init(void)
+{
+       if (g_mkdir_with_parents(tzplatform_mkpath(TZ_SYS_RUN, "mused"), S_IRWXU | S_IRWXG | S_IRWXO) != 0)
+               exit(EXIT_FAILURE);
+
+       if (muse_server->daemonize) {
+               if (ms_pidfile_create(MUSE_DEFAULT_PIDFILE, muse_server->pid) != MM_ERROR_NONE)
+                       exit(EXIT_FAILURE);
+               else
+                       LOGW("MUSE_DEFAULT_PIDFILE(%s) file was created", MUSE_DEFAULT_PIDFILE);
+       }
+
+       _ms_init();
+
+       muse_return_if_fail(_ms_open_lockfile() == MM_ERROR_NONE);
+
+       ms_new();
+}
+
+static void _ms_launch_foreground(void)
+{
+       muse_server->pid = (int)getpid();
+
+       _ms_process_init();
+}
+
+static void _ms_daemonize(void)
+{
+       int notify_fd;
+
+       muse_server->pid = ms_daemonize(&notify_fd);
+
+       _ms_process_init();
+
+       ms_daemonize_complete(notify_fd);
+}
+
 void ms_setup_syslog(void)
 {
        int flags = LOG_CONS|LOG_NDELAY|LOG_PID;
@@ -800,10 +848,6 @@ void ms_daemonize_complete(int notify_fd)
 
        muse_return_if_fail(muse_core_fd_is_valid(notify_fd));
 
-#ifdef MUSE_REGISTER_VIP
-       proc_stat_set_vip_process();
-#endif
-
        write(notify_fd, MSG_DONE, strlen(MSG_DONE) + 1);
        LOGW("[%d] Notify parent process that child initialization is done", notify_fd);
        close(notify_fd);
@@ -944,32 +988,30 @@ int ms_pidfile_create(const char *path, pid_t pid)
 void ms_init(char **argv)
 {
        int idx;
-       int notify_fd;
+
        muse_module_cmd_dispatchfunc *cmd_dispatcher = NULL;
 
        LOGW("Enter");
 
        muse_server = g_new0(muse_server_t, 1);
 
-       ms_setup_syslog();
-
-       muse_server->pid = ms_daemonize(&notify_fd);
+       for (idx = 1; argv[idx] != NULL; idx++) {
+               if (strcmp(argv[idx], "-D") == 0) {
+                       LOGI("enable daemonize");
+                       muse_server->daemonize = TRUE;
+               }
+       }
 
-       if (g_mkdir_with_parents(tzplatform_mkpath(TZ_SYS_RUN, "mused"), S_IRWXU | S_IRWXG | S_IRWXO) != 0)
-               exit(EXIT_FAILURE);
+       ms_setup_syslog();
 
-       if (ms_pidfile_create(MUSE_DEFAULT_PIDFILE, muse_server->pid) != MM_ERROR_NONE)
-               exit(EXIT_FAILURE);
+       if (muse_server->daemonize)
+               _ms_daemonize();
        else
-               LOGW("MUSE_DEFAULT_PIDFILE(%s) file was created", MUSE_DEFAULT_PIDFILE);
-
-       _ms_init();
+               _ms_launch_foreground();
 
-       muse_return_if_fail(_ms_open_lockfile() == MM_ERROR_NONE);
-
-       ms_new();
-
-       ms_daemonize_complete(notify_fd);
+#ifdef MUSE_REGISTER_VIP
+       proc_stat_set_vip_process();
+#endif
 
 #ifdef MUSE_TTRACE_LOG
        trace_end();
index 4618efd..bb88252 100644 (file)
@@ -331,7 +331,7 @@ static gboolean _ms_system_cpu_usage_cb(gpointer user_data)
        system->st.idle += i;
 
        if (u + n + s + i == 0) {
-               LOGD("[#%d] cpu usage is 0%%", system->st.counter);
+               LOGW("[#%d] cpu usage is 0%%", system->st.counter);
                return G_SOURCE_REMOVE;
        }
 
@@ -339,7 +339,7 @@ static gboolean _ms_system_cpu_usage_cb(gpointer user_data)
        LOGD("[#%d] cpu usage %d %%", system->st.counter, system->st.usage);
 
        if (system->st.usage < cpu_threshold) {
-               LOGD("[#%d] cpu usage (%d) < cpu_threshold (%d)", system->st.counter, system->st.usage, cpu_threshold);
+               LOGI("[#%d] cpu usage (%d) < cpu_threshold (%d)", system->st.counter, system->st.usage, cpu_threshold);
                return G_SOURCE_REMOVE;
        }