Commit Graph

11741 Commits

Author SHA1 Message Date
Ruediger Meier 43c960c8fa blockdev: correct man page name in --help
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 15:36:39 +02:00
Karel Zak 07fd6640c8 Merge branch 'path-fixes' of https://github.com/rudimeier/util-linux
* 'path-fixes' of https://github.com/rudimeier/util-linux:
  hwclock: don't ifdef printf arguments
  setpriv: align --help
  tools: add segfault detection for checkusage.sh
  misc: avoid some dead initialization warnings
  lscpu: make clang analyzer happy
  lsmem: fix, using freed memory
  lib/path: add error handling to path_vcreate()
  lib/path: fix crash, pathbuf overflow
2017-06-29 15:29:33 +02:00
Ruediger Meier 3eeaef995b hwclock: don't ifdef printf arguments
This may fails if printf() is macro, introduced in cc7cb070.

clang compiler warnings:

    CC       sys-utils/hwclock.o
  ../sys-utils/hwclock.c:1228:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
  #ifdef __linux__
   ^
  ../sys-utils/hwclock.c:1230:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
  #endif
   ^
  2 warnings generated.

CC: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:04:36 +02:00
Ruediger Meier a4dc44337d setpriv: align --help
This was forgotton during my last cleanup because the build was
auto-disabled on my system.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:04:32 +02:00
Ruediger Meier 66b7469960 tools: add segfault detection for checkusage.sh
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:04:29 +02:00
Ruediger Meier c3ae785433 misc: avoid some dead initialization warnings
Clang analyzer warnings:

Dead store, Dead initialization:

    lib/mbsedit.c:154:8: warning: Value stored to 'in' during its initialization is never read
            char *in = (char *) &c;
                  ^~   ~~~~~~~~~~~

    misc-utils/findmnt-verify.c:129:14: warning: Value stored to 'cn' during its initialization is never read
            const char *cn = tgt;
                        ^~   ~~~
Dead store, Dead increment:

    sys-utils/hwclock.c:1461:2: warning: Value stored to 'argv' is never read
            argv += optind;
            ^       ~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:04:25 +02:00
Ruediger Meier a25fb9e8ec lscpu: make clang analyzer happy
Let read_nodes() work on uninitialized structs to silence these two
warnings:

  CC       sys-utils/lscpu-lscpu.o
warning: Path diagnostic report is not generated. Current output format does not support diagnostics that cross file boundaries. Refer to --analyzer-output for valid output formats
In file included from sys-utils/lscpu.c:63:
./include/xalloc.h:32:21: warning: Call to 'malloc' has an allocation size of 0 bytes
        void *ret = malloc(size);
                    ^~~~~~~~~~~~
sys-utils/lscpu.c:1468:23: warning: Function call argument is an uninitialized value
                desc->nodemaps[i] = path_read_cpuset(maxcpus,
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:04:21 +02:00
Ruediger Meier 81435af3be lsmem: fix, using freed memory
Simply avoiding strdup(). Error handling improved.

This was the Clang Analyzer warning:

    Memory Error, Use-after-free
    sys-utils/lsmem.c:259:3: warning: Use of memory after it is freed
                    err(EXIT_FAILURE, _("Failed to open %s"), path);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:04:18 +02:00
Ruediger Meier f567220b71 lib/path: add error handling to path_vcreate()
Do not operate on truncated/random paths. Note, path_strdup()
can now really return NULL, to be handled in next commit.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:03:49 +02:00
Karel Zak afeb1a8255 tests: explicitly define wipefs outpuit columns
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 13:31:35 +02:00
Karel Zak 050f8e357b tests: update wipefs outputs
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 13:07:10 +02:00
Carlos Santos ccedd0d7b1 column: fix compilation when libc lacks wide-character support
Commit 4762ae9d removed mtsafe_strtok() but left behind calls to wcstok
and wcspbrk. This leads to build failures when libc does not have the
wide-character functions, like some uClibc builds.

Solve the problem by using strtok_r and strpbrk when HAVE_WIDECHAR is
not defined.

Fixes:
  http://autobuild.buildroot.net/results/fd8a1a8e0cef3aeed9588540e8e663664f6b43aa
  http://autobuild.buildroot.net/results/5ad73ea8b471321988c50d80a5e50d4504151dd6
  http://autobuild.buildroot.net/results/04411b7280dc51ecd51236967981a42352bbeb3e

Signed-off-by: Carlos Santos <casantos@datacom.ind.br>
2017-06-29 13:03:43 +02:00
Karel Zak 41d758f82d libmount: use _exit() in <type> handlers
The originally used exit() is bad idea for the shared library.

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 12:58:57 +02:00
Ruediger Meier 1626ce113e docs: correct line(1) deprecation comment
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 12:56:22 +02:00
Ruediger Meier ad553030fb lib/blkdev: remove support for Linux < 2.6
Remove a hack for kernels between  2.4.15 and 2.4.17

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 12:56:22 +02:00
Ruediger Meier 9f3d0fce66 docs: remove some old history from manpages
We assume that users will have a kernel >= 2.6.0 and removel
references to earlier kernels. There are still a few ones
left.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 12:56:22 +02:00
Karel Zak 4c2af16845 uuidgen: improve --help
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 12:40:22 +02:00
Karel Zak 42d2a8b30d wipefs: improve --help
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 12:38:40 +02:00
Karel Zak d9921b2a12 wipefs: use libsmartcols
The old output is horrible and useless when more devices specified.
The old format is also too tricky if more signatures detected. The new
output uses one line for each signature, prefixed by device name.

For example my workstation:

	# wipefs /dev/sda* /dev/sdb*
	DEVICE OFFSET       TYPE UUID                                 LABEL
	sda    0x1fe        PMBR
	sda    0x37e4895e00 gpt
	sda    0x200        gpt
	sda1   0x1fe        vfat F2BC-BFEC                            EFI
	sda1   0x0          vfat F2BC-BFEC                            EFI
	sda1   0x36         vfat F2BC-BFEC                            EFI
	sda2   0x438        ext4 c5490147-2a6c-4c8a-aa1b-33492034f927 BOOT
	sda3   0x438        ext4 196972ad-3b13-4bba-ac54-4cb3f7b409a4 HOME
	sda4   0x438        ext4 d834bc84-0089-4be1-9013-cd8bf35d5ffa ROOT
	sda5   0x438        ext4 e8ce5375-29d4-4e2f-a688-d3bae4b8d162 WINE
	sda6   0xff6        swap 210337c6-f8b5-4d65-aab5-a0f343fa9ad4 SWAP
	sdb    0x200        gpt
	sdb    0x1fe        dos
	sdb1   0x438        ext4 6467a684-0d10-4f61-a301-67bb26934d90

This patch add --noheadings, --json and --output.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 11:59:38 +02:00
Karel Zak e8fd8c6b9b uuidparse: se JSON table name on -J
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 11:07:54 +02:00
Karel Zak 2cd417ea71 wipefs: try another magic strings on -o and -t
The commit 92296e9ba2 introduces "try
all permutations for the same superblock". This feature has to be also
available if -o and -t is specified.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-28 12:08:25 +02:00
Karel Zak 4e60928139 wipefs: add control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-28 11:51:12 +02:00
Karel Zak 193d6f27fb wipefs: don't do step-back if <type> does not match
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-28 10:28:41 +02:00
Karel Zak 92296e9ba2 wipefs: print all signature permutations
The same FS/RAID/PT signature may be detected by more ways and on more
places on the device. The libblkid returns only the first detected
signature by default. This patch use blkid_probe_hide_range() to
re-scan device for all possible permutations of the same signature.

For example the default wipefs(8) output as well as --no-act output will
contains primary as well as backup GPT signature now.

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-28 10:28:41 +02:00
Karel Zak d2b0c6587d libblkid: allow to hide already detected signatures
The libblkid probing functions returns the first successful result of
the filesystem/RAID/PT. Unfortunately, some signatures is possible to
detect by more ways or device may contains more copies (e.g. GPT).

This is no problem when we wipe signatures from the device. In this
case we zeroize on-device signature and re-scan for the signature (by
blkid_probe_step_back()).

The problem is if we want to read all permutations without the device
modification (for example wipefs(8) dry run).

This patch add blkid_probe_hide_range(). The function remove (zeroize)
specified signature from in-memory cached buffers. If the buffer is
later re-used by probing functions then the signature is invisible and
we can try detect another variant of the magic string.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-28 10:28:41 +02:00
Ruediger Meier e230ae7b68 lib/path: fix crash, pathbuf overflow
Before:

$ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)"
Segmentation fault (core dumped)

