From 8549676d9cc54c2e44ee93972b82879661f68fb0 Mon Sep 17 00:00:00 2001 From: Semun Lee Date: Thu, 28 Jul 2016 19:08:25 +0900 Subject: Use fork/unshare instead of clone Change-Id: I687a275ed1a35fbc5a08b8e40fc3875da175ef05 Signed-off-by: Semun Lee --- src/launchpad.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'src/launchpad.c') diff --git a/src/launchpad.c b/src/launchpad.c index d55074f..2728b27 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -91,7 +90,6 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, int detection_method, int timeout_val); static int __remove_slot(int type, int loader_id); static int __add_default_slots(void); -static int stack_limit; static int __make_loader_id(void) { @@ -353,26 +351,27 @@ static void __send_result_to_caller(int clifd, int ret, const char *app_path) static int __fork_app_process(int (*child_fn)(void *), void *arg) { - char *stack; - char *stack_top; int pid; + int ret; + + pid = fork(); - stack = malloc(stack_limit); - if (stack == NULL) { - _E("failed to alloc child stack"); + if (pid == -1) { + _E("failed to fork child process"); return -1; } - stack_top = stack + stack_limit; - - pid = clone(child_fn, stack_top, - CLONE_NEWNS | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, - arg); - - free(stack); + if (pid == 0) { + ret = unshare(CLONE_NEWNS); + if (ret != 0) { + _E("failed to unshare mount namespace (%d)", errno); + exit(ret); + } - if (pid == -1) - _E("failed to clone child process"); + ret = child_fn(arg); + _E("failed to exec app process (%d)", errno); + exit(ret); + } return pid; } @@ -1474,8 +1473,6 @@ static void __set_priority(void) int main(int argc, char **argv) { GMainLoop *mainloop = NULL; - int ret; - struct rlimit rlim; mainloop = g_main_loop_new(NULL, FALSE); if (!mainloop) { @@ -1483,13 +1480,6 @@ int main(int argc, char **argv) return -1; } - ret = getrlimit(RLIMIT_STACK, &rlim); - if (ret != 0) { - _E("failed to get stack limit size! (%d)", errno); - return -1; - } - stack_limit = rlim.rlim_cur; - if (__before_loop(argc, argv) != 0) { _E("process-pool Initialization failed!\n"); return -1; -- cgit v1.2.3