Subject: bin/20984: whereis returned value
To: None <gnats-bugs@gnats.netbsd.org>
From: Gabriel Gonzalez <gabriel@laptop.pear-labs.org>
List: netbsd-bugs
Date: 04/03/2003 14:39:39
>Number:         20984
>Category:       bin
>Synopsis:       whereis returned value
>Confidential:   yes
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 03 03:43:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Gabriel Gonzalez
>Release:        NetBSD 1.6.1_RC3
>Organization:
	
>Environment:
	
	
System: NetBSD laptop 1.6.1_RC3 NetBSD 1.6.1_RC3 (GENERIC) #0: Mon Mar 31 04:58:00 UTC 2003 autobuild@tgm.daemon.org:/autobuild/netbsd-1-6/i386/OBJ/autobuild/netbsd-1-6/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
	When a searched command isn't in paths, the returned value is 0.
	I think it should be a non 0 value since the invoked command didn't finish successfully.
	
>How-To-Repeat:
$ whereis abcdefghijkl
$ echo $?
0
>Fix:
	The patch fix this little problem in the following way:
	a) if all commands were found in some paths return 0;
	b) if not all requested commands were found then return 1;
	c) if none of requested commands were found then return 2;

Index: src/usr.bin/whereis/whereis.c
===================================================================
RCS file: /cvsroot/src/usr.bin/whereis/whereis.c,v
retrieving revision 1.11
diff -u -r1.11 whereis.c
--- src/usr.bin/whereis/whereis.c	11 Jun 2002 06:06:21 -0000	1.11
+++ src/usr.bin/whereis/whereis.c	2 Apr 2003 11:51:40 -0000
@@ -69,7 +69,7 @@
 	size_t len;
 	int ch, sverrno, mib[2];
 	char *p, *t, *std, path[MAXPATHLEN];
-	int useenvpath = 0;
+	int useenvpath = 0, found = 0;
 
 	while ((ch = getopt(argc, argv, "p")) != -1)
 		switch (ch) {
@@ -120,13 +120,15 @@
 				if (strlen(t) == 0)
 					t = ".";
 			(void)snprintf(path, sizeof(path), "%s/%s", t, *argv);
-			if (!stat(path, &sb))
+			if (!stat(path, &sb)) {
 				(void)printf("%s\n", path);
+				found ++;
+			}
 			if (p == NULL)
 				break;
 		}
-
-	return (0);
+	
+	return ((found == 0) ? 2 : ((found == argc) ? 0 : 1));
 }
 
 void
	
>Release-Note:
>Audit-Trail:
>Unformatted: