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

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

 



Hi

Some time ago I tried to send that patch to the ML, but it seems to be blocked, so I retry.

Cheers,
Peter

-------- Original Message --------
Subject: 	[PATCH] whereis: removing hard-coded binary paths
Date: 	Tue, 10 Aug 2010 03:15:32 +0200
From: 	Peter Reineke <preineke@xxxxxxx>
To: 	util-linux-ng@xxxxxxxxxxxxxxx



Hi,

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

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


[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