diff options
author | eadler <eadler@FreeBSD.org> | 2014-04-14 16:43:36 +0000 |
---|---|---|
committer | eadler <eadler@FreeBSD.org> | 2014-04-14 16:43:36 +0000 |
commit | 25d806296075b2fe0216ad9aa0de732862a2edbe (patch) | |
tree | 4f09ef42f30a619c97be97fbc7ca8528f604dd80 /usr.bin | |
parent | 8a0ac6f17bcd1041b6cba5955abb200ca2027ffa (diff) | |
download | FreeBSD-src-25d806296075b2fe0216ad9aa0de732862a2edbe.zip FreeBSD-src-25d806296075b2fe0216ad9aa0de732862a2edbe.tar.gz |
units(1): support reading multiple units files
GNU units(1) supports reading up to 25 -f options. We support an arbitrary
number.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/units/units.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.bin/units/units.c b/usr.bin/units/units.c index df2913f..0ec77f6 100644 --- a/usr.bin/units/units.c +++ b/usr.bin/units/units.c @@ -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]; |