summaryrefslogtreecommitdiffstats
path: root/usr.sbin/jexec
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2009-04-04 16:03:28 +0000
committerru <ru@FreeBSD.org>2009-04-04 16:03:28 +0000
commit424510e7af2b5c60d6b798be40f46d67f4ef1e05 (patch)
tree9d4b05432d47fba642aacefbff3213bb551e628a /usr.sbin/jexec
parentf2d082b711af7eba38f12d8bcdb000a1c99a5c00 (diff)
downloadFreeBSD-src-424510e7af2b5c60d6b798be40f46d67f4ef1e05.zip
FreeBSD-src-424510e7af2b5c60d6b798be40f46d67f4ef1e05.tar.gz
- Style: size_t can't be negative.
- Don't exit with a zero status code when no jails are configured on a system. - Style: simplify some code constructs. - If a single jail cannot be found, let the caller print a nicer diagnostic message. Reviewed by: bz MFC after: 3 days
Diffstat (limited to 'usr.sbin/jexec')
-rw-r--r--usr.sbin/jexec/jexec.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/usr.sbin/jexec/jexec.c b/usr.sbin/jexec/jexec.c
index 9d788dd..7237b5a 100644
--- a/usr.sbin/jexec/jexec.c
+++ b/usr.sbin/jexec/jexec.c
@@ -119,8 +119,8 @@ lookup_jail(int jid, char *jailname)
j = len;
for (i = 0; i < 4; i++) {
- if (len <= 0)
- exit(0);
+ if (len == 0)
+ return (-1);
p = q = malloc(len);
if (p == NULL)
err(1, "malloc()");
@@ -174,27 +174,21 @@ lookup_jail(int jid, char *jailname)
/* NOTREACHED */
break;
}
- /* Possible match. */
- if (id > 0) {
- /* Do we have a jail ID to match as well? */
- if (jid > 0) {
- if (jid == id) {
- xid = id;
- count++;
- }
- } else {
- xid = id;
- count++;
- }
+ /* Possible match; see if we have a jail ID to match as well. */
+ if (id > 0 && (jid <= 0 || id == jid)) {
+ xid = id;
+ count++;
}
}
free(p);
- if (count != 1)
+ if (count == 1)
+ return (xid);
+ else if (count > 1)
errx(1, "Could not uniquely identify the jail.");
-
- return (xid);
+ else
+ return (-1);
}
#define GET_USER_INFO do { \
OpenPOWER on IntegriCloud