Return non-zero exit status if the listed programs aren't found.

Submitted by Gabriel Gonzalez in PR bin/20984
I deviated from the patch by returning 2 if only some programs were
located and 3 if none were. The submitted patch returned 1 and 2,
respectively, and 1 is already used for general error.
This commit is contained in:
perry 2003-04-03 18:16:45 +00:00
parent 2f01db86ba
commit df28067f6e
2 changed files with 16 additions and 8 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: whereis.1,v 1.12 2001/12/01 16:43:27 wiz Exp $ .\" $NetBSD: whereis.1,v 1.13 2003/04/03 18:16:45 perry Exp $
.\" .\"
.\" Copyright (c) 1993 .\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,7 @@
.\" .\"
.\" @(#)whereis.1 8.3 (Berkeley) 4/27/95 .\" @(#)whereis.1 8.3 (Berkeley) 4/27/95
.\" .\"
.Dd April 27, 1995 .Dd April 3, 2003
.Dt WHEREIS 1 .Dt WHEREIS 1
.Os .Os
.Sh NAME .Sh NAME
@ -61,7 +61,13 @@ option is specified, then the value of the environment
variable variable
.Ev PATH .Ev PATH
is used instead. is used instead.
.Sh EXIT STATUS
The
.Nm
utility exits 0 on success, 1 on general error, 2 if only some
programs were located and 3 if none were.
.Sh SEE ALSO .Sh SEE ALSO
.Xr whatis 1 ,
.Xr which 1 , .Xr which 1 ,
.Xr sysctl 8 .Xr sysctl 8
.Sh COMPATIBILITY .Sh COMPATIBILITY

View File

@ -1,4 +1,4 @@
/* $NetBSD: whereis.c,v 1.11 2002/06/11 06:06:21 itojun Exp $ */ /* $NetBSD: whereis.c,v 1.12 2003/04/03 18:16:45 perry Exp $ */
/*- /*-
* Copyright (c) 1993 * Copyright (c) 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1993\n\
#if 0 #if 0
static char sccsid[] = "@(#)whereis.c 8.3 (Berkeley) 5/4/95"; static char sccsid[] = "@(#)whereis.c 8.3 (Berkeley) 5/4/95";
#endif #endif
__RCSID("$NetBSD: whereis.c,v 1.11 2002/06/11 06:06:21 itojun Exp $"); __RCSID("$NetBSD: whereis.c,v 1.12 2003/04/03 18:16:45 perry Exp $");
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -69,7 +69,7 @@ main(argc, argv)
size_t len; size_t len;
int ch, sverrno, mib[2]; int ch, sverrno, mib[2];
char *p, *t, *std, path[MAXPATHLEN]; char *p, *t, *std, path[MAXPATHLEN];
int useenvpath = 0; int useenvpath = 0, found = 0;
while ((ch = getopt(argc, argv, "p")) != -1) while ((ch = getopt(argc, argv, "p")) != -1)
switch (ch) { switch (ch) {
@ -120,13 +120,15 @@ main(argc, argv)
if (strlen(t) == 0) if (strlen(t) == 0)
t = "."; t = ".";
(void)snprintf(path, sizeof(path), "%s/%s", t, *argv); (void)snprintf(path, sizeof(path), "%s/%s", t, *argv);
if (!stat(path, &sb)) if (!stat(path, &sb)) {
(void)printf("%s\n", path); (void)printf("%s\n", path);
found++;
}
if (p == NULL) if (p == NULL)
break; break;
} }
return (0); return ((found == 0) ? 3 : ((found == argc) ? 0 : 2));
} }
void void