utils: add lxc_set_death_signal()

parent 46800e77
...@@ -996,32 +996,6 @@ void lxc_abort(const char *name, struct lxc_handler *handler) ...@@ -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) static int do_start(void *data)
{ {
int ret; int ret;
......
...@@ -2510,3 +2510,29 @@ uint64_t lxc_find_next_power2(uint64_t n) ...@@ -2510,3 +2510,29 @@ uint64_t lxc_find_next_power2(uint64_t n)
n = n << 1; n = n << 1;
return n; 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;
}
...@@ -589,4 +589,7 @@ static inline pid_t lxc_raw_gettid(void) ...@@ -589,4 +589,7 @@ static inline pid_t lxc_raw_gettid(void)
#endif #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 */ #endif /* __LXC_UTILS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment