Subject: bin/3363: whereis searches the kernel path
To: None <gnats-bugs@gnats.netbsd.org>
From: None <rickb@iaw.on.ca>
List: netbsd-bugs
Date: 03/19/1997 21:56:04
>Number:         3363
>Category:       bin
>Synopsis:       whereis searches the kernel path
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 19 19:05:01 1997
>Last-Modified:
>Originator:     Rick Byers
>Organization:
Internet Access Worldwide
	
>Release:        March 16, 97
>Environment:
	
System: NetBSD rickb.iaw.on.ca 1.2C NetBSD 1.2C (RICKB) #2: Sun Mar 16 22:11:38 EST 1997 root@rickb.iaw.on.ca:/usr/src/sys/arch/i386/compile/RICKB i386


>Description:
Whereis searches the kernel's path by default, which is pretty lame IMHO.  
I've added a quick -p option to whereis which will make it search the users 
path as specified in their environment instead.
	
>How-To-Repeat:
Try to "whereis" someing in /local/bin
	
>Fix:
Apply the following patch.
*** whereis.c.orig	Thu Jan 23 07:26:13 1997
--- whereis.c	Wed Mar 19 21:32:03 1997
***************
*** 68,76 ****
  	size_t len;
  	int ch, sverrno, mib[2];
  	char *p, *t, *std, path[MAXPATHLEN];
  
! 	while ((ch = getopt(argc, argv, "")) != -1)
  		switch (ch) {
  		case '?':
  		default:
  			usage();
--- 68,81 ----
  	size_t len;
  	int ch, sverrno, mib[2];
  	char *p, *t, *std, path[MAXPATHLEN];
+ 	char useenvpath=0;
  
! 	while ((ch = getopt(argc, argv, "p")) != -1)
  		switch (ch) {
+ 		case 'p':
+ 			useenvpath=1;	/* use environment for PATH */
+ 			break;
+ 
  		case '?':
  		default:
  			usage();
***************
*** 82,100 ****
  		usage();
  
  	/* Retrieve the standard path. */
! 	mib[0] = CTL_USER;
! 	mib[1] = USER_CS_PATH;
! 	if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1)
! 		return (-1);
! 	if (len == 0)
! 		err(1, "user_cs_path: sysctl: zero length\n");
! 	if ((std = malloc(len)) == NULL)
! 		err(1, NULL);
! 	if (sysctl(mib, 2, std, &len, NULL, 0) == -1) {
! 		sverrno = errno;
! 		free(std);
! 		errno = sverrno;
! 		err(1, "sysctl: user_cs_path");
  	}
  
  	/* For each path, for each program... */
--- 87,113 ----
  		usage();
  
  	/* Retrieve the standard path. */
! 	if( useenvpath )
! 	{
! 		if( (std = getenv("PATH"))==NULL )
! 			err(1, "getenv: PATH" );
! 	}
! 	else
! 	{
! 		mib[0] = CTL_USER;
! 		mib[1] = USER_CS_PATH;
! 		if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1)
! 			return (-1);
! 		if (len == 0)
! 			err(1, "user_cs_path: sysctl: zero length\n");
! 		if ((std = malloc(len)) == NULL)
! 			err(1, NULL);
! 		if (sysctl(mib, 2, std, &len, NULL, 0) == -1) {
! 			sverrno = errno;
! 			free(std);
! 			errno = sverrno;
! 			err(1, "sysctl: user_cs_path");
! 		}
  	}
  
  	/* For each path, for each program... */
***************
*** 122,127 ****
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: whereis program [...]\n");
  	exit (1);
  }
--- 135,140 ----
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: whereis [-p] program [...]\n");
  	exit (1);
  }
*** whereis.1.orig	Fri Oct 13 22:39:12 1995
--- whereis.1	Wed Mar 12 09:48:30 1997
***************
*** 41,46 ****
--- 41,47 ----
  .Nd locate programs
  .Sh SYNOPSIS
  .Nm whereis
+ .Op Fl p
  .Op Ar program ...
  .Sh DESCRIPTION
  The
***************
*** 48,58 ****
  utility checks the standard binary directories for the specified programs,
  printing out the paths of any it finds.
  .Pp
! The path searched is the string returned by the
  .Xr sysctl 8
  utility for the
  .Dq user.cs_path
! string.
  .Sh SEE ALSO
  .Xr sysctl 8
  .Sh COMPATIBILITY
--- 49,62 ----
  utility checks the standard binary directories for the specified programs,
  printing out the paths of any it finds.
  .Pp
! The default path searched is the string returned by the
  .Xr sysctl 8
  utility for the
  .Dq user.cs_path
! string.  If the 
! .Nm -p 
! option is specified, then the value of the environment
! variable PATH is used instead.
  .Sh SEE ALSO
  .Xr sysctl 8
  .Sh COMPATIBILITY

>Audit-Trail:
>Unformatted: