From: Sami Kerola Date: Sat, 16 Mar 2013 20:12:49 +0000 (+0000) Subject: whereis: add search scope listing option X-Git-Tag: v2.23-rc1~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3bfb96365dc7a7971f4cc941e95e1ce0d1f288c7;p=thirdparty%2Futil-linux.git whereis: add search scope listing option Mostly useful when debugging why the command does, or does not, work. Signed-off-by: Sami Kerola Signed-off-by: Karel Zak --- diff --git a/misc-utils/whereis.1 b/misc-utils/whereis.1 index 86e6a39b66..9b33999c48 100644 --- a/misc-utils/whereis.1 +++ b/misc-utils/whereis.1 @@ -91,7 +91,16 @@ be used when any of the or .BR \-S options is used. - +.IP "\fB\-l" +Output list of effective lookup paths the +.B whereis +is using. When non of +.BR \-B , +.BR \-M , +or +.BR \-S +is specified the option will out hard coded paths that the command was +able to find on system. .SH EXAMPLE To find all files in .B /usr/bin diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c index 97ec45cb28..0f14267f3e 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -176,6 +176,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) " -s search only for sources\n" " -S define sources lookup path\n" " -u search for unusual entries\n" + " -l output effective lookup paths\n" " -V output version information and exit\n" " -h display this help and exit\n\n"), out); @@ -436,6 +437,29 @@ static void lookup(const char *pattern, struct wh_dirlist *ls, int want) return; } +static void list_dirlist(struct wh_dirlist *ls) +{ + while (ls) { + if (ls->path) { + switch (ls->type) { + case BIN_DIR: + printf("bin: "); + break; + case MAN_DIR: + printf("man: "); + break; + case SRC_DIR: + printf("src: "); + break; + default: + abort(); + } + printf("%s\n", ls->path); + } + ls = ls->next; + } +} + int main(int argc, char **argv) { struct wh_dirlist *ls = NULL; @@ -515,6 +539,9 @@ int main(int argc, char **argv) case 's': want = want == ALL_DIRS ? SRC_DIR : want | SRC_DIR; break; + case 'l': + list_dirlist(ls); + break; case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; @@ -526,6 +553,8 @@ int main(int argc, char **argv) } } + + DBG(printf("DONE")); free_dirlist(&ls, ALL_DIRS); return EXIT_SUCCESS; }