]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
8 years agocfdisk: use fdisk_reread_changes()
Karel Zak [Fri, 14 Jul 2017 09:08:54 +0000 (11:08 +0200)] 
cfdisk: use fdisk_reread_changes()

Let's make cfdisk usable for disks where some partitions are mounted.

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agofdisk: use fdisk_reread_changes()
Karel Zak [Fri, 14 Jul 2017 09:08:54 +0000 (11:08 +0200)] 
fdisk: use fdisk_reread_changes()

Let's make fdisk usable for disks where some partitions are mounted.

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: use BLKPG ioctls to inform kernel about changes
Karel Zak [Fri, 14 Jul 2017 08:51:14 +0000 (10:51 +0200)] 
libfdisk: use BLKPG ioctls to inform kernel about changes

This patch introduces fdisk_reread_changes(). The function is
less invasive alternative to fdisk_reread_partition_table().

The new function uses BLKPG ioctls for modified partitions. The
another partitions are not affected. This solution allows to
successfully use fdisks on disk where some partitions are still use
(mounted). For example if you want to resize the last partition on the
device.

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agopartx: move partx.h to include/
Karel Zak [Thu, 13 Jul 2017 11:46:52 +0000 (13:46 +0200)] 
partx: move partx.h to include/

Let's make the ioctls usable also for libfdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: add comment
Karel Zak [Mon, 3 Jul 2017 08:23:16 +0000 (10:23 +0200)] 
libfdisk: add comment

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agosfdisk: use fdisk_device_is_used()
Karel Zak [Fri, 30 Jun 2017 09:49:29 +0000 (11:49 +0200)] 
sfdisk: use fdisk_device_is_used()

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: add fdisk_device_is_used()
Karel Zak [Fri, 30 Jun 2017 09:49:12 +0000 (11:49 +0200)] 
libfdisk: add fdisk_device_is_used()

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: remove unnecessary fstat() call
Karel Zak [Fri, 30 Jun 2017 09:29:47 +0000 (11:29 +0200)] 
libfdisk: remove unnecessary fstat() call

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: move fdisk_reread_partition_table() to another file
Karel Zak [Fri, 30 Jun 2017 09:24:36 +0000 (11:24 +0200)] 
libfdisk: move fdisk_reread_partition_table() to another file

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devices
Karel Zak [Wed, 12 Jul 2017 12:35:53 +0000 (14:35 +0200)] 
libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devices

For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64
add extra warning when the ioctl is used for DM devices. It seems we
can avoid this ioctl when the device has dm/uuid.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532
Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agotests: don't use errno in output
Karel Zak [Wed, 12 Jul 2017 10:34:22 +0000 (12:34 +0200)] 
tests: don't use errno in output

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agoMerge branch 'master' of https://github.com/pali/util-linux
Karel Zak [Tue, 11 Jul 2017 12:31:23 +0000 (14:31 +0200)] 
Merge branch 'master' of https://github.com/pali/util-linux

* 'master' of https://github.com/pali/util-linux:
  tests: update UDF test, add ID_FS_VERSION
  libblkid: udf: Add support for ID_FS_VERSION
  libblkid: udf: Fix types
  libblkid: udf: De-duplicate code for dstring decoding

8 years agotests: use sample-fdisk-mkpart-fullspec
Karel Zak [Tue, 11 Jul 2017 12:26:33 +0000 (14:26 +0200)] 
tests: use sample-fdisk-mkpart-fullspec

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: (dos) accept start for log.partitions on template
Karel Zak [Tue, 11 Jul 2017 12:24:32 +0000 (14:24 +0200)] 
libfdisk: (dos) accept start for log.partitions on template

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agotests: check for missing programs in last(1) test
Karel Zak [Tue, 11 Jul 2017 11:41:22 +0000 (13:41 +0200)] 
tests: check for missing programs in last(1) test

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agotests: use sample-fdisk-mkpart
Karel Zak [Tue, 11 Jul 2017 11:33:52 +0000 (13:33 +0200)] 
tests: use sample-fdisk-mkpart

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: don't hardcode label type in samples
Karel Zak [Tue, 11 Jul 2017 11:27:01 +0000 (13:27 +0200)] 
libfdisk: don't hardcode label type in samples

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: add sample-fdisk-mkpart-fullspec
Karel Zak [Tue, 11 Jul 2017 11:00:46 +0000 (13:00 +0200)] 
libfdisk: add sample-fdisk-mkpart-fullspec

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: (dos) cleanup template based partitioning
Karel Zak [Tue, 11 Jul 2017 10:25:02 +0000 (12:25 +0200)] 
libfdisk: (dos) cleanup template based partitioning

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibblkid: don't check for size on UBI (char dev)
Karel Zak [Tue, 11 Jul 2017 10:17:40 +0000 (12:17 +0200)] 
libblkid: don't check for size on UBI (char dev)

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agohwclock: sync one-liner descriptions
J William Piggott [Sun, 2 Jul 2017 18:09:41 +0000 (14:09 -0400)] 
hwclock: sync one-liner descriptions

Make whatisdb/manpage and usage() one-line descriptions match.

Also update the description; hwclock has evolved into much more
than reading and setting the Hardware Clock. It also sets the
System Clock, warps the System Clock, sets the kernel time
configurations, and more.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
8 years agodocs: update boilerplate.c usage()
J William Piggott [Sun, 2 Jul 2017 00:44:46 +0000 (20:44 -0400)] 
docs: update boilerplate.c usage()

Signed-off-by: J William Piggott <elseifthen@gmx.com>
8 years agohwclock: final usage() strings slice
J William Piggott [Sun, 2 Jul 2017 00:16:48 +0000 (20:16 -0400)] 
hwclock: final usage() strings slice

Signed-off-by: J William Piggott <elseifthen@gmx.com>
8 years agohwclock: usage() use program_invocation_short_name
J William Piggott [Sun, 2 Jul 2017 00:05:56 +0000 (20:05 -0400)] 
hwclock: usage() use program_invocation_short_name

Signed-off-by: J William Piggott <elseifthen@gmx.com>
8 years agohwclock: remove from usage() FILE *out = stdout
J William Piggott [Sat, 1 Jul 2017 18:07:14 +0000 (14:07 -0400)] 
hwclock: remove from usage() FILE *out = stdout

Signed-off-by: J William Piggott <elseifthen@gmx.com>
8 years agomount: remove extN from mount.8 man page
Karel Zak [Mon, 10 Jul 2017 10:51:53 +0000 (12:51 +0200)] 
mount: remove extN from mount.8 man page

The e2fsprogs package contains ext4(5) man page with all necessary
information. We do not have to duplicate effort and maintain copy of
the extN mount options in our mount.8.

(We already do the same for XFS.)

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agofdisk: reset context after failed script
Karel Zak [Mon, 10 Jul 2017 10:32:43 +0000 (12:32 +0200)] 
fdisk: reset context after failed script

Addresses: https://github.com/karelzak/util-linux/issues/481
Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolibfdisk: add fdisk_reassign_device()
Karel Zak [Mon, 10 Jul 2017 10:32:26 +0000 (12:32 +0200)] 
libfdisk: add fdisk_reassign_device()

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agoagetty: print /etc/issue on --skip-login
Karel Zak [Mon, 10 Jul 2017 08:42:49 +0000 (10:42 +0200)] 
agetty: print /etc/issue on --skip-login

The current --skip-login implementation disables also issue file
printing. This is unexpected behavior as /etc/issue may contains
important information and we have --noissue for admins who don't want
it.

This patch forces /etc/issue printing if --noissue no specified.

Addresses: https://github.com/karelzak/util-linux/issues/480
Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agoMerge branch 'help' of https://github.com/rudimeier/util-linux
Karel Zak [Mon, 10 Jul 2017 08:15:22 +0000 (10:15 +0200)] 
Merge branch 'help' of https://github.com/rudimeier/util-linux

