From a4c57fba2d418bd2c97011c019f0088253bff3e8 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 11 Sep 2017 14:54:03 -0400 Subject: [PATCH] use separate pid namespaces when forking runner gadgets ensure children of gadgets are destroyed when main gadget process exits --- src/runner.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/runner.c b/src/runner.c index f3bd5bc..93a924e 100644 --- a/src/runner.c +++ b/src/runner.c @@ -3,6 +3,11 @@ #include #include "e-gadget-server-protocol.h" #include "action_route-server-protocol.h" +#include + +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wformat-truncation" +#endif typedef enum { @@ -41,6 +46,8 @@ typedef struct RConfig static E_Config_DD *conf_edd = NULL; static E_Config_DD *conf_item_edd = NULL; +static int ns_fd = -1; + static RConfig *rconfig; static Eina_List *instances; static Eina_List *wizards; @@ -75,8 +82,12 @@ runner_run(Instance *inst) snprintf(buf, sizeof(buf), "%d", inst->ci->id); e_util_env_set("E_GADGET_ID", buf); + unshare(CLONE_NEWPID); + inst->exe = efl_wl_run(inst->obj, inst->ci->cmd); + setns(ns_fd, CLONE_NEWPID); + e_util_env_set("E_GADGET_ID", NULL); e_util_env_set("LD_PRELOAD", preload); free(file); @@ -796,6 +807,12 @@ runner_init(void) E_LIST_HANDLER_APPEND(handlers, EIO_MONITOR_ERROR, monitor_error, NULL); sandbox_gadgets = eina_hash_string_superfast_new((Eina_Free_Cb)efreet_desktop_free); + { + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "/proc/%d/ns/pid", getpid()); + ns_fd = open(buf, O_RDONLY); + } } EINTERN void @@ -827,6 +844,8 @@ runner_shutdown(void) E_FREE_LIST(handlers, ecore_event_handler_del); E_FREE_FUNC(sandbox_gadgets, eina_hash_free); E_FREE_FUNC(gadget_lister, eio_file_cancel); + close(ns_fd); + ns_fd = -1; } EINTERN void