busybox which does not generate proper return codes
David Douthitt
ssrat at mailbag.com
Mon Oct 23 16:24:57 UTC 2000
Package: busybox
Version: 0.47
The symptoms look like this:
# which foo
# echo $?
0
# which tcpdump
/sbin/tcpdump
# echo $?
0
#
The first return value should be 1. I tackled some code, and this is
what I came up with:
*** which.c.orig Mon Oct 23 11:12:15 2000
--- which.c Mon Oct 23 11:22:42 2000
***************
*** 28,34 ****
{
char *path_list, *path_n;
struct stat filestat;
! int i, count=1;
if (argc <= 1 || **(argv + 1) == '-')
usage(which_usage);
--- 28,34 ----
{
char *path_list, *path_n;
struct stat filestat;
! int i, found, count=1, retval;
if (argc <= 1 || **(argv + 1) == '-')
usage(which_usage);
***************
*** 45,53 ****
--- 45,55 ----
count++;
}
+ retval=TRUE;
while(argc-- > 0) {
path_n = path_list;
argv++;
+ found=FALSE;
for (i = 0; i < count; i++) {
char buf[strlen(path_n)+1+strlen(*argv)];
strcpy (buf, path_n);
***************
*** 57,68 ****
&& filestat.st_mode & S_IXUSR)
{
printf ("%s\n", buf);
break;
}
path_n += (strlen(path_n) + 1);
}
}
! return(TRUE);
}
/*
--- 59,74 ----
&& filestat.st_mode & S_IXUSR)
{
printf ("%s\n", buf);
+ found=TRUE;
break;
}
path_n += (strlen(path_n) + 1);
}
+ if (found == FALSE) {
+ retval=FALSE;
+ }
}
! return(retval);
}
/*
This was taken against current CVS sources...
--
David Douthitt
UNIX Systems Administrator
HP-UX, Linux, Unixware
ddouthitt at mennonite.minister.net
---------------------------------------
Received: (at 1066-close) by bugs.lineo.com; 18 Nov 2000 01:17:54 +0000
More information about the busybox
mailing list