From owner-svn-src-head@FreeBSD.ORG Mon Apr 14 16:43:37 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7AF78E49; Mon, 14 Apr 2014 16:43:37 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4E0721D78; Mon, 14 Apr 2014 16:43:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3EGhbht028744; Mon, 14 Apr 2014 16:43:37 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3EGhbMn028743; Mon, 14 Apr 2014 16:43:37 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201404141643.s3EGhbMn028743@svn.freebsd.org> From: Eitan Adler Date: Mon, 14 Apr 2014 16:43:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264462 - head/usr.bin/units X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Apr 2014 16:43:37 -0000 Author: eadler Date: Mon Apr 14 16:43:36 2014 New Revision: 264462 URL: http://svnweb.freebsd.org/changeset/base/264462 Log: units(1): support reading multiple units files GNU units(1) supports reading up to 25 -f options. We support an arbitrary number. Modified: head/usr.bin/units/units.c Modified: head/usr.bin/units/units.c ============================================================================== --- head/usr.bin/units/units.c Mon Apr 14 16:31:56 2014 (r264461) +++ head/usr.bin/units/units.c Mon Apr 14 16:43:36 2014 (r264462) @@ -153,8 +153,6 @@ readunits(const char *userfile) errx(1, "can't find units file '%s'", UNITSFILE); } } - if (cap_enter() < 0 && errno != ENOSYS) - err(1, "unable to enter capability mode"); cap_rights_init(&unitfilerights, CAP_READ, CAP_FSTAT); if (cap_rights_limit(fileno(unitfile), &unitfilerights) < 0 && errno != ENOSYS) @@ -693,19 +691,23 @@ main(int argc, char **argv) const char * havestr; const char * wantstr; int optchar; - char *userfile; bool quiet; + bool readfile; History *inhistory; EditLine *el; HistEvent ev; int inputsz; - userfile = NULL; quiet = false; + readfile = false; while ((optchar = getopt(argc, argv, "Vqf:")) != -1) { switch (optchar) { case 'f': - userfile = optarg; + readfile = true; + if (strlen(optarg) == 0) + readunits(NULL); + else + readunits(optarg); break; case 'q': quiet = true; @@ -719,8 +721,8 @@ main(int argc, char **argv) } } - if (optind != argc - 2 && optind != argc) - usage(); + if (!readfile) + readunits(NULL); inhistory = history_init(); el = el_init(argv[0], stdin, stdout, stderr); @@ -732,8 +734,9 @@ main(int argc, char **argv) history(inhistory, &ev, H_SETSIZE, 800); if (inhistory == 0) err(1, "Could not initalize history"); - - readunits(userfile); + + if (cap_enter() < 0 && errno != ENOSYS) + err(1, "unable to enter capability mode"); if (optind == argc - 2) { havestr = argv[optind];