summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorYoungHun Kim <yh8004.kim@samsung.com>2018-10-24 03:07:30 +0000
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>2018-10-24 03:07:30 +0000
commit9f04c564fc350b2fb26b8958c374461f006f576d (patch)
treee6f45d26fa1602674f0328549ef41ea2006ad313 /server
parentcaf6aa5e5cb9a7d9f58dece4fc00a9b31c8fac87 (diff)
parent9c05c99a8c280031592cb090808ce386705af9f9 (diff)
downloadmmsvc-core-9f04c564fc350b2fb26b8958c374461f006f576d.tar.gz
mmsvc-core-9f04c564fc350b2fb26b8958c374461f006f576d.tar.bz2
mmsvc-core-9f04c564fc350b2fb26b8958c374461f006f576d.zip
Merge "Update to wait until the child processe called by fork() completes" into tizensubmit/tizen/20181024.032316
Diffstat (limited to 'server')
-rw-r--r--server/include/muse_server_private.h4
-rw-r--r--server/src/muse_server.c49
-rw-r--r--server/src/muse_server_private.c11
3 files changed, 54 insertions, 10 deletions
diff --git a/server/include/muse_server_private.h b/server/include/muse_server_private.h
index 99f0e1b..b3dda50 100644
--- a/server/include/muse_server_private.h
+++ b/server/include/muse_server_private.h
@@ -45,6 +45,8 @@ extern "C" {
#define MS_TIMEOUT_MSEC 1000
#define MS_RECV_TRY_COUNT_MAX 3
+#define MSG_DONE "DONE"
+
gboolean ms_ipc_job_function(ms_workqueue_job_t *job);
gboolean ms_ipc_data_job_function(ms_workqueue_job_t *job);
@@ -91,7 +93,7 @@ ms_module_t *ms_get_module_instance(int idx);
int ms_deinit(void);
void ms_check_memory(int pid);
void ms_new(void);
-int ms_run(void);
+int ms_run(int notify_fd);
void ms_cmd_dispatch(muse_module_h m, muse_module_command_e cmd);
void ms_exit_worker(muse_module_h m);
void ms_respawn(int signo);
diff --git a/server/src/muse_server.c b/server/src/muse_server.c
index 3920c6e..de876cb 100644
--- a/server/src/muse_server.c
+++ b/server/src/muse_server.c
@@ -28,7 +28,8 @@
#endif
static void _ms_setup_syslog(void);
-static pid_t _ms_daemonize(void);
+static void _ms_fork(int *notify_fd);
+static pid_t _ms_daemonize(int *notify_fd);
static void _ms_gst_init(char **cmd);
static int _ms_pidfile_create(const char *path, pid_t pid);
@@ -42,19 +43,52 @@ static void _ms_setup_syslog(void)
LOGD("openlog - mused");
}
-static pid_t _ms_daemonize(void)
+static void _ms_fork(int *notify_fd)
{
pid_t pid;
- int fd, result;
+ int result, fds[2];
char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
+ char msg[MUSE_MSG_LEN_MAX] = {'\0',};
+
+ if (pipe(fds) == MUSE_ERR) {
+ strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
+ LOGE("Failed to create pipe to get child status: %s", err_msg);
+ exit(EXIT_FAILURE);
+ }
if ((pid = fork()) < 0) {
strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
LOGE("Error: fork() failed: %s", err_msg);
- exit(EXIT_SUCCESS);
+ exit(EXIT_FAILURE);
} else if (pid != 0) {
- exit(EXIT_SUCCESS);
+ close(fds[1]);
+ /* Read in a string from the pipe */
+ result = read(fds[0], msg, sizeof(msg));
+ close(fds[0]);
+
+ /* Parent process closes up output side of pipe */
+ if (!strcmp(msg, MSG_DONE)) {
+ LOGI("Successfully daemonized");
+ exit(EXIT_SUCCESS);
+ } else {
+ LOGE("Daemonizing failed after fork");
+ exit(EXIT_FAILURE);
+ }
+ } else if (pid == 0) {
+ /* Child process closes up input side of pipe */
+ close(fds[0]);
+ *notify_fd = fds[1];
}
+}
+
+static pid_t _ms_daemonize(int *notify_fd)
+{
+ pid_t pid;
+ int fd, result;
+
+ muse_return_val_if_fail(notify_fd, MUSE_ERR);
+
+ _ms_fork(notify_fd);
if ((pid = setsid()) < 0) {
LOGE("create new session");
@@ -401,6 +435,7 @@ int main(int argc, char **argv)
{
pid_t pid;
int idx;
+ int notify_fd = -1;
muse_module_cmd_dispatchfunc *cmd_dispatcher = NULL;
#ifdef MUSE_TTRACE_LOG
@@ -409,7 +444,7 @@ int main(int argc, char **argv)
_ms_setup_syslog();
- pid = _ms_daemonize();
+ pid = _ms_daemonize(&notify_fd);
if (_ms_pidfile_create(MUSE_DEFAULT_PIDFILE, pid) != MM_ERROR_NONE)
exit(EXIT_FAILURE);
@@ -448,5 +483,5 @@ int main(int argc, char **argv)
#ifdef MUSE_TTRACE_LOG
trace_end();
#endif
- return ms_run();
+ return ms_run(notify_fd);
}
diff --git a/server/src/muse_server_private.c b/server/src/muse_server_private.c
index 67f4c9a..d24255c 100644
--- a/server/src/muse_server_private.c
+++ b/server/src/muse_server_private.c
@@ -298,6 +298,8 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
}
client_len = sizeof(client_address);
+
+ LOGI("[%d] Try to accept...", server_sockfd);
client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
if (!muse_core_fd_is_valid(client_sockfd)) {
LOGE("Critical Error : accept %d is invalid", client_sockfd);
@@ -693,7 +695,7 @@ void ms_new(void)
_ms_create_new_server_from_fd(fd, READ | PERSIST);
}
-int ms_run(void)
+int ms_run(int notify_fd)
{
char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
GError *error = NULL;
@@ -704,6 +706,7 @@ int ms_run(void)
LOGW("Enter");
+ muse_return_val_if_fail(muse_core_fd_is_valid(notify_fd), MUSE_ERR);
muse_return_val_if_fail(_ms_run() == MM_ERROR_NONE, MUSE_ERR);
muse_return_val_if_fail(muse_server, MUSE_ERR);
@@ -753,10 +756,13 @@ int ms_run(void)
LOGE("Fail to subscribe external storage state change");
#endif
+ write(notify_fd, MSG_DONE, strlen(MSG_DONE) + 1);
+ LOGI("[%d] Notify parent process that child initialization is done", notify_fd);
+ close(notify_fd);
+
#ifdef MUSE_USE_WATCHDOG
if (ms_watchdog_attach(muse_server->watchdog)) {
LOGW("g_main_loop_run");
-
g_main_loop_run(muse_server->main_loop);
ms_watchdog_detach(muse_server->watchdog);
@@ -765,6 +771,7 @@ int ms_run(void)
ms_log_process_info(muse_server->pid);
}
#else
+ LOGW("g_main_loop_run");
g_main_loop_run(muse_server->main_loop);
#endif