]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
6 years agowipefs: try another magic strings on -o and -t
Karel Zak [Wed, 28 Jun 2017 10:08:25 +0000 (12:08 +0200)] 
wipefs: try another magic strings on -o and -t

The commit 92296e9ba2bf95259520fa7537ff8edc2aa9edbc 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>
6 years agowipefs: add control struct
Karel Zak [Wed, 28 Jun 2017 09:51:12 +0000 (11:51 +0200)] 
wipefs: add control struct

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agowipefs: don't do step-back if <type> does not match
Karel Zak [Fri, 16 Jun 2017 09:36:41 +0000 (11:36 +0200)] 
wipefs: don't do step-back if <type> does not match

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agowipefs: print all signature permutations
Karel Zak [Fri, 26 May 2017 11:11:37 +0000 (13:11 +0200)] 
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>
6 years agolibblkid: allow to hide already detected signatures
Karel Zak [Fri, 26 May 2017 10:58:09 +0000 (12:58 +0200)] 
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>
6 years agosetpriv: add --ambient-caps to usage()
Karel Zak [Tue, 27 Jun 2017 13:10:09 +0000 (15:10 +0200)] 
setpriv: add --ambient-caps to usage()

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agosetpriv: support modifying the set of ambient capabilities
Patrick Steinhardt [Sat, 24 Jun 2017 14:04:34 +0000 (16:04 +0200)] 
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>
6 years agosetpriv: support dumping ambient capabilities
Patrick Steinhardt [Sat, 24 Jun 2017 14:04:33 +0000 (16:04 +0200)] 
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>
6 years agosetpriv: proxy function to update capabilities
Patrick Steinhardt [Sat, 24 Jun 2017 14:04:32 +0000 (16:04 +0200)] 
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>
6 years agosetpriv: proxy function checking whether a capability is set
Patrick Steinhardt [Sat, 24 Jun 2017 14:04:31 +0000 (16:04 +0200)] 
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>
6 years agosetpriv: introduce indirection for `capng_type` enum
Patrick Steinhardt [Sat, 24 Jun 2017 14:04:30 +0000 (16:04 +0200)] 
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>
6 years agoMerge branch 'travis-checkusage' of https://github.com/rudimeier/util-linux
Karel Zak [Tue, 27 Jun 2017 12:14:57 +0000 (14:14 +0200)] 
Merge branch 'travis-checkusage' of https://github.com/rudimeier/util-linux

6 years agoMerge branch 'help-description' of https://github.com/rudimeier/util-linux
Karel Zak [Tue, 27 Jun 2017 12:14:14 +0000 (14:14 +0200)] 
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

6 years agomisc: update --help content again
Ruediger Meier [Sun, 25 Jun 2017 20:01:12 +0000 (22:01 +0200)] 
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>
6 years agologin: add --help text
Ruediger Meier [Sun, 25 Jun 2017 19:58:12 +0000 (21:58 +0200)] 
login: add --help text

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agoblockdev: improve --help and man page
Ruediger Meier [Sun, 25 Jun 2017 18:43:44 +0000 (20:43 +0200)] 
blockdev: improve --help and man page

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: consolidate all --help option descriptions
Ruediger Meier [Sun, 25 Jun 2017 12:49:47 +0000 (14:49 +0200)] 
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>
6 years agomisc: introduce print_usage_help_options()
Ruediger Meier [Sat, 24 Jun 2017 22:19:50 +0000 (00:19 +0200)] 
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>
6 years agolibblkid: remove dead code and blkid_probe_new_value()
Karel Zak [Tue, 27 Jun 2017 09:26:41 +0000 (11:26 +0200)] 
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>
6 years agotravis: add make checkusage
Ruediger Meier [Tue, 27 Jun 2017 06:25:30 +0000 (08:25 +0200)] 
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>
6 years agotools: checkusage can dump all command output
Ruediger Meier [Tue, 27 Jun 2017 06:25:22 +0000 (08:25 +0200)] 
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>
6 years agotools: ignore unsafe commands in checkusage.sh
Ruediger Meier [Tue, 27 Jun 2017 06:25:10 +0000 (08:25 +0200)] 
tools: ignore unsafe commands in checkusage.sh