After:

$ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)"
lscpu: invalid argument to --sysroot: File name too long

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 21:39:35 +02:00
Karel Zak 4fb515f900 setpriv: add --ambient-caps to usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-27 15:10:09 +02:00
Patrick Steinhardt 0c92194eee setpriv: support modifying the set of ambient capabilities
Right now, we do not support modifying the set of ambient capabilities,
which has been introduced quite recently with Linux 4.3. As libcap-ng
does not yet provide any ability to modify this set, we do have to roll
our own support via `prctl`, which is now easy to do due to the
indirections introduced in the preceding commits. We add a new command
line argument "--ambient-caps", which uses the same syntax as both
"--inh-caps" and "--bounding-set" to specify either adding or dropping
capabilities.

This commit also adjusts documentation to mention the newly introduced
ability to modify the ambient capability set.

Based on a patch by Andy Lutomirski.

Reviewed-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-06-27 14:59:19 +02:00
Patrick Steinhardt 05a22eac65 setpriv: support dumping ambient capabilities
Our code dumping owned capabilities does not yet handle ambient
capabilities, which were only recently introduced with Linux 4.3. This
commit implements printing ambient capabilities if they're supported by
the system.

Based on a patch by Andy Lutomirski.

Reviewed-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-06-27 14:59:19 +02:00
Patrick Steinhardt 8a5af72c22 setpriv: proxy function to update capabilities
libcap-ng provides a function to update capabilities with
`capng_update`. As libcap-ng has not yet been updated to enable
modification of ambient capabilities, we cannot use it to update this
set, though. In order to allow easily extending the logic to also handle
ambient capability sets, we create a new function `cap_update`. Right
now, it simply calls out to `capng_update` for all supported capability
types.

Reviewed-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-06-27 14:59:19 +02:00
Patrick Steinhardt 30129e2f58 setpriv: proxy function checking whether a capability is set
The loop in `print_caps` iterates over every capability, checks whether
it is set and, if so, prints out its name. Currently, the checking and
printing is rather intertwined, making it harder to extend the check
whether we own a capability.

Prepare code for the introduction of ambient capabilities by
disentangling the code checking for a capability and printing code. A
new function `has_cap` is introduced and `print_caps` will now simply
call out to it and only handle printing itself. This easily allows to
extend the capability check based on which capability set is queried.

Reviewed-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-06-27 14:59:19 +02:00
Patrick Steinhardt 9e5dd89da6 setpriv: introduce indirection for `capng_type` enum
The capng_type is used to distinguish the different types of capability
sets, that is the effective, inheratibale, permitted capabilities as
well as the capability bounding set. In Linux 4.3, a new set of
capabilities was introduced with ambient capabilities. Unfortunately,
libcap-ng does not provide any support for these kind of capabilities
and as such, we will have to roll our own support.

As a first step, we introduce an indirection for the `capng_type` enum,
allowing us to add the ambient capability type later on. Right now, no
functional change is expected from this change and in fact, each of the
newly introduce enums should have the same value as respective enum of
libcap-ng.

Reviewed-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-06-27 14:59:19 +02:00
Karel Zak d0983208a8 Merge branch 'travis-checkusage' of https://github.com/rudimeier/util-linux 2017-06-27 14:14:57 +02:00
Karel Zak b899fd87bd Merge branch 'help-description' of https://github.com/rudimeier/util-linux
* 'help-description' of https://github.com/rudimeier/util-linux:
  misc: update --help content again
  login: add --help text
  blockdev: improve --help and man page
  misc: consolidate all --help option descriptions
  misc: introduce print_usage_help_options()
  misc: revert to the old USAGE_HELP strings
2017-06-27 14:14:14 +02:00
Ruediger Meier 551b9cd3f9 misc: update --help content again
We change

 -h, --help     display this help and exit
 -V, --version  output version information and exit

