From owner-svn-src-all@FreeBSD.ORG Tue Apr 7 12:49:50 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EFB7610656DC; Tue, 7 Apr 2009 12:49:50 +0000 (UTC) (envelope-from ru@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DD1EE8FC2E; Tue, 7 Apr 2009 12:49:50 +0000 (UTC) (envelope-from ru@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n37CnoYn008740; Tue, 7 Apr 2009 12:49:50 GMT (envelope-from ru@svn.freebsd.org) Received: (from ru@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n37CnoC4008739; Tue, 7 Apr 2009 12:49:50 GMT (envelope-from ru@svn.freebsd.org) Message-Id: <200904071249.n37CnoC4008739@svn.freebsd.org> From: Ruslan Ermilov Date: Tue, 7 Apr 2009 12:49:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190797 - stable/7/usr.sbin/jexec X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Apr 2009 12:49:52 -0000 Author: ru Date: Tue Apr 7 12:49:50 2009 New Revision: 190797 URL: http://svn.freebsd.org/changeset/base/190797 Log: MFC: - Add missing include. - 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 proper diagnostic message. Approved by: re (kib) Modified: stable/7/usr.sbin/jexec/ (props changed) stable/7/usr.sbin/jexec/jexec.c Modified: stable/7/usr.sbin/jexec/jexec.c ============================================================================== --- stable/7/usr.sbin/jexec/jexec.c Tue Apr 7 12:39:55 2009 (r190796) +++ stable/7/usr.sbin/jexec/jexec.c Tue Apr 7 12:49:50 2009 (r190797) @@ -29,8 +29,10 @@ #include #include +#include #include + #include #include #include @@ -117,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()"); @@ -172,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 { \