Karel Zak [Mon, 9 Dec 2019 11:20:22 +0000 (12:20 +0100)]
Merge branch 'kill-pidfd' of https://github.com/kerolasa/util-linux
* 'kill-pidfd' of https://github.com/kerolasa/util-linux:
kill: use pidfd system calls to implement --timeout option
build-sys: add missing NR underscore to UL_CHECK_SYSCALL()
Karel Zak [Mon, 9 Dec 2019 10:30:55 +0000 (11:30 +0100)]
lib/randutils: re-licensing back to BSD
The file is originally from libuuid, this library is under BSD
licence. Unfortunately, I have added LGPL header by accident to the
file (commit 0f23ee0c855d686b0c315af2c96b8835134cd9e3).
The file under LGPL was modified (in relevant way) by Sami,
Christopher and me. We all agree with re-licensing back to BSD.
Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Christopher James Halse Rogers <chris@cooperteam.net> Signed-off-by: Karel Zak <kzak@redhat.com>
Pierre Labastie [Fri, 6 Dec 2019 11:50:46 +0000 (12:50 +0100)]
docs: Fix adjtime documentation
The first line of the adjtime file is made of three numbers (see=20
hwclock.c):
- a drift factor as a decimal float
- the time of last adjust as a decimal integer
- a zero (for compatibility) as a decimal float.
but both man pages (hwclock.8 and adj_time.5) tell that the third
number is a decimal integer.
Of course this is harmless if somebody edits the adjtime file with
"0"=20 as the third number: it will be correctly read by hwclock
anyway. But if for some reason, a program reads the adjtime file and
expects an integer, it will fail, because hwclock writes O.OOOO0O as
the third=20 number.
Signed-off-by:: Pierre Labastie <pierre.labastie@neuf.fr> Signed-off-by: Karel Zak <kzak@redhat.com>
The source path will be used as a dm-verity object, and will be
opened using libcryptsetup APIs.
A new --with-cryptsetup build-time option is added, which adds a
dependency on libcryptsetup. To ease bootstrapping, given libcryptsetup
build-depends on util-linux for libuuid, if --with-cryptsetup=yes but
libcryptsetup is not installed only a warning will be printed at
configure time rather than an error. This way stage0/first stage/ring0
builds can use the same configure options but avoid installing
cryptsetup to get a working base set, and then rebuild util-linux in
the next step of the boostrapping process.
If verity options are selected but cannot be fullfilled due to lack of
dependencies, mounting a volume will fail even if using a loop device
would work as a fallback, to avoid silently skipping integrity checks.
Sami Kerola [Mon, 25 Nov 2019 20:31:20 +0000 (20:31 +0000)]
kill: use pidfd system calls to implement --timeout option
At times there is need in scripts to send multiple signals to a process.
Often these cases require some amount of waiting before follow-up signal
should be sent.
One common case is process termination, where first script tries to kill
process gracefully but if that does not work SIGKILL is sent. Functionality
like that is commonly done by periodically checking if signalled pid exist
or not, and if it does another signal is sent possibly to an unrelated
process that reused pid number. That means polling a pid is prone to a data
race. Also if the first signal immediately kills the process one polling
interval is lost in sleep.
Another example when multiple signal need to be sent is various daemon
process control situations, such as Upgrading Executable on the Fly (see
reference). This happens to be the case that inspired change author to make
sequential signaling a little bit easier.
Reference: http://nginx.org/en/docs/control.html#upgrade
Pull-request: https://github.com/karelzak/util-linux/pull/902 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Karel Zak [Mon, 25 Nov 2019 12:55:18 +0000 (13:55 +0100)]
build-sys: fix out-of-tree build for hwclock
The file sys-utils/hwclock-parse-date.c is generated from .y and
stored in the build directory and "#include hwclock.h" is interpreted
relatively to the build tree rather than to source tree. We need
explicit -I compiler option to point to $srcdir for hwclock.
Karel Zak [Fri, 22 Nov 2019 11:34:45 +0000 (12:34 +0100)]
scriptlive: terminate session at end of the log
We need a proper way how to inform child (shell) that the game is
over. It seems the best is to send EOF to child rather than
immediately break PTY mainloop where we have poll(), because shell can
still produce data etc.
Karel Zak [Tue, 19 Nov 2019 13:58:20 +0000 (14:58 +0100)]
mount: no exit on EPERM, continue without suid
The current libmount assumes that mount(8) and umount(8) are suid
binaries. For this reason it implements internal rules which
restrict what is allowed for non-root users. Unfortunately, it's
out of reality for some use-cases where root permissions are no
required. Nice example are fuse filesystems.
So, the current situation is to call exit() always when mount, umount or
libmount are unsure with non-root user rights. This patch removes the
exit() call and replaces it with suid permissions drop, after that it
continues as usually. It means after suid-drop all depend on kernel
and no another security rule is used by libmount (simply because any
rule is no more necessary).
Example:
old version:
$ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
mount: only root can use "--types" option
new version:
$ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
kzak@192.168.111.1's password:
Sami Kerola [Sun, 17 Nov 2019 08:33:04 +0000 (08:33 +0000)]
nologin: silently ignore well known shell command-line options
nologin is typically used in /etc/passwd as a shell replacement. Hence it
is reasonable to ignore well known command-line options silently to avoid
unwanted ugly error messages.
Addresses: https://github.com/karelzak/util-linux/issues/895 Requested-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Evan Green [Tue, 12 Nov 2019 22:17:37 +0000 (14:17 -0800)]
libfdisk: Space before first partition may not be aligned
libfdisk chooses a grain of 1MB fairly arbitrarily, and this granule
may not be honored by other utilities. GPT disks formatted elsewhere
may have space before the first partition, AND a partition that exists
solely below 1MB. If this occurs, cfdisk ends up adding a free space
region where end < start, resulting in a 16 Exabyte free region.
That's too many exabytes.
This happens because the start gets rounded up to the granule size in
new_freespace() but the end is left alone. The logs show it best:
Karel Zak [Tue, 12 Nov 2019 10:15:38 +0000 (11:15 +0100)]
agetty: add --show-issue to review issue output
Let's make life easier for admins and allow to review issue file
output on the current terminal without all full agetty execution. Use
case is pretty simple:
# $EDITOR /etc/issue
# agetty --show-issue
Addresses: https://github.com/karelzak/util-linux/issues/828 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 7 Nov 2019 08:02:23 +0000 (09:02 +0100)]
build-sys: use parse-date() only for hwclock
The parse-date.y is used only for hwclock, let's keep it together.
Note that the file (originally from gnulib) has GPLv3 license, so it's
better to make it obvious that we use it really only for hwclock (also
GPL).
Michal Suchanek [Mon, 4 Nov 2019 20:23:15 +0000 (21:23 +0100)]
libblkid: open device in nonblock mode.
When autoclose is set (kernel default but many distributions reverse the
setting) opening a CD-rom device causes the tray to close.
The function of blkid is to report the current state of the device and
not to change it. Hence it should use O_NONBLOCK when opening the
device to avoid closing a CD-rom tray.
blkid is used liberally in scripts so it can potentially interfere with
the user operating the CD-rom hardware.
[kzak@redhat.com: add O_NONBLOCK also to:
- wipefs
- blkid_new_probe_from_filename()
- blkid_evaluate_tag()]
Signed-off-by: Michal Suchanek <msuchanek@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 31 Oct 2019 12:51:29 +0000 (13:51 +0100)]
libmount: make sure optsmode is initialized
Since 34333e5244167a8f6385faa350938ed5cb6d5c0a we apply fstab options
manually by mnt_context_apply_fs() on --all. The function does not
work correctly when optsmode is zero.
Karel Zak [Thu, 31 Oct 2019 09:34:12 +0000 (10:34 +0100)]
libmount: fix mnt_context_next_remount()
The current implementation works, but the remount operation is done in
the cloned context and the original context (and calling application)
has no information about the final status/errors. This is mistake.
This new implementation works like mnt_context_next_mount(), it means
the same context (as used by application) is reused for all remounts.
The original setting is restored by mnt_context_apply_template().
Karel Zak [Thu, 31 Oct 2019 09:31:53 +0000 (10:31 +0100)]
libmount: save current FS setting as template
This commit adds new functions to save and reuse the current FS
setting (mount options from command line, etc) after context reset.
It's usable for example in "mount --all" when we use the same context
for more times for more mount operations.
Karel Zak [Wed, 23 Oct 2019 10:02:33 +0000 (12:02 +0200)]
libmount: cleanup strdup() use in context, add reg.test
* don't ignore strdup() result
* cleanup mnt_context_prepare_helper() to have only one return point
(due to mnt_context_switch_ns())
* add mnt_context_prepare_helper() test program
Karel Zak [Tue, 29 Oct 2019 11:59:08 +0000 (12:59 +0100)]
libmount: don't use /proc/mounts fallback if filename specified
The current solution is to use /proc/mounts if previous attempt to
open /proc/self/mountinfo failed. The fallback should not be used when
mount table path is explicitly specified by application. The default
is NULL, only in this case libmount should be try to be smart.
Reported-by: Alasdair G Kergon <agk@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Anatoly Pugachev [Wed, 23 Oct 2019 08:26:19 +0000 (11:26 +0300)]
tests: fixes blkid/md-raidX-whole on Sparc
Since SPARC is using 'sun' partition table by default, make test not to
assume that disk has 'dos' partition table, so write 'dos' partition
table on disk, before proceeding any further.
In commit b1418ed14 (lib/path: add ul_path_stat(), fix absolute paths,
2019-10-15), a new function `ul_path_stat()` was added to "path.h". This
new function prototype causes a compiler warning on musl libc based
systems due to one of the parameters having the unknown type `struct
stat` due to the <sys/stat.h> header not being included.
Karel Zak [Thu, 17 Oct 2019 08:36:27 +0000 (10:36 +0200)]
lib/fileutils: add close_all_fds()
The classic way which is based on file-descriptors table size is
pretty expensive (due to table size) and forces code to do many
unnecessary close() calls. It seems better to use /proc/self/fds and
close used descriptors only.
Addresses: https://github.com/karelzak/util-linux/issues/883 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 15 Oct 2019 10:36:16 +0000 (12:36 +0200)]
lsblk: on --sysroot read attributes from /dev/<devname> text file
The option --sysroot is used to read information from dumps rather
than from the current system. This patch allows to read also udev
attributes from text file in location /sysroot/dev/<devname>. The file
is text file in format NAME=value\n.
Suggested-by: Alasdair G Kergon <agk@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 15 Oct 2019 09:59:16 +0000 (11:59 +0200)]
lib/path: add ul_path_stat(), fix absolute paths
* add ul_path_stat()
* make sure all paths for ul_path_..() functions are always
interpreted relatively to the context directory and prefix. This is
difference between ul_path_ API and standard libc "at" functions. We
do not use any exception for absolute paths. The reason is that we
need to read from prefixed paths although application assume absolute
path (/dev/sda1 means /prefix/dev/sda1 if a /prefix is defined).