subproc: Allow killing subprocesses with different signal
`subproc::killAndReapAll()` is always killing the child process with the SIGKILL signal. We're about to make this configurable though so that we may optionally forward signals received by nsjail to the child process. Add a new parameter to `killAndReapAll()` to prepare for this change.
This commit is contained in:
parent
6483728e24
commit
a517934aba
@ -222,7 +222,7 @@ static int listenMode(nsjconf_t* nsjconf) {
|
||||
}
|
||||
for (;;) {
|
||||
if (sigFatal > 0) {
|
||||
subproc::killAndReapAll(nsjconf);
|
||||
subproc::killAndReapAll(nsjconf, SIGKILL);
|
||||
logs::logStop(sigFatal);
|
||||
close(listenfd);
|
||||
return EXIT_SUCCESS;
|
||||
@ -285,7 +285,7 @@ static int standaloneMode(nsjconf_t* nsjconf) {
|
||||
subproc::displayProc(nsjconf);
|
||||
}
|
||||
if (sigFatal > 0) {
|
||||
subproc::killAndReapAll(nsjconf);
|
||||
subproc::killAndReapAll(nsjconf, SIGKILL);
|
||||
logs::logStop(sigFatal);
|
||||
return (128 + sigFatal);
|
||||
}
|
||||
|
@ -389,10 +389,10 @@ int reapProc(nsjconf_t* nsjconf) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
void killAndReapAll(nsjconf_t* nsjconf) {
|
||||
void killAndReapAll(nsjconf_t* nsjconf, int signal) {
|
||||
while (!nsjconf->pids.empty()) {
|
||||
pid_t pid = nsjconf->pids.begin()->first;
|
||||
if (kill(pid, SIGKILL) == 0) {
|
||||
if (kill(pid, signal) == 0) {
|
||||
reapProc(nsjconf, pid, true);
|
||||
} else {
|
||||
removeProc(nsjconf, pid);
|
||||
|
@ -37,7 +37,7 @@ namespace subproc {
|
||||
pid_t runChild(nsjconf_t* nsjconf, int listen_fd, int fd_in, int fd_out, int fd_err);
|
||||
int countProc(nsjconf_t* nsjconf);
|
||||
void displayProc(nsjconf_t* nsjconf);
|
||||
void killAndReapAll(nsjconf_t* nsjconf);
|
||||
void killAndReapAll(nsjconf_t* nsjconf, int signal);
|
||||
/* Returns the exit code of the first failing subprocess, or 0 if none fail */
|
||||
int reapProc(nsjconf_t* nsjconf);
|
||||
int systemExe(const std::vector<std::string>& args, char** env);
|
||||
|
Loading…
Reference in New Issue
Block a user