Commit Graph

66 Commits

Author SHA1 Message Date
Karel Zak 403cd1086e namei: simplify code
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-17 13:23:53 +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 1405658822 nls: remove translation strings
While looking earlier commit I noticed everything but formatting was removed
from a message in namei.c file.  That inspired me to look if there are more
strings that does not need translation project attention.  This change
removes at least some of them, if not all.

Reference: e19cc7b65b
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-28 13:36:38 +02:00
Karel Zak e19cc7b65b namei: provide more usable error message on lstat() error
Addresses: https://github.com/karelzak/util-linux/issues/608
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-27 13:30:16 +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 b305445495 misc: consolidate all --help option descriptions
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:36 +02:00
Ruediger Meier 5118d1be2a misc: never use usage(ERROR)
We are using better/shorter error messages and somtimes
also errtryhelp().

Here we fix all cases where the usage function took
an int argument for exit_code.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Ruediger Meier 06c8aec38c lib: define LOGIN_NAME_MAX fallback
LOGIN_NAME_MAX was unused in misc-utils/namei.c since 04a5cb58.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:14 +01:00
Ruediger Meier b0b24b11f8 lib: rename strmode() and setmode()
On BSD they are part of the standard C library.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Karel Zak 04a5cb58b6 namei: move icache to lib/
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-27 13:56:01 +01:00
Benno Schulenberg fc14ceba5e textual: grammarize and harmonize the stat error message
The message "stat failed %s" seems to say that stat() failed to
do something, or failed to pass a test, but of course it means
that the statting of something failed.  So say so.  Also make
two very similar messages equal to this one.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-02 11:27:10 +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
Sami Kerola db433bf737 textual: use usage() text element macros
Translating these text elements should happen only once, which is
more likely when the text macros are used properly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:26 +02:00
Sami Kerola a587cc5520 textual: use manual tail usage() macro
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:24 +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
Sami Kerola cd80445017 namei: align missing files with rest of the print out
This change should make namei output more readable when multiple
arguments are supplied.

The old:

$ namei -l /usr/foo
f: /usr/foo
drwxr-xr-x root root /
drwxr-xr-x root root usr
foo - No such file or directory

The new:

$ namei -l /usr/foo
f: /usr/foo
drwxr-xr-x root root /
drwxr-xr-x root root usr
                     foo - No such file or directory

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-12-02 10:59:27 +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
Karel Zak 7a591a1fb5 namei: don't care about xasprintf() return code
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 12:12:25 +01:00
Karel Zak 38efd1e2b7 namei: remove dead code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-07 11:39:38 +02:00
Sami Kerola add1b8afd0 translation: unify stat error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
maximilian attems adddfd37a1 misc-utils: cleanup unused strings.h includes
Noticed on klibc building.

Signed-off-by: maximilian attems <max@stro.at>
2012-05-23 10:31:12 +02:00
Karel Zak 89394013f6 namei: fix relative symlinks evaluation
Fedora 17 (/bin is symlink to /usr/bin):

	[root@intel ~]# /bin/namei /bin/namei
	f: /bin/namei
	 d /
	 l bin -> usr/bin
	usr - No such file or directory

Reported-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-20 15:06:57 +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
Sami Kerola 6f312c8957 xalloc: use xasprintf in all files
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-18 14:28:05 +01:00
Karel Zak 54b6adf344 namei: more robust add_it() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-31 14:04:03 +01:00
Karel Zak 54f0728944 namei: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 12:33:56 +02:00
Sami Kerola 5a0d925569 namei: fix to argument handling
Missing pathname argument can only be checked after options are
parsed. Earlier for example 'namei -l' print nothing and was
successful.

The option parsing is changed to be less POSIXLY_CORRECT and
continue if nonoption argument is found, which allows users to
define options and arguments in the order they prefer.

Unknown short options, which earlier matched case '?' that was
help option alias, are now made to indicate failure in return
value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-25 12:37:37 +02:00
Sami Kerola b977951749 namei: use xalloc.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-25 12:37:37 +02:00
Sami Kerola 64718fe7d9 namei: add --version option
Add to namei.1 man also the --help option along with the new
--version.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-25 12:37:04 +02:00
Karel Zak 8fec558bc3 namei: remove unused variable
namei.c: In function ‘print_namei’:
namei.c:368:16: warning: variable ‘prev’ set but not used [-Wunused-but-set-variable]

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-08 12:18:49 +02:00
Karel Zak eb9a65bb54 lsblk: use ssize_t for readlink() return code
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-11 10:49:08 +01:00
Karel Zak 6c7d5ae9a2 move struct option to .rodata
It does not make sense to have writable large arrays of "struct
option" on the stack.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-03 15:00:30 +01:00
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2011-02-14 17:45:24 +01:00
Karel Zak 601d12fb10 rename util-linux-ng back to util-linux
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-30 11:41:59 +01:00
Karel Zak ce877f2d16 lib: [strutils] move strmode() from namei.c to strutils.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-24 17:08:32 +01:00
Davidlohr Bueso 87f3feac71 misc-utils: use new xmalloc() wrapper
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-10-21 10:31:50 +02:00
Sami Kerola c49e31f4ee namei: parse all path arguments when an optarg path will fail
Old implementation of namei listed path all the way to non-existing
file or directory, something like:

f: /usr/bin/nxdir/file
 d /
 d usr
 d bin
 ? nxdir - No such file or directory (2)

whiles the current implementation prints:

namei: failed to stat: /usr/bin/nxdir/file: No such file or directory

The new output it's not helpful. I am especially interested see where
the path is broken when a path is symlink to other path with symlink,
and few more like that, and something somewhere is broken.

[kzak@redhat.com: - coding style changes]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-01 00:36:45 +02:00
Davidlohr Bueso bf13602c24 namei: fix memory leak in namei(1)
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-07-29 17:50:46 +02:00
Karel Zak fd03d92da8 namei: use c.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-16 01:44:33 +02:00
Karel Zak c21e7023ca namei: better mount points detection
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-09 16:43:35 +02:00
Karel Zak a439d194fb namei: gater information about / (root)
$ ll -d /foo
	drwxr-xr-x 2 kzak kzak 4096 2009-10-07 01:23 /foo

old version:

	$ namei -l /foo
	f: /foo
	Segmentation fault

new version:

	$ namei -l /foo
	f: /foo
	drwxr-xr-x root root /
	drwxr-xr-x kzak kzak foo

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-07 01:37:57 +02:00
Karel Zak d1dca71078 namei: fix alone symlink evaluation
$ mkdir aaa
	$ ln -s aaa mylink

old version:

	$ namei mylink
	namei: could not stat 'mylink/aaa': No such file or directory

new version:

        $ namei mylink
	f: mylink
	 l mylink -> aaa
	   d aaa

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-07 01:34:36 +02:00
Karel Zak c3ecdb3ea4 namei: add --vertical option
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-01-27 14:48:32 +01:00
Karel Zak 922a121b60 namei: don't duplicate '/' directory
sake@lelux ~ namei -l /
f: /
 drwxr-xr-x root root /
 drwxr-xr-x root root

The duplicate '/' directory is unexpected behavior.

Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-01-26 11:36:31 +01:00
Karel Zak f7ed29a7b6 namei: fix buffer overflow
$ ./namei  /usr/bin/java
 *** glibc detected *** ./namei: free(): invalid next size (fast): 0x00000000018e5070 ***
 [...]
 Aborted

Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-01-06 14:26:12 +01:00
Karel Zak 4cfcf09b33 namei: add --owners and --long options
Added file owner and group name printing support. The groupnames and
usernames are cached to avoid an extra overhead. This implementation
does not use fixed width of user/group name columns.

$ namei -l /var/www/cgi-bin
f: /var/www/cgi-bin
 drwxr-xr-x root root /
 drwxr-xr-x root root var
 drwxr-xr-x root root www
 drwxr-xr-x root root cgi-bin

Signed-off-by: Karel Zak <kzak@redhat.com>
2008-11-13 23:25:59 +01:00
Karel Zak c84a633a92 namei: new re-written version
This new version:
 * not based on chdir()
 * implemented without recursion (does not depend on stack size)
 * list of directories is stored in allocated memory (the code is
   extendable with new functionality (e.g. show usernames, groupnames,
   selunux contexts, ...).
 * supports long command line options
 * adds a new command line option:
     -n, --nosymlinks    don't follow symlinks

Signed-off-by: Karel Zak <kzak@redhat.com>
2008-11-13 23:25:46 +01:00