These commands behave unusual with --unknownopt.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agoMerge branch 'travis-fix' of https://github.com/rudimeier/util-linux
Karel Zak [Mon, 26 Jun 2017 20:42:24 +0000 (22:42 +0200)] 
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

6 years agouuidparse: fix getopt crash
Ruediger Meier [Mon, 26 Jun 2017 16:20:06 +0000 (18:20 +0200)] 
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>
6 years agomisc: revert to the old USAGE_HELP strings
Ruediger Meier [Sat, 24 Jun 2017 14:47:30 +0000 (16:47 +0200)] 
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>
6 years agobuild-sys: fix chown mistake, add checkusage.sh to the dist
Ruediger Meier [Mon, 26 Jun 2017 14:54:57 +0000 (16:54 +0200)] 
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>
6 years agoMerge branch 'usage-part2' of https://github.com/rudimeier/util-linux
Karel Zak [Mon, 26 Jun 2017 13:58:37 +0000 (15:58 +0200)] 
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

6 years agoscript: rename fixtty() to enable_rawmode_tty()
Karel Zak [Mon, 26 Jun 2017 13:30:12 +0000 (15:30 +0200)] 
script: rename fixtty() to enable_rawmode_tty()

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agoscript: ensure typescript and timing errors do not break terminal
Sami Kerola [Sat, 24 Jun 2017 10:48:08 +0000 (11:48 +0100)] 
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>
6 years agouuidparse: add new command
Sami Kerola [Sun, 18 Jun 2017 17:16:35 +0000 (17:16 +0000)] 
uuidparse: add new command

This command will analyze and print information about UUID's.  The command
is based on libuuid/src/uuid_time.c but modified to use libsmartcol.

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

Reference: http://marc.info/?l=util-linux-ng&m=149735980715600&w=2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agomisc: cosmetics, remove argument from usage(FILE*)
Ruediger Meier [Tue, 20 Jun 2017 18:20:29 +0000 (20:20 +0200)] 
misc: cosmetics, remove argument from usage(FILE*)

This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: cosmetics, remove argument from usage(int)
Ruediger Meier [Tue, 20 Jun 2017 18:30:29 +0000 (20:30 +0200)] 
misc: cosmetics, remove argument from usage(int)

This patch is trivial and changes nothing, because
we were always using usage(0).

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: never use usage(stderr)
Ruediger Meier [Mon, 19 Jun 2017 18:52:50 +0000 (20:52 +0200)] 
misc: never use usage(stderr)

Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: never use usage(ERROR)
Ruediger Meier [Mon, 19 Jun 2017 18:51:50 +0000 (20:51 +0200)] 
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>
6 years agomisc: cleanup and fix --unknownopt issues
Ruediger Meier [Mon, 19 Jun 2017 07:24:10 +0000 (09:24 +0200)] 
misc: cleanup and fix --unknownopt issues

Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agoflock, getopt: write --help to stdout and return 0
Ruediger Meier [Sun, 18 Jun 2017 22:02:44 +0000 (00:02 +0200)] 
flock, getopt: write --help to stdout and return 0

... and use errtryhelp() instead of usage().

Note in past "getopt --help" returned 2. But it is otherwise
documented and was just a mistake IMO. See the unreachable exit(0)
which was removed here: d1d03b54

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agotools: add checkusage.sh
Ruediger Meier [Sun, 18 Jun 2017 13:19:39 +0000 (15:19 +0200)] 
tools: add checkusage.sh

Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.

The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).

For the record here are the current candidates with possible
problems:

