summaryrefslogtreecommitdiffstats
path: root/usr.sbin/jail
diff options
context:
space:
mode:
authorjamie <jamie@FreeBSD.org>2013-02-14 19:27:52 +0000
committerjamie <jamie@FreeBSD.org>2013-02-14 19:27:52 +0000
commit10787524f805dbb72b195e27788e2feebcdbf75a (patch)
treec96b00f62510b3bd255fcde11daa370e5378d667 /usr.sbin/jail
parentca4c3f9c587c9b313d48c94e5acc4f321ce3cfd3 (diff)
downloadFreeBSD-src-10787524f805dbb72b195e27788e2feebcdbf75a.zip
FreeBSD-src-10787524f805dbb72b195e27788e2feebcdbf75a.tar.gz
Handle (ignore) when a process disappears before it can be tracked.
Diffstat (limited to 'usr.sbin/jail')
-rw-r--r--usr.sbin/jail/command.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/usr.sbin/jail/command.c b/usr.sbin/jail/command.c
index b7d5168..3bdedad 100644
--- a/usr.sbin/jail/command.c
+++ b/usr.sbin/jail/command.c
@@ -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;
OpenPOWER on IntegriCloud