From: Christian Brauner Date: Mon, 19 Feb 2018 09:58:56 +0000 (+0100) Subject: utils: add lxc_set_death_signal() X-Git-Tag: lxc-3.0.0.beta1~22^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fd0f41eff5c52bea00f031bd0764b121753c301;p=thirdparty%2Flxc.git utils: add lxc_set_death_signal() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/start.c b/src/lxc/start.c index e664087c2..db961e569 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -996,32 +996,6 @@ void lxc_abort(const char *name, struct lxc_handler *handler) } } -static int lxc_set_death_signal(int signal) -{ - int ret; - pid_t ppid; - - ret = prctl(PR_SET_PDEATHSIG, signal, 0, 0, 0); - - /* Check whether we have been orphaned. */ - ppid = (pid_t)syscall(SYS_getppid); - if (ppid == 1) { - pid_t self; - - self = lxc_raw_getpid(); - ret = kill(self, SIGKILL); - if (ret < 0) - return -1; - } - - if (ret < 0) { - SYSERROR("Failed to set PR_SET_PDEATHSIG to %d", signal); - return -1; - } - - return 0; -} - static int do_start(void *data) { int ret; diff --git a/src/lxc/utils.c b/src/lxc/utils.c index afcbdf34a..d7527b429 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -2510,3 +2510,29 @@ uint64_t lxc_find_next_power2(uint64_t n) n = n << 1; return n; } + +int lxc_set_death_signal(int signal) +{ + int ret; + pid_t ppid; + + ret = prctl(PR_SET_PDEATHSIG, signal, 0, 0, 0); + + /* Check whether we have been orphaned. */ + ppid = (pid_t)syscall(SYS_getppid); + if (ppid == 1) { + pid_t self; + + self = lxc_raw_getpid(); + ret = kill(self, SIGKILL); + if (ret < 0) + return -1; + } + + if (ret < 0) { + SYSERROR("Failed to set PR_SET_PDEATHSIG to %d", signal); + return -1; + } + + return 0; +} diff --git a/src/lxc/utils.h b/src/lxc/utils.h index 048995475..224c7a724 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -589,4 +589,7 @@ static inline pid_t lxc_raw_gettid(void) #endif } +/* Set a signal the child process will receive after the parent has died. */ +extern int lxc_set_death_signal(int signal); + #endif /* __LXC_UTILS_H */