summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-03-11 04:30:22 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-03-11 04:30:22 +0000
commitdb832097f4874722934efa9ebe9f11ae85462991 (patch)
treefd46c592075f5980f6ddbf79504bbc5a49054bde /usr.bin
parentbcc53476188646a13fa8afe78d5b87a831c1cc08 (diff)
The -a option shouldn't change the exit status
Patch from David Julio (david.a.julio at gmail.com)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/which/which.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/usr.bin/which/which.c b/usr.bin/which/which.c
index 220d082c93a..782e94a96a7 100644
--- a/usr.bin/which/which.c
+++ b/usr.bin/which/which.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: which.c,v 1.16 2010/05/31 14:01:49 sobrado Exp $ */
+/* $OpenBSD: which.c,v 1.17 2011/03/11 04:30:21 guenther Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -55,11 +55,7 @@ main(int argc, char *argv[])
(void)setlocale(LC_ALL, "");
- if (argc == 1)
- usage();
-
- /* Don't accept command args but check since old whereis(1) used to */
- while ((ch = getopt(argc, argv, "a")) != -1) {
+ while ((ch = getopt(argc, argv, "a")) != -1)
switch (ch) {
case 'a':
allmatches = 1;
@@ -67,7 +63,11 @@ main(int argc, char *argv[])
default:
usage();
}
- }
+ argc -= optind;
+ argv += optind;
+
+ if (argc == 0)
+ usage();
/*
* which(1) uses user's $PATH.
@@ -98,11 +98,11 @@ main(int argc, char *argv[])
if (setuid(geteuid()))
err(1, "Can't set uid to %u", geteuid());
- for (n = optind; n < argc; n++)
+ for (n = 0; n < argc; n++)
if (findprog(argv[n], path, progmode, allmatches) == 0)
notfound++;
- exit((notfound == 0) ? 0 : ((notfound == argc - 1) ? 2 : 1));
+ exit((notfound == 0) ? 0 : ((notfound == argc) ? 2 : 1));
}
int