Re: Fwd: [PATCH] whereis: removing hard-coded binary paths

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hi Peter,

On Tue, Aug 24, 2010 at 07:43:22PM +0200, Peter Reineke wrote:
> This is gonna fix a bug in whereis, already documented in the man page,  
> however the paths to the manpage and source dirs still are hard-coded:
>
> Reading PATH variable instead of relying on hard-coded binary paths

 thanks for the patch, but I have doubts that your solution is
 acceptable. The current bindirs array contains directories that are
 not in usual $PATH variable, try:

     $ whereis stdlib
    stdlib: /usr/include/stdlib.h

 I think the ideal solution is to add missing directories from PATH to
 the array rather than remove the array at all.

 Note that your coding style is not compatible with the rest of
 whereis.c or with kernel coding style.

    Karel

>
> Signed-off-by: Peter Reineke<preineke@xxxxxxx>
> ---
> diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
> index 931ff77..c602e19 100644
> --- a/misc-utils/whereis.c
> +++ b/misc-utils/whereis.c
> @@ -57,62 +57,9 @@ void findv(char **, int, char *);
>   void find(char **, char *);
>   void findin(char *, char *);
>   int itsit(char *, char *);
> +char **get_path();
>
> -static char *bindirs[] = {
> -   "/bin",
> -   "/usr/bin",
> -   "/sbin",
> -   "/usr/sbin",
> -   "/etc",
> -   "/usr/etc",
> -   "/lib",
> -   "/usr/lib",
> -   "/lib64",
> -   "/usr/lib64",
> -   "/usr/games",
> -   "/usr/games/bin",
> -   "/usr/games/lib",
> -   "/usr/emacs/etc",
> -   "/usr/lib/emacs/*/etc",
> -   "/usr/TeX/bin",
> -   "/usr/tex/bin",
> -   "/usr/interviews/bin/LINUX",
> -
> -   "/usr/X11R6/bin",
> -   "/usr/X386/bin",
> -   "/usr/bin/X11",
> -   "/usr/X11/bin",
> -   "/usr/X11R5/bin",
> -
> -   "/usr/local/bin",
> -   "/usr/local/sbin",
> -   "/usr/local/etc",
> -   "/usr/local/lib",
> -   "/usr/local/games",
> -   "/usr/local/games/bin",
> -   "/usr/local/emacs/etc",
> -   "/usr/local/TeX/bin",
> -   "/usr/local/tex/bin",
> -   "/usr/local/bin/X11",
> -
> -   "/usr/contrib",
> -   "/usr/hosts",
> -   "/usr/include",
> -
> -   "/usr/g++-include",
> -
> -   "/usr/ucb",
> -   "/usr/old",
> -   "/usr/new",
> -   "/usr/local",
> -   "/usr/libexec",
> -   "/usr/share",
> -
> -   "/opt/*/bin",
> -
> -	0
> -};
> -
> +static char **bindirs;
>   static char *mandirs[] = {
>   	"/usr/man/*",
>   	"/usr/share/man/*",
> @@ -152,7 +99,7 @@ main(int argc, char **argv) {
>   	setlocale(LC_ALL, "");
>   	bindtextdomain(PACKAGE, LOCALEDIR);
>   	textdomain(PACKAGE);
> -
> +	bindirs = get_path();	
>   	argc--, argv++;
>   	if (argc == 0) {
>   usage:
> @@ -396,3 +343,24 @@ itsit(char *cp, char *dp) {
>   	}
>   	return (0);
>   }
> +
> +char **get_path()
> +{
> +	char *path;
> +	path = getenv("PATH");
> +        char *buf = strdup(path);
> +	char *cp;
> +	int count=1; // there is one entry more than there are colons
> +	for(cp=buf;*cp;cp++)
> +		if (*cp==':') count++;
> +	char **dirs = malloc(sizeof(char*)*(count+1)); // another entry for the 0
> +	char **dirp = dirs;
> +	*(dirp++) = buf;
> +	for(cp=buf;*cp;cp++)
> +		if (*cp==':') {
> +			*cp = 0;
> +			*(dirp++) = cp+1;
> +		}
> +	dirp = 0;	
> +	return dirs;
> +}
>
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux