Commit Graph
7447 Commits
Author SHA1 Message Date
Daan De Meyer f3b81859c2 namespace-util: Fix logging in userns_enter_and_pin() 2026-02-05 14:09:03 +01:00
Kai Lueke 23115eeaf1 sysext: Skip refresh if no changes are found
When the extensions for the final system are already set up from the
initrd we should avoid disrupting the boot process with the remount
(which currently isn't atomic) and the daemon reload for
systemd-confext and systemd-sysext. Similarly, when sysupdate ran and
updated extensions it's best to avoid the remount and daemon reload if
no changes are found.
To do this, encode the current extension state in more detail than
before where only the names of the extensions where encoded in the
overlay mount. This can also be used to provide more details about the
extension origin in "systemd-sysext status (--json=)". During the
refresh add a check whether the old state matches the new state and in
this case skip the refresh unless the user provides a flag to always
refresh. Besides the extension name and the resolved path the best
method for identification is the verity hash but that is not available
for plain image files or directories. Therefore, also include data to
check for file/directory replacements. The creation/modification times
are not always real on reproducible images or extracted archive content.
The file handle together with the unique mount ID is the next best
identifier we can use when we have no verity hash. Fall back to an inode
when we get no handle. With the creation/modification time and the path
this should be good enough. Using a unique mount ID is important (with
a fallback to the regular non-unique mount ID) instead of st_dev because
st_dev gets reused too easily, e.g., by a loop device mount and the
mount ID helps to catch this. For the mount ID to be valid it has to be
resolved before we enter the new mount namespace. Thus, it gets provided
by the image dissect logic and handed over to the sysext subprocess
which runs in a new mount namespace.
Luckily, we can rule out online modification of directories or image
files because this is anyway not well supported with overlay mounts, so
we don't do a file checksum nor do we recurse into a directory to look
for the most recently touched files.  But, as said, with the
always-refresh flag one can force a reload.
2026-02-04 00:05:24 +01:00
Yu Watanabe ede1caeada cgroup-util: declare file_handle union in cg_cgroupid_open()
This also effectively reverts eb2e91b981,
as now the object is only used as input, and kernel would need to handle
input with only ID no matter whether the struct later gets extended.
2026-02-04 02:45:17 +09:00
Yu Watanabe f37931bd78 tree-wide: replace cg_{fd,path}_get_cgroupid() with {fd,path}_to_handle_u64() 2026-02-04 02:45:17 +09:00
Yu Watanabe 2eab8fa1e4 pidfd-util: use fd_to_handle_u64() 2026-02-04 02:45:17 +09:00
Yu Watanabe e7ce1e22b9 mountpoint-util: introduce name_to_handle_at_u64() and friends
They will be used later.
2026-02-04 02:45:06 +09:00
Yu Watanabe 09811ccaa1 mountpoint-util: make name_to_handle_at_loop() gracefully handle NULL path 2026-02-04 00:07:02 +09:00
Yu Watanabe dd839b1463 parse-util: rename trivial argument for parse_pid()
The function parse_pid() trivially returns pid, hence it is not
necessary to name the argument for storing result as 'ret_pid'.
2026-02-03 21:43:17 +09:00
Jeff Layton eb2e91b981 pidfd/cgroup-util: use fully-sized filehandle buffers
The current code assumes that FILEID_KERNFS filehandles will never grow
in size. This is not a safe assumption and userland shouldn't be trying
to guess the size of the filehandle it'll get.

We have a macro for that: MAX_HANDLE_SZ.
2026-01-29 00:57:03 +09:00
Yu Watanabe 701cf5b698 ansi-color: follow-ups for $SYSTEMD_COLOR=auto-* (#40442)
Follow-ups for #40303
2026-01-28 16:00:38 +09:00
Yu Watanabe 149a8e6306 Bump required minimum version of glibc to 2.34
Major distributions already have glibc >= 2.34.
Let's bump the required minimum version.

Note, glibc-2.34 was released on 2021-08-01.
2026-01-28 10:56:53 +09:00
Mike Yuan cc7fe807c1 ansi-color: $SYSTEMD_COLORS=true should mean generic "auto", not 24bit
Follow-up for af718e0535

The commit changed the documentation, but the actual impl
was apparently not updated. And the documented behavior
feels a bit off. I think generally "auto"/true should
override $NO_COLOR.

Plus, the test for auto-24bit is at odds with the logic
we merged. I guess it was overlooked after applying
https://github.com/systemd/systemd/pull/40303#discussion_r2720450393
2026-01-27 19:20:30 +01:00
Mike Yuan 97be547c6f ansi-color: assert on final result of get_color_mode() being settled 2026-01-27 19:17:42 +01:00
Lennart Poettering 65a6da9c96 conf-files: add flag so that we don't always prefix returned paths with the root dir path used
This is useful in tools such as system-repart where we show the
definition file paths a lot in our output, but if prefixed with the root
path we'd show a temporary mount dir when operating on a image file.
Hence, let's drop the prefix here, and show only the path within the
image.
2026-01-25 20:51:50 +01:00
Lennart Poettering 8a4f856977 conf-files: rename .name field to .filename to make clearer what precisely it is the name of 2026-01-25 20:51:50 +01:00
Lennart Poettering 64ef947022 os-util: support XAT_FDROOT everywhere 2026-01-25 20:51:50 +01:00
Lennart Poettering 6ecfa12af0 conf-files: add support for root_fd based operation
Let's make sure we can safely load configuration files based on a root
fd, including XAT_FDROOT.

(While we are at it, always pass path to root fs before fd to root fs,
following our recently updated CODING_STYLE)
2026-01-25 20:51:50 +01:00
Peter Oliver af718e0535 ansi-color: new option SYSTEMD_COLORS=auto-16/auto-256/auto-24bit (#40303)
Setting SYSTEMD_COLORS=auto-16 is like SYSTEMD_COLORS=16 if output is to
a non-dumb TTY, and like SYSTEMD_COLORS=no otherwise.

Relates to
https://github.com/systemd/systemd/issues/15498#issuecomment-1682025186
2026-01-23 13:54:31 +01:00
Mike Yuan dbd7555190 mkdir: reset mtime *after* fchown()
Follow-up for 34c3d57474

Also, drop pointless shortcut.
2026-01-21 08:35:31 +09:00
Yu Watanabe e6a25c2fc7 stat-util: make proc_mounted() not update errno
Typically, proc_mounted() is used in error handling. Hence, it is better
to make it not update the original errno.

Currently, there are two places that returns wrong error code:
- pidref_get_capability() in src/basic/capability-util.c
```c
        _cleanup_fclose_ FILE *f = fopen(path, "re");
        if (!f) {
                if (errno == ENOENT && proc_mounted() == 0)
                        return -ENOSYS;

                return -errno;
        }
```
- fdset_new_fill() in src/shared/fdset.c
```c
        d = opendir("/proc/self/fd");
        if (!d) {
                if (errno == ENOENT && proc_mounted() == 0)
                        return -ENOSYS;

                return -errno;
        }
```

Rather than fixing them, let's make proc_mounted() not update errno,
otherwise we may make a similar failure in a future.
2026-01-20 22:37:04 +09:00
Yu Watanabe b7dd507cae tree-wide: use consistent format of short comment for constant argument
Follow-ups for recent changes after 93378148d4.
2026-01-20 00:22:15 +09:00
Mike Yuan 5f90e4e4bc stat-util: O_NOCTTY is nop with O_PATH 2026-01-19 13:33:27 +01:00
Mike Yuan b0906b1216 stat-util: do not use RET_NERRNO for our own function
Follow-up for 95abe4beff
2026-01-19 13:33:27 +01:00
Mike Yuan 02bf2b7cdf fs-util: optimize xopenat(XAT_FDROOT, ...) a bit
Follow-up for ef582ab201

* Open / with O_PATH
* Shortcut to fd_reopen() directly if path is empty
2026-01-19 13:33:27 +01:00
Mike Yuan 9b906ae48e fs-util: group access_fd() with access_nofollow() 2026-01-19 13:33:27 +01:00
Mike Yuan 52bf232e82 fs-util: drop fallback for kernels without AT_EMPTY_PATH support (< 5.8) 2026-01-19 13:33:26 +01:00
Mike Yuan 6753bd8a2f mountpoint-util: assume MS_NOSYMFOLLOW is available
Since our kernel baseline is v5.10 now.
2026-01-19 13:33:26 +01:00
Mike Yuan 537045ec2f recurse-dir: remove stale comment
Follow-up for 6393b847f4
2026-01-19 03:06:30 +01:00
cyclopentane 465f6a6284 cryptenroll,cryptsetup,shutdown: only call mlockall if we have CAP_IPC_LOCK
Calling mlockall in an unprivileged process most notably had the effect
of making systemd-cryptenroll OOM while trying to open a normal-sized
argon2 keyslot due to it hitting RLIMIT_MEMLOCK.
2026-01-18 19:15:30 +01:00
Daan De Meyer 103f7d2303 fd-util: introduce XAT_FDROOT fd shortcut for the root dir (#39244) 2026-01-18 11:57:11 +01:00
Lennart Poettering 95abe4beff stat-util: write up XAT_FDROOT in stat-util.[ch] 2026-01-17 12:37:39 +01:00
Lennart Poettering c67abc9c43 chase: extend coverage of the root fd shortcut
Let's use dir_fd_is_root() to check if we are looking at the real root
fs.
2026-01-17 12:37:39 +01:00
Lennart Poettering ded2531764 chase: optimize the special case where no root dir specified
Now that we can recognize the root dir in chaseat() sanely, let's use it
top optimize the very common special case where we have no root dir to
consider, and directly call open_tree().
2026-01-17 12:37:39 +01:00
Lennart Poettering 874971b1c0 chase: wire up XAT_FDROOT 2026-01-17 12:37:39 +01:00
Lennart Poettering 5667cbcacf fd-util: wire up XAT_FDROOT in various really basic fd-util.h calls 2026-01-17 12:37:39 +01:00
Lennart Poettering ef582ab201 fs-util: wire up XAT_FDROOT in xopenat_full() and access_fd() 2026-01-17 12:37:33 +01:00
Lennart Poettering ee79c9d309 fd-util: introduce XAT_FDROOT fd shortcut for the root dir
This takes inspiration from AT_FDCWD, but always references the root dir
rather than the cwd. This allows various convenience uses, as we can now
reference the root dir without actually allocating an fd for chaseat(),
fd_get_path() and various others.

The value of XAT_FDROOT is chosen so that it is not a valid fd (essential,
because we do not intend to hook this up everywhere, just where we need
it, just like AT_FCWD only works in some syscalls), and we want uses at
the wrong places to fail cleanly. It also uses a valud outside of the
range where we usually return negative errnos, i.e. < -ERRNO_MAX.
2026-01-17 12:35:33 +01:00
Lennart Poettering e09b5366e5 string-util: accept ":" when stripping ANSI color sequences
Since 6eabe9f2ff we generate sequences
with ":", hence we better also know how to strip them.

(Without this patch we'd strip simple ANSI colors, but not RGB ones that
use ":" syntax).

(While we are at it, also drop a duplicate "0" in the list of valid
chars)
2026-01-17 12:07:36 +01:00
Lennart Poettering 24c315e911 ansi-color: convert one more ANSI sequence from ";" to ":" separators
This is a follow-up for 6eabe9f2ff where
one sequence was forgotten.
2026-01-17 12:07:05 +01:00
Yu Watanabe 2aa496312e conf-files: introduce CONF_FILES_WARN flag and set it at various places
Closes #40285.
2026-01-16 23:05:33 +09:00
Yu Watanabe 5d0dc9915c conf-files: make conf_file_new() take ConfFilesFlags rather than ChaseFlags
No functional change, preparation for later commit.
2026-01-16 23:01:04 +09:00
Yu Watanabe 0c109deda1 conf-files: use empty_to_root()
No functional change. For consistency with conf_file_chase_and_verify().
2026-01-16 23:01:04 +09:00
Yu Watanabe 4a8e0ea4ec conf-files: split out several helper functions from files_add()
No functional change, preparation for later commit.
2026-01-16 23:01:01 +09:00
Yu Watanabe fce7ad481b process-util: drop unnecessary E2BIG error handling
E2BIG is returned when the kernel does not support CLONE_INTO_CGROUP,
but the flag is supported since kernel v5.7.
2026-01-13 10:21:36 +09:00
Yu Watanabe d58c826c54 fd-util: drop close_all_fds_by_proc()
With the previous commit, now the function is used only on OOM.
In that case, let's do like close_all_fds_without_malloc().
2026-01-13 10:21:36 +09:00
Yu Watanabe c471cca093 fd-util: close_range() is available since kernel 5.9
Our baseline on kernel is 5.10, hence we can always use it.
2026-01-13 10:21:36 +09:00
Yu Watanabe d377cc5244 stat-util: STATX_TYPE and STATX_INO should be always set 2026-01-13 10:21:05 +09:00
Yu Watanabe 7ecfa87c56 fd-util,mountpoint-util: STATX_MNT_ID is supported since kernel 5.10
Our baseline on kernel is 5.10, hence we can assume it works.
2026-01-13 10:21:05 +09:00
Yu Watanabe 7f6cf19513 mountpoint-util: make is_mount_point_at() take usual dir_fd + path style arguments 2026-01-13 10:21:05 +09:00
Yu Watanabe a98a6eb95c tree-wide: statx() supports STATX_ATTR_MOUNT_ROOT since kernel 5.8
Our baseline on kernel is 5.10, hence we can unconditionally use it.
2026-01-13 10:21:04 +09:00