to

 -h, --help     display this help
 -V, --version  print version

Some thoughts about this:

  * use "display" for --help because it matches better if we
    would add pager support (like git --help)
  * "print" for --version to be different
  * "this" for --help is important to make clear that running
    --help would not give you any better information than the
    one you see already
  * remove "information and exit" because it's bloat for the
    short-help, everybody knows what it does if it exists

In the manpages we should use the old, longer but more correct
descriptions, inclusive a reminder if --help/--version are only
working when used as the only option. Note the term "version
information" indicates that we don't only print a single version
number.

CC: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:29:37 +02:00
Ruediger Meier 62cd916f1e login: add --help text
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:29:06 +02:00
Ruediger Meier a861538cc8 blockdev: improve --help and man page
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:44 +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 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
Karel Zak 08029093b0 libblkid: remove dead code and blkid_probe_new_value()
The function blkid_probe_new_value() is unnecessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-27 11:26:41 +02:00
Ruediger Meier d1a7c00eae travis: add make checkusage
We will run all built programs with 3 different
options on Linux and OSX.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 08:25:30 +02:00
Ruediger Meier 99267518a6 tools: checkusage can dump all command output
use
$ make CU_DUMP=1 checkusage

for easily reviewing and comparing all output in
  /tmp/checkusage--help
  /tmp/checkusage--version
  /tmp/checkusage--unknownopt

This was a big help when doing all my last usage cleanup.
Actually I used it to dump the original output, edited it
how I would like it, and then changed our programs to match
the wanted output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 08:25:22 +02:00
Ruediger Meier e8e9267f5d tools: ignore unsafe commands in checkusage.sh
These commands behave unusual with --unknownopt.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 08:25:10 +02:00
Karel Zak b768ac6b60 Merge branch 'travis-fix' of https://github.com/rudimeier/util-linux
* 'travis-fix' of https://github.com/rudimeier/util-linux:
  build-sys: fix chown mistake, add checkusage.sh to the dist
2017-06-26 22:42:24 +02:00
Ruediger Meier f2bd688157 uuidparse: fix getopt crash
$ ./uuidparse --unknownopt
Segmentation fault (core dumped)

Hehe, this is the first real bug found by 'make checkusage'.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 22:38:43 +02:00
Ruediger Meier 789ac55e4f misc: revert to the old USAGE_HELP strings
This reverts the include/c.h part of cc7cb070.

As discussed on ml. Our current strings are imported from
coreutils and not too bad. Also the old strings are still
hardcoded at many places.

So let's revert the change, then consolidate these strings
really everywhere and then think again whether and how we
should change them.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 21:04:34 +02:00
Ruediger Meier 22174021f8 build-sys: fix chown mistake, add checkusage.sh to the dist
Sorry, don't know why I reverted fad561b0.

But for travis we need it only in check_nonroot().
check_root() *can* do chown and the check_dist() is handled
by Makefile.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 21:00:09 +02:00
Karel Zak 47ccf06b47 Merge branch 'usage-part2' of https://github.com/rudimeier/util-linux
* 'usage-part2' of https://github.com/rudimeier/util-linux:
  misc: cosmetics, remove argument from usage(FILE*)
  misc: cosmetics, remove argument from usage(int)
  misc: never use usage(stderr)
  misc: never use usage(ERROR)
  misc: cleanup and fix --unknownopt issues
  flock, getopt: write --help to stdout and return 0
  tools: add checkusage.sh
2017-06-26 15:58:37 +02:00
Karel Zak 7fb65db124 script: rename fixtty() to enable_rawmode_tty()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-26 15:30:12 +02:00
Sami Kerola 8198052c9e script: ensure typescript and timing errors do not break terminal
Earlier when typescript file failed new line after the error did not cause
carriage return.  Here is an example how prompt> travels to wrong place:

prompt> script 0500-perms/typescript
Script started, file is 0500-perms/typescript
script: cannot open 0500-perms/typescript: Permission denied
                                                            prompt>

But that wasn't quite as bad as what happen with timing file, that at
failure left terminal to state where a reset(1) run was needed.

[kzak@redhat.com: - move code to restore_tty()]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-26 15:23:31 +02:00