Karel Zak [Mon, 5 Jun 2023 10:59:41 +0000 (12:59 +0200)]
libmount: use mount(2) for remount on Linux < 5.14
It seems mount_setattr() is supported on Linux < 5.14, but it's without
MOUNT_ATTR_NOSYMFOLLOW. That's problem for remount where we reset all
VFS flags.
The most simple (but not elegant) is to check for kernel version and
fallback to mount(2) on remount.
Addresses: https://github.com/util-linux/util-linux/issues/2283 Signed-off-by: Karel Zak <kzak@redhat.com>
Debarshi Ray [Thu, 13 Jul 2023 09:07:27 +0000 (11:07 +0200)]
libmount: handle failure to apply flags as part of a mount operation
If a mount operation with extra flags runs into an EPERM when applying
the flags, then mnt_context_get_mount_excode() returns 'Unknown error
5005' and MNT_EX_FAIL. Here's an example:
Create a mount point on the host with 'nodev,nosuid,noexec':
$ dd if=/dev/zero of=/var/tmp/loopfile bs=40960 count=1024
$ sudo losetup --find /var/tmp/loopfile
$ sudo mkfs.ext4 /dev/loop0
$ sudo mkdir /mnt/a
$ sudo mount -o nosuid,nodev,noexec /dev/loop0 /mnt/a
Check the mount options to be sure:
$ findmnt --output OPTIONS,PROPAGATION /mnt/a
OPTIONS PROPAGATION
rw,nosuid,nodev,noexec,relatime,seclabel shared
Enter a mount and user namespace:
$ podman run \
--interactive \
--privileged \
--rm \
--tty \
--volume /:/run/host:rslave \
registry.fedoraproject.org/fedora:38 \
/bin/bash
Try to bind mount the mount point from the host inside the namespace
with some extra flags:
# mkdir ~/b
# mount --bind -o ro /run/host/mnt/a ~/b
mount: /root/b: filesystem was mounted, but any subsequent operation
failed: Unknown error 5005.
# echo $?
32
It will be better to show something more human-readable than 'Unknown
error 5005'.
Secondly, an exit code of 32 means 'mount failure', which isn't quite
correct here. The mount operation is split into two mount(2) calls,
where the first one uses MS_BIND to create the bind mount, and the
second uses MS_REMOUNT | MS_BIND | MS_RDONLY to apply the 'ro' flag.
Here, the first mount(2) does succeed:
# findmnt --output OPTIONS,PROPAGATION ~/b
OPTIONS PROPAGATION
rw,nosuid,nodev,noexec,relatime,seclabel private,slave
It's only the application of the 'ro' flag with the second mount(2) that
fails with an EPERM. Hence, an exit code of 1 that means 'incorrect
invocation or permissions' seems more appropriate.
Signed-off-by: Debarshi Ray <rishi@fedoraproject.org>
Thomas Weißschuh [Wed, 21 Jun 2023 12:26:05 +0000 (14:26 +0200)]
tests: (run.sh) detect builddir from working directory
This makes it easier to run test.sh from the build directory as
everything will work without any parameters irrespective of the build
directories name.
Karel Zak [Mon, 26 Jun 2023 10:00:41 +0000 (12:00 +0200)]
Merge branch 'lsfd--fix-separators-for-json-output-endpoints-only' of https://github.com/masatake/util-linux into stable/v2.39
* 'lsfd--fix-separators-for-json-output-endpoints-only' of https://github.com/masatake/util-linux:
tests: (lsfd) add a case for verifying ENDPOINTS column output in JSON mode
lsfd: use ARRAY_STRING for ENDPOINTS column in JSON output mode
lsfd: (filter) weakly support ARRAY_STRING and ARRAY_NUMBER json types
Karel Zak [Thu, 22 Jun 2023 11:11:57 +0000 (13:11 +0200)]
libmount: fix sync options between context and fs structs
Since v2.39 libmount prefers "struct libmnt_optlist" to keep mount options
rather than the original "struct libmnt_fs". This is problem if the
"fs" struct is defined and maintained outside the context.
The library has already a way how to sync "fs" and "optlist", but this
needs to be improved and used more widely. Changes:
* force "fs" from context to always read options from "optlist"
* copy options from "fs" to "optlist" in mnt_context_set_fs()
* internally redirect mnt_fs_* API for options to "optlist" if optlist
defined
* add simple test to make sure options from different sources are
always merged together
Addresses: https://github.com/util-linux/util-linux/issues/2326 Signed-off-by: Karel Zak <kzak@redhat.com>
Masatake YAMATO [Thu, 22 Jun 2023 02:28:47 +0000 (11:28 +0900)]
lsfd: (filter) weakly support ARRAY_STRING and ARRAY_NUMBER json types
We will have operators for array types in the future. Till having
them, we treat the types as STRING. So we can use string operators for
the column having types.
Karel Zak [Tue, 20 Jun 2023 11:15:45 +0000 (13:15 +0200)]
lib: remove pager.c from libcommon
The libcommon is a binary archive to keep compilation and maintenance
simple. The library is not linked as shared or so. The unused symbols
are removed from binaries (for example, by "make install-strip").
But it isn't evident for license analyzers (and some humans) that the
library uses GPL and non-GPL stuff simultaneously. Let's avoid doubts
and keep pager.c (with GPL license) out of the archive
Karel Zak [Mon, 19 Jun 2023 11:29:42 +0000 (13:29 +0200)]
libmount: always ignore user=<name>
The library (on mount) cares about "user", but has to ignore
"user=name". It works as expected, but only for non-root users. We
need to ignore it also root to be compatible with /sbin/mount.cifs
where some people still use "user=" (rather than "username=").
This conditional was never implemented in the meson config. Under
autotools, it is guarded by availability of headers and an option. I
didn't implement the option here.
Fixes #2310.
'!= false' is used because 'x == 1' is rejected by meson if 'x' is
false. OTOH, 'x != false' seems to work if 'x' is 1.
Karel Zak [Thu, 25 May 2023 09:48:24 +0000 (11:48 +0200)]
libmount: don't call hooks after mount.<type> helper
In case more filesystems are specified (or when libmount follows
/{etc,proc}/filesystems) then the library may try to use and
initialize the new API because for some filesystems, we need
exec(/sbin/mount.<type>) and for another fsopen().
The hooks that use the API have to smart and detect that the mount
operation was done in external /sbin/mount.<type> helper. And in this
case, the new API file descriptors must be ignored.
The exception is propagation flags, mount(8) can set the flags after
exec(/sbin/mount.<type>), for example, "mount -t ntfs --make-private".
Fixes: https://github.com/util-linux/util-linux/issues/2267 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 22 May 2023 15:26:55 +0000 (17:26 +0200)]
libmount: don't call mount.<type> helper with usernames
This is v2.39 regression. The "user" mount option is internally
converted to "user=<name>", but this should not be exported to
the mount helpers.
The mount helper accepts the <name> only if specified in mount options
(cifs uses user=). The real username as generated by libmount is not
relevant in this case.
Frantisek Sumsal [Thu, 18 May 2023 16:56:15 +0000 (18:56 +0200)]
build-sys: add --disable-waitpid
The new pidfd stuff waitpid uses is not compatible with older kernel
headers, but the rest of the util-linux is still perfectly fine, so
allow disabling just the waitpid utility to make the builds happy again.
наб [Sun, 14 May 2023 23:19:58 +0000 (01:19 +0200)]
mesg.1 cleanups/updates
First hunk: grammar.
Second hunk: (a) mentioning BSD ptys and not UNIX98 ones is odd,
(b) mentioning /only/ ptys is odder still.
Third hunk: mesg is found in the UNIX Programmer's Manual;
it takes its modern form in V7
(it's unclear to me why V6 specifically is mentioned,
since it's still default-invert + always-report-"was X").
Thomas Weißschuh [Fri, 19 May 2023 15:34:00 +0000 (17:34 +0200)]
libsmartcols: (samples): fix format truncation warning
As this is only an example and the needed memory is not much just
hardcode a large enough number.
The previously computed value was wrong anyways.
libsmartcols/samples/continuous.c: In function 'main':
libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing between 3 and 11 bytes into a region of size between 0 and 7 [-Werror=format-truncation=]
110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
| ^~~
libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 333 bytes into a destination of size 12
110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111 | done ? 100 : (int)(diff / (TIME_PERIOD / 100.0)));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing 3 bytes into a region of size between 0 and 7 [-Werror=format-truncation=]
110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
| ^~~
libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 325 bytes into a destination of size 12
110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111 | done ? 100 : (int)(diff / (TIME_PERIOD / 100.0)));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~