* 'help' of https://github.com/rudimeier/util-linux:
  setpriv: silence compiler warning
  misc: consolidate macro style USAGE_HELP_OPTIONS
  blockdev: correct man page name in --help

8 years agolast: condition (secs == 0) - now handled correctly
coastal-hiker [Tue, 27 Jun 2017 12:14:49 +0000 (14:14 +0200)] 
last: condition (secs == 0) - now handled correctly

Changed comparison "if (secs > 0)" to "if (secs >= 0)" to handle
condition (secs == 0) correctly.  Suggestions to improve the
less-than-elegant if-else chain are welcome.

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agolast: don't show negative time
coastal-hiker [Mon, 26 Jun 2017 16:40:28 +0000 (18:40 +0200)] 
last: don't show negative time

Under strange circumstances, the output of command 'last reboot'
showed the last time as a negative time, with both the hours and the
mins value having a minus sign. Example, taken from my workstation:

$last reboot
[...]
reboot   system boot  4.4.0-79-generic Wed Jun 14 09:20 - 07:33  (-1:-47)
[...]

I am aware this should happen only infrequently. Nevertheless, I
propose a more robust behaviour: show a minus sign only for the most
significant value (days or hours) and show the rest always as
positive. In the special case of ((secs < 0) && (secs >= -59)), print
mins as "-00".

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agotests: update UDF test, add ID_FS_VERSION
Pali Rohár [Wed, 5 Jul 2017 11:56:05 +0000 (13:56 +0200)] 
tests: update UDF test, add ID_FS_VERSION

8 years agolibblkid: udf: Add support for ID_FS_VERSION
Pali Rohár [Wed, 5 Jul 2017 11:50:52 +0000 (13:50 +0200)] 
libblkid: udf: Add support for ID_FS_VERSION

Set ID_FS_VERSION to Minimum UDF Read Revision.

8 years agolibblkid: udf: Fix types
Pali Rohár [Wed, 5 Jul 2017 11:46:12 +0000 (13:46 +0200)] 
libblkid: udf: Fix types

8 years agolibblkid: udf: De-duplicate code for dstring decoding
Pali Rohár [Wed, 5 Jul 2017 10:15:00 +0000 (12:15 +0200)] 
libblkid: udf: De-duplicate code for dstring decoding

8 years agologin: use IPv4 on IPv4-mapping-to-IPv6
Karel Zak [Tue, 4 Jul 2017 10:50:39 +0000 (12:50 +0200)] 
login: use IPv4 on IPv4-mapping-to-IPv6

It seems that on some systems (e.g. RHEL7) the libc function
getaddrinfo() is not able to translate ::ffff: address to IPv4. The
result is 0.0.0.0 host address in the last(1) and utmpdump(1) output.

 /sbin/login -h "::ffff:192.168.1.7"

utmpdump:

  [7] [03926] [1   ] [user1   ] [pts/1       ] [::ffff:192.168.1.7  ] [0.0.0.0        ] [Thu May 12 17:49:50 2016    ]

Not sure if this is about order of the getaddrinfo() results, system
configuration or libc version. It's irrelevant for login(1). We have
to be robust enough to write usable address to log files everywhere.

The solution is to detect IPv4-mapping-to-IPv6 and use IPv4 for utmp.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1296233
Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agosetpriv: silence compiler warning
Ruediger Meier [Thu, 29 Jun 2017 15:28:01 +0000 (17:28 +0200)] 
setpriv: silence compiler warning

This got lost in 30129e2f

sys-utils/setpriv.c:182:32: warning: implicit conversion from enumeration type
      'enum cap_type' to different enumeration type 'capng_type_t'
      [-Wenum-conversion]
                return capng_have_capability(which, i);
                       ~~~~~~~~~~~~~~~~~~~~~ ^~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
