Commit Graph

70 Commits

Author SHA1 Message Date
Samanta Navarro 653f672ab6 whereis: filter bin, man and src differently
Consider "s." prefixes for source code files only (even though I do not
know which VCS does that), compression suffixes for manual pages and
strict matching for executables.

Calling "whereis python3" is kind of okay to return python3.8 next to
python3, but python3.8-config is not the same tool as python3.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 117ddbeedc whereis: do not strip suffixes
The whereis implementations of FreeBSD, macOS, NetBSD, and OpenBSD do
not strip suffixes. Although whereis is not a POSIX tool and has no
shared standard, even its manual page indicates that the supplied names
are command names.

Commands do not have a suffix on Linux systems.

Stripping suffixes actually leads to issues with tools like fsck.ext4,
since fsck.ext4 is not the same tool as fsck and definitely not the same
tool as fsck.minix.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro d95ee9fd75 whereis: do not ignore trailing numbers
The commands diff and diff3 are so distinct that their manual pages
should not be mixed in whereis output.

Theoretically this works for commands and binaries with links to each
other, e.g. gpg and gpg2, but if gpg is version 1 and gpg2 is version 2
then manual pages do not match either.

Also the while loop does not decrement "i" while incrementing "dp". The
effect of this is that the output of whereis depends on manual pages
being compressed or not.

The easiest solution is to not ignore trailing numbers.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 74b7c01fa6 whereis: add lib32 directories
These directories are sometimes used by Linux distributions.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 6065250a4d whereis: support zst compressed man pages
Add zst as extension for manual pages. Current version of man-db
supports zst extension out of the box.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro cd4142f7c3 whereis: fix out of boundary read
If whereis encounters a short file name then an out of boundary
read can occur.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Karel Zak a2761af42b whereis: make subdirs scan more robust
* call strchr() only once
* avoid things like strcat(buf, strchr(dir, '*') + 1)
* make it more readable
* improve debug messages

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-23 13:53:00 +02:00
Karel Zak aa75c5eb74 whereis: use xstrncpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 12:59:02 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Karel Zak 9ed2117897 whereis: search in /(s)bin before /usr/lib
Addresses: https://github.com/karelzak/util-linux/issues/741
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-17 11:19:27 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Karel Zak 7468a8d106 whereis: fix typo in debug message
Reported-by: Matthew White <mehw.is.me@inventati.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-14 15:52:57 +01:00
Andreas Henriksson c9ab738706 whereis: include native multiarch path in lib search paths
This includes atleast the native multiarch path in the paths to search.
(Maybe also other multiarch paths should also be searched? But atleast
this is a first step.)

Before this change (on Debian):
$ whereis libc
libc: /usr/share/man/man7/libc.7.gz

After this change:
$ whereis libc
libc: /usr/lib/x86_64-linux-gnu/libc.so /usr/lib/x86_64-linux-gnu/libc.a /usr/share/man/man7/libc.7.gz

Addresses: https://bugs.debian.org/856968
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2017-07-31 13:48:04 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 5aaa966dcd whereis: add --help and --version
We can use errtryhelp() now and never print usage to stderr.
One may improve all these "bad usage" messages.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:34:58 +02:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Boris Egorov 7508d991c5 libblkid/whereis: simplify some conditions [cppcheck]
[misc-utils/whereis.c:466]: (style) Redundant condition: uflag.
'A && (!A || B)' is equivalent to 'A || B'
[libblkid/src/tag.c:373]: (style) Redundant condition: dev.
'A && (!A || B)' is equivalent to 'A || B'

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-25 12:08:50 +02:00
Karel Zak bde76c048a whereis: make "-BMS <dir> -f" more obvious in usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-05 10:31:18 +01:00
Sami Kerola a3d29ee0c7 whereis: tell when mandatory option is missing
The <dirs> list is terminated by any arbitrary option, but to be simple
when none is specified complain about -f being missing.

Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-03-03 19:35:27 +00:00
Karel Zak db0ccb761d whereis: lookup also info docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-02 11:15:47 +01:00
Yuri Chornoivan 6e834d67ee textual: fix various minor typos 2015-01-26 11:38:38 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Karel Zak 819d9a2975 include/debug: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-24 11:19:23 +02:00
Karel Zak f4802c9011 whereis: reset search mask more carefully
# whereis -m cal -M /usr/share/man/man1/ -f ls
 cal: /usr/share/man/man1/cal.1.gz /usr/share/man/man1p/cal.1p.gz
 ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

the -M also resets the search mask, so for 'ls' it returns also
binaries. That's bug. Expected result is:

 # ./whereis -m cal -M /usr/share/man/man1/ -f ls
 cal: /usr/share/man/man1/cal.1.gz /usr/share/man/man1p/cal.1p.gz
 ls: /usr/share/man/man1/ls.1.gz

the search mask has to be sensitive only to -b -m -s options,
otherwise the semantic is pretty messy.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-23 14:29:45 +02:00
Karel Zak 3635f53ca2 whereis: cleanup debug stuff, fix argv[] usage
* use debug stuff from include/debug.h and make whereis(1) sensitive
  to WHEREIS_DEBUG=0xffff mask

* fix problem with argv[] usage

  # whereis -b -m -M /usr/share/man/man1 -B /usr/bin -f gcc
  bin: /usr/local/bin
  gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz

the code ignores "-B" and /usr/bin is interpreted as search pattern,
expected result is:

  # whereis -b -m -M /usr/share/man/man1 -B /usr/bin -f gcc
  gcc: /usr/share/man/man1/gcc.1.gz /usr/bin/gcc

Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=765306
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-23 13:44:00 +02:00
Benno Schulenberg 09af3db48e textual: fix some typos and inconsistencies in various messages
Fixing plain typos, miswordings, inconsistent periods, some missing
angular brackets, and a proper pluralization (even when it involves
a constant, because for some languages the precise value matters).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-07-23 08:56:00 +02:00
Karel Zak 2fa32bea49 Merge branch 'minor-fixes' of git://github.com/kerolasa/lelux-utiliteetit
* 'minor-fixes' of git://github.com/kerolasa/lelux-utiliteetit:
  lscpu: avoid double free
  libsmartcols: avoid variable dereference after release
  libfdisk: do not do the same thing twice in single if statement
  whereis: avoid printing uninitialized string
  setpriv: avoid alloca() use xmalloc() instead
  dmesg: avoid unnecessary variable assignment
  fdisk: avoid code duplication
  mkfs.cramfs: use defined failure name rather than magic value
  fdformat: match variable and print format types
  cfdisk: add braces to ensure operation order
  lscpu: avoid use of bzero() in favor of memset()
  setterm: remove unnecessary variable
  cal: remove unnused structure and definition
  textual: fix some typos
2014-07-14 16:03:48 +02:00
Andreas Henriksson 8a11218213 whereis: fix missing newline on empty results
Running "whereis foo.bar.quux" previously resulted in
printing the "foo.bar:" pattern prefix without any
newline following it.

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2014-07-14 15:49:27 +02:00
Sami Kerola 46ed183613 whereis: avoid printing uninitialized string
The patbuf[] needs to be filled before print out.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-13 18:35:38 +01:00
Karel Zak f84559ee1c whereis: canonicalize directories paths
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-20 11:52:35 +01:00
Sami Kerola ccec32a121 whereis: support MANPATH environment variable
The MANPATH has been around long enough that it can be added to whereis
default search path.

Reference: manpath(1)
Addresses: http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-19 16:09:38 +01:00
Sami Kerola ec3bc7aaf4 whereis: align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-03-19 16:03:19 +01:00
Sami Kerola 3bfb96365d whereis: add search scope listing option
Mostly useful when debugging why the command does, or does not, work.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-19 16:02:32 +01:00
Sami Kerola 9db54a7e08 whereis: rewrite most of the command
The earlier code gave little or no change to fix bugs and improve the
command.  This rewrite attempts to make further patching easier.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Co-Author: Karel Zak <kzak@redhat.com>
2013-03-19 15:44:45 +01:00
Sami Kerola f8bd089b1d a pointer should not be compared to zero [coccinelle]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:15 +01:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Karel Zak e421313dc2 textual: use UTIL_LINUX_VERSION everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-25 12:05:26 +01:00
Benno Schulenberg 095345d07d textual: fix a few typos in some of the usage help texts
Also improve clarity of some other lines of those texts.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:26 +01:00
Karel Zak 63beec6443 whereis: improve readability for analysers
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-07 13:43:49 +02:00
Karel Zak af842d142e whereis: fix shadow declaration
misc-utils/whereis.c:191:7: warning: declaration of 'dirp' shadows a global declaration [-Wshadow]
misc-utils/whereis.c:134:42: warning: shadowed declaration is here [-Wshadow]

Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-26 13:27:06 +02:00
Sami Kerola c05a80ca63 misc-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:56:48 +02:00
Davidlohr Bueso aec5c2a626 misc-utils: fix typos
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-02-24 14:15:39 +01:00
Karel Zak 48a5ed6306 whereis: move token assignment into loop syntax
Reported-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-30 13:19:14 +01:00
Francesco Cosoleto 3c6e035e1a whereis: remove unused value warning
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-09 10:04:24 +01:00
Karel Zak ac9b7477d2 whereis: non-ANSI definition [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-12 16:15:19 +02:00
Karel Zak cc69f339c1 whereis: fix gcc warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-31 11:58:01 +02:00