aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/jail
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2013-04-12 20:48:55 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2013-04-12 20:48:55 +0000
commit69e6d7b75e96c406d072cb83ffc9b26fbf1a86fb (patch)
tree54038c9ac32a45f8741dcc23fb9a8ffc0e15ff89 /usr.sbin/jail
parent51048477bcc79bcc8753121ec91c150648df3d1b (diff)
parent8818042ff2ecd155adb5c248a22de2dbe5d9c2a9 (diff)
downloadsrc-69e6d7b75e96c406d072cb83ffc9b26fbf1a86fb.tar.gz
src-69e6d7b75e96c406d072cb83ffc9b26fbf1a86fb.zip
sync from head
Notes
Notes: svn path=/projects/bmake/; revision=249429
Diffstat (limited to 'usr.sbin/jail')
-rw-r--r--usr.sbin/jail/command.c24
-rw-r--r--usr.sbin/jail/config.c8
-rw-r--r--usr.sbin/jail/jailp.h1
3 files changed, 20 insertions, 13 deletions
diff --git a/usr.sbin/jail/command.c b/usr.sbin/jail/command.c
index b7d5168d8b4f..452a079829d2 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);
@@ -88,13 +88,14 @@ int
next_command(struct cfjail *j)
{
enum intparam comparam;
- int create_failed;
+ int create_failed, stopping;
if (paralimit == 0) {
requeue(j, &runnable);
return 1;
}
create_failed = (j->flags & (JF_STOP | JF_FAILED)) == JF_FAILED;
+ stopping = (j->flags & JF_STOP) != 0;
comparam = *j->comparam;
for (;;) {
if (j->comstring == NULL) {
@@ -113,14 +114,16 @@ next_command(struct cfjail *j)
default:
if (j->intparams[comparam] == NULL)
continue;
- j->comstring = create_failed
+ j->comstring = create_failed || (stopping &&
+ (j->intparams[comparam]->flags & PF_REV))
? TAILQ_LAST(&j->intparams[comparam]->val,
cfstrings)
: TAILQ_FIRST(&j->intparams[comparam]->val);
}
} else {
j->comstring = j->comstring == &dummystring ? NULL :
- create_failed
+ create_failed || (stopping &&
+ (j->intparams[comparam]->flags & PF_REV))
? TAILQ_PREV(j->comstring, cfstrings, tq)
: TAILQ_NEXT(j->comstring, tq);
}
@@ -542,13 +545,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 +624,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 +634,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 +663,7 @@ add_proc(struct cfjail *j, pid_t pid)
TAILQ_INSERT_TAIL(&sleeping, j, tq);
j->queue = &sleeping;
}
+ return 1;
}
/*
@@ -730,7 +736,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;
diff --git a/usr.sbin/jail/config.c b/usr.sbin/jail/config.c
index d0b7d266b518..a201f314e577 100644
--- a/usr.sbin/jail/config.c
+++ b/usr.sbin/jail/config.c
@@ -81,18 +81,18 @@ static const struct ipspec intparams[] = {
[IP_INTERFACE] = {"interface", PF_INTERNAL},
[IP_IP_HOSTNAME] = {"ip_hostname", PF_INTERNAL | PF_BOOL},
#endif
- [IP_MOUNT] = {"mount", PF_INTERNAL},
+ [IP_MOUNT] = {"mount", PF_INTERNAL | PF_REV},
[IP_MOUNT_DEVFS] = {"mount.devfs", PF_INTERNAL | PF_BOOL},
[IP_MOUNT_FSTAB] = {"mount.fstab", PF_INTERNAL},
[IP_STOP_TIMEOUT] = {"stop.timeout", PF_INTERNAL | PF_INT},
[IP_VNET_INTERFACE] = {"vnet.interface", PF_INTERNAL},
#ifdef INET
- [IP__IP4_IFADDR] = {"ip4.addr", PF_INTERNAL | PF_CONV},
+ [IP__IP4_IFADDR] = {"ip4.addr", PF_INTERNAL | PF_CONV | PF_REV},
#endif
#ifdef INET6
- [IP__IP6_IFADDR] = {"ip6.addr", PF_INTERNAL | PF_CONV},
+ [IP__IP6_IFADDR] = {"ip6.addr", PF_INTERNAL | PF_CONV | PF_REV},
#endif
- [IP__MOUNT_FROM_FSTAB] = {"mount.fstab", PF_INTERNAL | PF_CONV},
+ [IP__MOUNT_FROM_FSTAB] = {"mount.fstab", PF_INTERNAL | PF_CONV | PF_REV},
[IP__OP] = {NULL, PF_CONV},
[KP_ALLOW_CHFLAGS] = {"allow.chflags", 0},
[KP_ALLOW_MOUNT] = {"allow.mount", 0},
diff --git a/usr.sbin/jail/jailp.h b/usr.sbin/jail/jailp.h
index ffd35cc81896..63995b2be6a4 100644
--- a/usr.sbin/jail/jailp.h
+++ b/usr.sbin/jail/jailp.h
@@ -50,6 +50,7 @@
#define PF_BOOL 0x10 /* Boolean parameter */
#define PF_INT 0x20 /* Integer parameter */
#define PF_CONV 0x40 /* Parameter duplicated in converted form */
+#define PF_REV 0x80 /* Run commands in reverse order on stopping */
#define JF_START 0x0001 /* -c */
#define JF_SET 0x0002 /* -m */