8 years agomisc: consolidate macro style USAGE_HELP_OPTIONS
Ruediger Meier [Thu, 29 Jun 2017 13:52:16 +0000 (15:52 +0200)] 
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>
8 years agoblockdev: correct man page name in --help
Ruediger Meier [Thu, 29 Jun 2017 13:03:23 +0000 (15:03 +0200)] 
blockdev: correct man page name in --help

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
8 years agoMerge branch 'path-fixes' of https://github.com/rudimeier/util-linux
Karel Zak [Thu, 29 Jun 2017 13:29:33 +0000 (15:29 +0200)] 
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

8 years agohwclock: don't ifdef printf arguments
Ruediger Meier [Wed, 28 Jun 2017 16:37:44 +0000 (18:37 +0200)] 
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>
8 years agosetpriv: align --help
Ruediger Meier [Tue, 27 Jun 2017 18:36:11 +0000 (20:36 +0200)] 
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>
8 years agotools: add segfault detection for checkusage.sh
Ruediger Meier [Tue, 27 Jun 2017 18:34:29 +0000 (20:34 +0200)] 
tools: add segfault detection for checkusage.sh

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
8 years agomisc: avoid some dead initialization warnings
Ruediger Meier [Sat, 17 Jun 2017 20:40:41 +0000 (22:40 +0200)] 
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>
8 years agolscpu: make clang analyzer happy
Ruediger Meier [Tue, 27 Jun 2017 18:33:28 +0000 (20:33 +0200)] 
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>
8 years agolsmem: fix, using freed memory
Ruediger Meier [Tue, 27 Jun 2017 18:33:18 +0000 (20:33 +0200)] 
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>
8 years agolib/path: add error handling to path_vcreate()
Ruediger Meier [Tue, 27 Jun 2017 18:33:08 +0000 (20:33 +0200)] 
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>
8 years agotests: explicitly define wipefs outpuit columns
Karel Zak [Thu, 29 Jun 2017 11:31:35 +0000 (13:31 +0200)] 
tests: explicitly define wipefs outpuit columns

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agotests: update wipefs outputs
Karel Zak [Thu, 29 Jun 2017 11:07:10 +0000 (13:07 +0200)] 
tests: update wipefs outputs

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agocolumn: fix compilation when libc lacks wide-character support
Carlos Santos [Thu, 29 Jun 2017 10:55:42 +0000 (07:55 -0300)] 
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>
8 years agolibmount: use _exit() in <type> handlers
Karel Zak [Thu, 29 Jun 2017 10:58:57 +0000 (12:58 +0200)] 
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>
8 years agodocs: correct line(1) deprecation comment
Ruediger Meier [Thu, 29 Jun 2017 02:09:08 +0000 (04:09 +0200)] 
docs: correct line(1) deprecation comment

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
8 years agolib/blkdev: remove support for Linux < 2.6
Ruediger Meier [Thu, 29 Jun 2017 02:09:07 +0000 (04:09 +0200)] 
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>
8 years agodocs: remove some old history from manpages
Ruediger Meier [Thu, 29 Jun 2017 02:09:06 +0000 (04:09 +0200)] 
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>
8 years agouuidgen: improve --help
Karel Zak [Thu, 29 Jun 2017 10:40:22 +0000 (12:40 +0200)] 
uuidgen: improve --help

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agowipefs: improve --help
Karel Zak [Thu, 29 Jun 2017 10:38:40 +0000 (12:38 +0200)] 
wipefs: improve --help

Signed-off-by: Karel Zak <kzak@redhat.com>
8 years agowipefs: use libsmartcols
Karel Zak [Thu, 29 Jun 2017 09:57:22 +0000 (11:57 +0200)] 
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>
8 years agouuidparse: se JSON table name on -J
Karel Zak [Thu, 29 Jun 2017 09:07:54 +0000 (11:07 +0200)] 
uuidparse: se JSON table name on -J

Signed-off-by: Karel Zak <kzak@redhat.com>
8 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>
8 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>
8 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>
8 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>
8 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>
8 years agolib/path: fix crash, pathbuf overflow
Ruediger Meier [Tue, 27 Jun 2017 18:32:52 +0000 (20:32 +0200)] 
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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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

8 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

8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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

8 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>
8 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>
8 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>
8 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

8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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

8 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