Make Process do prctl(PR_SET_PDEATHSIG)
This means that nanosm managed process will also predictably die if nanosm is killed.
This commit is contained in:
parent
bc530fe8a2
commit
0a0ab0703a
|
@ -3,6 +3,7 @@
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "WordExp.hpp"
|
#include "WordExp.hpp"
|
||||||
|
@ -49,6 +50,12 @@ namespace nanosm {
|
||||||
for(usize i = 0; i < exp.words.size(); ++i)
|
for(usize i = 0; i < exp.words.size(); ++i)
|
||||||
argv[i] = exp.words[i].data();
|
argv[i] = exp.words[i].data();
|
||||||
|
|
||||||
|
// Ensure that if nanosm (the parent) dies, we die along with it
|
||||||
|
if(prctl(PR_SET_PDEATHSIG, SIGTERM) == -1) {
|
||||||
|
perror("Process pre-exec: prctl(PR_SET_PDEATHSIG)");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
exit(execvp(exp.words[0].data(), argv.data()));
|
exit(execvp(exp.words[0].data(), argv.data()));
|
||||||
} else {
|
} else {
|
||||||
// Parent: monitor the pidfd by adding ourselves to the event loop now
|
// Parent: monitor the pidfd by adding ourselves to the event loop now
|
||||||
|
|
Loading…
Reference in New Issue