summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSemun Lee <sm79.lee@samsung.com>2016-07-28 19:08:25 +0900
committerSemun Lee <sm79.lee@samsung.com>2016-07-28 19:27:08 +0900
commit8549676d9cc54c2e44ee93972b82879661f68fb0 (patch)
tree3474a9ef045d740265f586b78d06df866cf17cfa
parenta807134e50aacb942b3719e443d303d50d221f67 (diff)
downloadlaunchpad-8549676d9cc54c2e44ee93972b82879661f68fb0.tar.gz
launchpad-8549676d9cc54c2e44ee93972b82879661f68fb0.tar.bz2
launchpad-8549676d9cc54c2e44ee93972b82879661f68fb0.zip
Use fork/unshare instead of clone
Change-Id: I687a275ed1a35fbc5a08b8e40fc3875da175ef05 Signed-off-by: Semun Lee <sm79.lee@samsung.com>
-rwxr-xr-xsrc/launchpad.c40
1 files changed, 15 insertions, 25 deletions
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 <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
-#include <sys/resource.h>
#include <sched.h>
#include <stdbool.h>
#include <malloc.h>
@@ -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;