$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: consolidate usage() "Available columns"
Karel Zak [Mon, 26 Jun 2017 12:09:53 +0000 (14:09 +0200)] 
misc: consolidate usage() "Available columns"

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agoMerge branch '170622' of github.com:jwpi/util-linux
Karel Zak [Mon, 26 Jun 2017 11:56:45 +0000 (13:56 +0200)] 
Merge branch '170622' of github.com:jwpi/util-linux

* '170622' of github.com:jwpi/util-linux:
  Docs: move option naming to howto-contribute.txt
  Docs: update howto-usage-function.txt
  Docs: add a comment for constants to boilerplate.c
  include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS

6 years agoMerge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linux
Karel Zak [Mon, 26 Jun 2017 11:47:04 +0000 (13:47 +0200)] 
Merge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linux

* 'fix-exit-codes' of https://github.com/rudimeier/util-linux:
  misc: fix optutils.h related exit codes
  misc: fix xalloc.h related exit codes
  misc: fix more strutils related exit codes
  lib: fix strutils.h, remove STRTOXX_EXIT_CODE
  misc: fix some broken exit codes

6 years agoMerge branch 'usage-part1' of https://github.com/rudimeier/util-linux
Karel Zak [Mon, 26 Jun 2017 11:42:25 +0000 (13:42 +0200)] 
Merge branch 'usage-part1' of https://github.com/rudimeier/util-linux

* 'usage-part1' of https://github.com/rudimeier/util-linux:
  misc: no more errtryh()
  mkfs.cramfs: add --help and --version
  more: add --help and --version
  whereis: add --help and --version
  login: add --help and --version
  fsck: add --help and --version
  setarch: use errtryhelp()
  dmesg: do not accept any non-option arguments
  blkid: use errtryhelp instead of errtryh
  misc: remove superfluous null pointer checks for optarg
  uuidd: remove unused define

6 years agomisc: no more errtryh()
Ruediger Meier [Thu, 22 Jun 2017 00:27:23 +0000 (02:27 +0200)] 
misc: no more errtryh()

Nowadays all our regular commands have --help options.
test_uuidd does not use translations anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomkfs.cramfs: add --help and --version
Ruediger Meier [Wed, 21 Jun 2017 20:37:37 +0000 (22:37 +0200)] 
mkfs.cramfs: add --help and --version

Note, we were already using errtryhelp() without providing
a --help option.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agoDocs: move option naming to howto-contribute.txt
J William Piggott [Sat, 24 Jun 2017 19:22:49 +0000 (15:22 -0400)] 
Docs: move option naming to howto-contribute.txt

Creating and naming options is not done when writing usage().
A contributor may not even read howto-usage-function.txt, but
they should read howto-contribute.txt. So move option naming
and change information there.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agoDocs: update howto-usage-function.txt
J William Piggott [Fri, 23 Jun 2017 23:57:46 +0000 (19:57 -0400)] 
Docs: update howto-usage-function.txt

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agoDocs: add a comment for constants to boilerplate.c
J William Piggott [Fri, 23 Jun 2017 23:24:38 +0000 (19:24 -0400)] 
Docs: add a comment for constants to boilerplate.c

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agoinclude/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
J William Piggott [Fri, 23 Jun 2017 00:32:27 +0000 (20:32 -0400)] 
include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS

* login-utils/lslogins.c: all uses changed
* misc-utils/findmnt.c: likewise
* sys-utils/blkzone.c: likewise
* disk-utils/sfdisk.c: likewise
* sys-utils/lscpu.c: likewise
* sys-utils/lsmem.c: likewise
* sys-utils/wdctl.c: likewise

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agoagetty: fix login name DEL/CTRL^U issue
Karel Zak [Fri, 23 Jun 2017 12:26:47 +0000 (14:26 +0200)] 
agetty: fix login name DEL/CTRL^U issue

