Handle (ignore) when a process disappears before it can be tracked.
This commit is contained in:
parent
4e95969e06
commit
e593549587
@ -66,7 +66,7 @@ int paralimit = -1;
|
||||
extern char **environ;
|
||||
|
||||
static int run_command(struct cfjail *j);
|
||||
static void add_proc(struct cfjail *j, pid_t pid);
|
||||
static int add_proc(struct cfjail *j, pid_t pid);
|
||||
static void clear_procs(struct cfjail *j);
|
||||
static struct cfjail *find_proc(pid_t pid);
|
||||
static int term_procs(struct cfjail *j);
|
||||
@ -542,13 +542,12 @@ run_command(struct cfjail *j)
|
||||
if (pid < 0)
|
||||
err(1, "fork");
|
||||
if (pid > 0) {
|
||||
if (bg) {
|
||||
if (bg || !add_proc(j, pid)) {
|
||||
free(j->comline);
|
||||
j->comline = NULL;
|
||||
return 0;
|
||||
} else {
|
||||
paralimit--;
|
||||
add_proc(j, pid);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -622,7 +621,7 @@ run_command(struct cfjail *j)
|
||||
/*
|
||||
* Add a process to the hash, tied to a jail.
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
add_proc(struct cfjail *j, pid_t pid)
|
||||
{
|
||||
struct kevent ke;
|
||||
@ -632,8 +631,11 @@ add_proc(struct cfjail *j, pid_t pid)
|
||||
if (!kq && (kq = kqueue()) < 0)
|
||||
err(1, "kqueue");
|
||||
EV_SET(&ke, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
|
||||
if (kevent(kq, &ke, 1, NULL, 0, NULL) < 0)
|
||||
if (kevent(kq, &ke, 1, NULL, 0, NULL) < 0) {
|
||||
if (errno == ESRCH)
|
||||
return 0;
|
||||
err(1, "kevent");
|
||||
}
|
||||
ph = emalloc(sizeof(struct phash));
|
||||
ph->j = j;
|
||||
ph->pid = pid;
|
||||
@ -658,6 +660,7 @@ add_proc(struct cfjail *j, pid_t pid)
|
||||
TAILQ_INSERT_TAIL(&sleeping, j, tq);
|
||||
j->queue = &sleeping;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -730,7 +733,7 @@ term_procs(struct cfjail *j)
|
||||
for (i = 0; i < pcnt; i++)
|
||||
if (ki[i].ki_jid == j->jid &&
|
||||
kill(ki[i].ki_pid, SIGTERM) == 0) {
|
||||
add_proc(j, ki[i].ki_pid);
|
||||
(void)add_proc(j, ki[i].ki_pid);
|
||||
if (verbose > 0) {
|
||||
if (!noted) {
|
||||
noted = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user