agetty refresh prompt (/etc/issue file etc.) when requested by inotify
or netlink. For this purpose we monitor some file descriptors by
select().

The terminal input file descriptor is switched to non-canonical mode before
select(). The goal is to be informed about user activity before
new-line. The FD is immediately switched back to canonical mode when
activity is detected. The side effect is that all not-read-yet chars in
the input buffer are lost ... so we need to call read() before switch
to canonical mode to save the chars.

The original implementation has been based on TIOCSTI ioctl. It
returns already read chars back to the terminal input buffer to make
them useful for canonical mode. The problem was race (agetty writes to
input buffer in the same time as user) and result was reordered chars
in login name... so useless.

This issue has been later fixed by extra buffer (commit
790119b8850ae13bb4254c5096a54b2aeb355b20) for already read data.  And
TIOCSTI ioctl has been removed. Unfortunately this solution is also
wrong, because the buffer is maintained only by agetty and
inaccessible for terminal when user edit (by DEL/CTRL^U) login name in
canonical mode.

The solution is simple -- just don't try to be smart and keep terminal
in canonical mode all time (so terminal controls DEL, CTRL^U, etc) and
flush input buffer (=discard unread data) and ask user for login name
again after prompt reload.

The agetty reload is very rarely situation and for user it's pretty
obvious that he has to type login name again (as all terminal has been
clear+redraw).

Addresses: https://github.com/karelzak/util-linux/issues/454
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1464148
Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agomisc: fix optutils.h related exit codes
Ruediger Meier [Thu, 22 Jun 2017 20:18:14 +0000 (22:18 +0200)] 
misc: fix optutils.h related exit codes

Found by:

  grep -L "OPTUTILS_EXIT_CODE" $(grep -l "err_exclusive_options" \
      $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: fix xalloc.h related exit codes
Ruediger Meier [Thu, 22 Jun 2017 20:17:14 +0000 (22:17 +0200)] 
misc: fix xalloc.h related exit codes

Found by:

grep -L "XALLOC_EXIT_CODE" $(grep -l "xalloc\.h" \
    $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: fix more strutils related exit codes
Ruediger Meier [Thu, 22 Jun 2017 20:16:14 +0000 (22:16 +0200)] 
misc: fix more strutils related exit codes

Found by grep:

grep -l "\bEXIT_\|exit *( *[0-9][0-9] *)\|strutils\.h" $(grep -L \
    strutils_set_exitcode  $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

The Command shows also some false positives (fstrim.c,
context_mount.c, ...)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agolib: fix strutils.h, remove STRTOXX_EXIT_CODE
Ruediger Meier [Thu, 22 Jun 2017 20:15:14 +0000 (22:15 +0200)] 
lib: fix strutils.h, remove STRTOXX_EXIT_CODE

As discussed on the mailing list. We fix all places
where the non-working define STRTOXX_EXIT_CODE was used.

Regarding tunelp, also see 7e3c80a7.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomisc: fix some broken exit codes
Ruediger Meier [Tue, 20 Jun 2017 18:01:32 +0000 (20:01 +0200)] 
misc: fix some broken exit codes

These tools have special exit codes. They got changed mistakenly.

See:
  findfs       0e1fa6b6
  fsck         658c0891
  fsck.cramfs  922ec175
  mkfs.cramfs  16154b1f
  tunelp       2ab428f6

FIXME: STRTOXX_EXIT_CODE doesn't work as it should.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agomore: add --help and --version
Ruediger Meier [Wed, 21 Jun 2017 20:37:37 +0000 (22:37 +0200)] 
more: add --help and --version

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agowhereis: add --help and --version
Ruediger Meier [Wed, 21 Jun 2017 20:17:36 +0000 (22:17 +0200)] 
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>
6 years agologin: add --help and --version
Ruediger Meier [Wed, 21 Jun 2017 02:14:58 +0000 (04:14 +0200)] 
login: add --help and --version

Also we don't print the usage text on stderr anymore.

Note, the usage text could be improved, currently it
does not describe any options. I have only added a
pointer to the man page.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agofsck: add --help and --version
Ruediger Meier [Wed, 21 Jun 2017 13:33:57 +0000 (15:33 +0200)] 
fsck: add --help and --version

Also cleanup usage() function, never write usage to stderr.

FIXME:
 - currently strtou32_or_err() exits with wrong exit code.
 - option -C does not use a safe strto*_err function

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agosetarch: use errtryhelp()
Ruediger Meier [Wed, 21 Jun 2017 18:23:09 +0000 (20:23 +0200)] 
setarch: use errtryhelp()

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agodmesg: do not accept any non-option arguments
Ruediger Meier [Tue, 20 Jun 2017 09:50:20 +0000 (11:50 +0200)] 
dmesg: do not accept any non-option arguments

'dmesg foo' is no valid syntax and gives an error now.
BTW we avoid the "dead increment of argc and argv.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agoblkid: use errtryhelp instead of errtryh
Ruediger Meier [Tue, 20 Jun 2017 18:07:01 +0000 (20:07 +0200)] 
blkid: use errtryhelp instead of errtryh

We have a --help option and this is preferred.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agoMerge branch 'master' of https://github.com/pali/util-linux
Karel Zak [Thu, 22 Jun 2017 08:51:58 +0000 (10:51 +0200)] 
Merge branch 'master' of https://github.com/pali/util-linux

* 'master' of https://github.com/pali/util-linux:
  tests: Add UDF hdd image which label has length 30 characters
  libblkid: udf: Fix parsing of UDF dstring structures

6 years agoMerge branch '170618' of github.com:jwpi/util-linux
Karel Zak [Thu, 22 Jun 2017 08:45:22 +0000 (10:45 +0200)] 
Merge branch '170618' of github.com:jwpi/util-linux

* '170618' of github.com:jwpi/util-linux:
  hwclock: add audit for --systz
  hwclock: remove unused optstring characters

6 years agodmesg: print only 2 hex digits for each hex-escaped byte
Ivan Delalande [Wed, 21 Jun 2017 23:43:05 +0000 (16:43 -0700)] 
dmesg: print only 2 hex digits for each hex-escaped byte

As buf is passed as a signed char buffer in fwrite_hex, fprintf will
print every byte from 0x80 as a signed-extended int causing each of
these bytes to be printed as "\xffffff80" and such, which can be pretty
confusing. Force fprintf to use the argument as a char to make it print
only 2 digits, e.g. "\x80".

Signed-off-by: Ivan Delalande <colona@arista.com>
6 years agotests: Add UDF hdd image which label has length 30 characters
Pali Rohár [Thu, 22 Jun 2017 08:38:24 +0000 (10:38 +0200)] 
tests: Add UDF hdd image which label has length 30 characters

Structure dstring for label has 32 bytes, first byte is 8 (Compression ID),
last byte is 30 (count of 8bit characters in label). Therefore label is not
nul terminated and dstring parser needs to handle it (fixed in previous
commit).

$ dd if=/dev/zero of=udf-hdd-mkudffs-1.3-6.img bs=1M count=10
$ mkudffs -l AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -b 512 udf-hdd-mkudffs-1.3-6.img

6 years agolibblkid: udf: Fix parsing of UDF dstring structures
Pali Rohár [Thu, 22 Jun 2017 08:38:08 +0000 (10:38 +0200)] 
libblkid: udf: Fix parsing of UDF dstring structures

First byte of dstring is OSTA Compression ID and the last byte is length of
recorded bytes (including first byte). Last byte is not a part of recorded
characters, therefore it should not be treated as data to decode.

6 years agomisc: remove superfluous null pointer checks for optarg
Ruediger Meier [Wed, 21 Jun 2017 01:01:30 +0000 (03:01 +0200)] 
misc: remove superfluous null pointer checks for optarg

This is only needed for optional arguments.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agouuidd: remove unused define
Ruediger Meier [Mon, 19 Jun 2017 14:49:50 +0000 (16:49 +0200)] 
uuidd: remove unused define

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
6 years agohwclock: add audit for --systz
J William Piggott [Tue, 20 Jun 2017 00:30:58 +0000 (20:30 -0400)] 
hwclock: add audit for --systz

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: remove unused optstring characters
J William Piggott [Tue, 20 Jun 2017 00:04:21 +0000 (20:04 -0400)] 
hwclock: remove unused optstring characters

getopt_long() opstring contained obsolete entries.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agobuild-sys: update DISTCHECK_CONFIGURE_FLAGS
Karel Zak [Wed, 21 Jun 2017 13:41:21 +0000 (15:41 +0200)] 
build-sys: update DISTCHECK_CONFIGURE_FLAGS

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agotravis: fix another chown issue
Karel Zak [Wed, 21 Jun 2017 11:41:08 +0000 (13:41 +0200)] 
travis: fix another chown issue

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agoMerge branch 'master' of https://github.com/pali/util-linux
Karel Zak [Wed, 21 Jun 2017 09:54:51 +0000 (11:54 +0200)] 
Merge branch 'master' of https://github.com/pali/util-linux

* 'master' of https://github.com/pali/util-linux:
  tests: Add UDF hdd images with blocksize 1024 and 4096 created by Linux mkudffs 1.3
  libblkid: udf: Fix detection of UDF images with block size 1024 and 4096

6 years agotravis: use --disable-makeinstall-chown everywhere
Karel Zak [Wed, 21 Jun 2017 09:51:39 +0000 (11:51 +0200)] 
travis: use --disable-makeinstall-chown everywhere

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agodocs: add program-desc to howto-usage-function.txt and boilerplate.c
Karel Zak [Wed, 21 Jun 2017 09:25:55 +0000 (11:25 +0200)] 
docs: add program-desc to howto-usage-function.txt and boilerplate.c

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agohwclock: remove unwanted space before description
Karel Zak [Wed, 21 Jun 2017 09:25:16 +0000 (11:25 +0200)] 
hwclock: remove unwanted space before description

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agoMerge branch '170427' of github.com:jwpi/util-linux
Karel Zak [Wed, 21 Jun 2017 09:16:23 +0000 (11:16 +0200)] 
Merge branch '170427' of github.com:jwpi/util-linux

* '170427' of github.com:jwpi/util-linux:
  hwclock: remove unused stdarg.h
  Docs: update howto-usage-function.txt
  hwclock: add --update-drift check
  hwclock: slice up the usage text
  hwclock: update --help content and grammar
  hwclock: use RTC in help output
  include: update pathnames.h
  hwclock: add usage() functions heading
  hwclock: update usage() FILE name
  hwclock: update usage() to util-linux style
  hwclock: remove dead code in usage()

6 years agobuild-sys: make chown usage more robust
Karel Zak [Wed, 21 Jun 2017 09:12:04 +0000 (11:12 +0200)] 
build-sys: make chown usage more robust

* add --disable-makeinstall-chown to travis non-root mode

* use "if MAKEINSTALL_DO_SETUID" for chown root:root

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agowipefs: exit on failed erase
Karel Zak [Wed, 21 Jun 2017 08:53:28 +0000 (10:53 +0200)] 
wipefs: exit on failed erase

The current behavior is to report error and continue, it seems strange:

# blockdev --setro /dev/sdc

# wipefs -a /dev/sdc
wipefs: /dev/sdc: failed to erase xfs magic string at offset 0x00000000: Operation not permitted
/dev/sdc: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42
                          ^^^^^^^^^^^
                           not true

The patch calls err() to exit.

Reported-by: Vratislav Podzimek <vpodzime@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agohwclock: remove unused stdarg.h
J William Piggott [Mon, 19 Jun 2017 00:21:27 +0000 (20:21 -0400)] 
hwclock: remove unused stdarg.h

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agoDocs: update howto-usage-function.txt
J William Piggott [Sun, 18 Jun 2017 17:31:36 +0000 (13:31 -0400)] 
Docs: update howto-usage-function.txt

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: add --update-drift check
J William Piggott [Sun, 18 Jun 2017 17:14:40 +0000 (13:14 -0400)] 
hwclock: add --update-drift check

Only allow --update-drift for --set or --systohc

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: slice up the usage text
J William Piggott [Sun, 18 Jun 2017 15:47:18 +0000 (11:47 -0400)] 
hwclock: slice up the usage text

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: update --help content and grammar
J William Piggott [Sun, 18 Jun 2017 14:32:42 +0000 (10:32 -0400)] 
hwclock: update --help content and grammar

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: use RTC in help output
J William Piggott [Sat, 17 Jun 2017 23:21:13 +0000 (19:21 -0400)] 
hwclock: use RTC in help output

Switching between 'hardware clock' and 'RTC' is ambiguous.
RTC is used due to space constraints, so use it consistently.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agoinclude: update pathnames.h
J William Piggott [Sat, 17 Jun 2017 20:32:19 +0000 (16:32 -0400)] 
include: update pathnames.h

* use /dev/rtc0 (/dev/rtc was for the 'old' driver)
* remove hwclock Award workaround and alpha cmos paths
* relocate _PATH_BTMP from hwclock to login-utils
* add a comment for _PATH_BTMP and fix other login-utils comments
* add a comment for proc/cpuinfo
* remove empty shutdown.c comment from 4d43977f

Review changes
* remove 'used in' comments
* white space fixes

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: add usage() functions heading
J William Piggott [Sat, 17 Jun 2017 19:32:28 +0000 (15:32 -0400)] 
hwclock: add usage() functions heading

Make a functions heading, similar to the existing options heading.

* include/c.h: define USAGE_FUNCTIONS
* Documentation/boilerplate.c: add USAGE_FUNCTIONS
* sys-utils/hwclock.c add functions header to usage()

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: update usage() FILE name
J William Piggott [Fri, 21 Apr 2017 00:53:23 +0000 (20:53 -0400)] 
hwclock: update usage() FILE name

Use the util-linux standard file name instead of 'usageto'.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: update usage() to util-linux style
J William Piggott [Fri, 21 Apr 2017 00:44:13 +0000 (20:44 -0400)] 
hwclock: update usage() to util-linux style

Update usage() according to:
  Documentation/howto-usage-function.txt
  Documentation/boilerplate.c

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agohwclock: remove dead code in usage()
J William Piggott [Fri, 21 Apr 2017 00:29:15 +0000 (20:29 -0400)] 
hwclock: remove dead code in usage()

Commit 677ec86 caused usage() to be called only by --help.

So remove the now dead code from usage().

Signed-off-by: J William Piggott <elseifthen@gmx.com>
6 years agobuild-sys: chown before chmod for SUIDs
Karel Zak [Tue, 20 Jun 2017 11:12:43 +0000 (13:12 +0200)] 
build-sys: chown before chmod for SUIDs

Make sure SUIDs are really owned by root.

Reported-by: L A Walsh <lkml@tlinx.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agolibmount: ignore "bind" from fstab on command line "remount"
Karel Zak [Tue, 20 Jun 2017 10:46:02 +0000 (12:46 +0200)] 
libmount: ignore "bind" from fstab on command line "remount"

The current code always apply all flags from /etc/fstab on remount.
Unfortunately remount+bind has special semantic and it's impossible
from command line to avoid interaction with the "bind" from fstab.

Example, fstab:

/dev/sda1 /bar ext4 defaults 0 1
/bar /foo none bind 0 0

Command line:

    # mount /foo -o remount,rw

produces:

    mount(... MS_REMOUNT|MS_BIND ) syscall

This changes the per-mountpoint (VFS) ro flag to rw, but doesn't
change the filesystem itself.

This patch forces libmount to ignore "bind" from fstab when "-o
remount" specified on command line. If you need remount+bind semantic
you have to specify the "bind" flag on command line. This allow to
differentiate between

    # mount /foo -o remount,bind,rw  --> mount(MS_REMOUNT|MS_BIND)
and

    # mount /foo -o remount,rw       --> mount(MS_REMOUNT)

Suggested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agodmesg: fragment concatenation
Vinnie Magro [Mon, 19 Jun 2017 21:45:02 +0000 (14:45 -0700)] 
dmesg: fragment concatenation

When extended console is enabled, the kernel doesn't internally
concatenate message fragments, this change adds log fragment
concatenation to dmesg: instead of being printed as separate messages,
fragments are combined onto one line and printed with the timestamp of
the first line.

This doesn't work in all cases - such as if another message is logged in
between two fragment lines, but in this case the behavior matches the
previous output format (printed on the separate lines).

[kzak@redhat.com: - rename kmsg_read_buf to kmsg_saved_size,
                  - minor coding style fixes]

Signed-off-by: Vinnie Magro <vmagro@fb.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agoMerge branch '170424' of github.com:jwpi/util-linux
Karel Zak [Tue, 20 Jun 2017 08:20:49 +0000 (10:20 +0200)] 
Merge branch '170424' of github.com:jwpi/util-linux

* '170424' of github.com:jwpi/util-linux:
  parse-date: time_zone_hhmm() bug fixes
  parse-date: remove unused ordinal_day_seen
  parse-date: remove unused year_seen
  parse-date: refactor tm_diff()
  parse-date: use to_uchar() instead of assignment.
  parse-date: use uintmax_t where appropriate
  parse-date: use int where appropriate
  parse-date: use intmax_t where appropriate
  parse-date: remove unused EPOCH_YEAR
  parse-date: replace ISDIGIT with c_isdigit

6 years agotests: add MBR resize tests
Karel Zak [Mon, 19 Jun 2017 14:10:33 +0000 (16:10 +0200)] 
tests: add MBR resize tests

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agolibfdisk: support logical partition resize
Karel Zak [Mon, 19 Jun 2017 14:03:41 +0000 (16:03 +0200)] 
libfdisk: support logical partition resize

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agolibfdisk: allow to resize container
Karel Zak [Mon, 19 Jun 2017 13:32:02 +0000 (15:32 +0200)] 
libfdisk: allow to resize container

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agolibfdisk: add more debug messages to get-last-possible resize space
Karel Zak [Mon, 19 Jun 2017 13:27:05 +0000 (15:27 +0200)] 
libfdisk: add more debug messages to get-last-possible resize space

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agolibfdisk: (dos) be more verbose on partno -ERANGE error
Karel Zak [Mon, 19 Jun 2017 12:32:59 +0000 (14:32 +0200)] 
libfdisk: (dos) be more verbose on partno -ERANGE error

Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agomount: fix man page typo (--bind,ro)
Karel Zak [Mon, 19 Jun 2017 09:49:51 +0000 (11:49 +0200)] 
mount: fix man page typo (--bind,ro)

Addresses: https://github.com/karelzak/util-linux/issues/464
Signed-off-by: Karel Zak <kzak@redhat.com>
6 years agolibfdisk: (dos) fix primary/logical logic when follow template
Karel Zak [Mon, 19 Jun 2017 09:41:02 +0000 (11:41 +0200)] 
libfdisk: (dos) fix primary/logical logic when follow template

This stupid bug has been introduced by e1cfb304 (v2.30) and it
disables to create extended partition by cfdisk :-(

Signed-off-by: Karel Zak <kzak@redhat.com>