Commit Graph
7460 Commits
Author SHA1 Message Date
Mike Yuan 18a8ea3377 path-util: unify path_extract_filename/directory into path_split_prefix_filename() 2026-02-09 09:05:45 +01:00
Mike Yuan 294855953c path-util: drop redundant condition in path_find_last_component()
Follow-up for 3a7ba9f6b9
2026-02-09 09:05:44 +01:00
Matteo Croce c1bf450fa0 oomd: implement a prekill varlink event
When a cgroup is selected for termination, send varlink messages
to hooks registered in `/run/systemd/oomd.prekill-hooks/`.
oomd waits up to `PreKillHookTimeoutSec=` seconds for response
before proceeding with the kill.
2026-02-09 02:05:57 +01:00
Mike Yuan a3ecd774db stat-util: introduce xstatx() (#40507) 2026-02-05 16:51:57 +01:00
Daan De Meyer dd8c07da04 Various fixes related to mountfsd (#40564) 2026-02-05 16:39:28 +01:00
Daan De Meyer cbd2e08f00 pidfd-util: Remove unused include
This snuck in when CI was broken.
2026-02-05 16:18:35 +01:00
Mike Yuan 9feb490633 stat-util: drop now unused statx_warn_mount_{id,root}() 2026-02-05 14:14:40 +01:00
Mike Yuan 10072d8be4 various: use xstatx() 2026-02-05 14:14:40 +01:00
Mike Yuan 5817c73391 mountpoint-util: rework name_to_handle_at() unique mount id handling
name_to_handle_at_try_unique_mntid_fid() in its current form is
ill-designed for various reasons:

* AT_HANDLE_FID requires file system support, while unique mount id
  is a VFS concept hence is always available if supported. Hence
  the fallback for AT_HANDLE_MNT_ID_UNIQUE should be independent
  of fid.
* The request for AT_HANDLE_MNT_ID_UNIQUE can be identified via
  specifying ret_unique_mnt_id, no need for opening up the control
  to caller (and currently the function simply doesn't handle
  mismatch between ret params and flags).
* The caller cannot realistically differentiate whether the returned
  mount id is actually unique.
* The path_get_unique_mnt_id() fallback did not handle AT_SYMLINK_FOLLOW.

Let's instead move the statx() fallback into name_to_handle_at_loop()
directly, and revamp interaction of ret_mnt_id/ret_unique_mnt_id:
if both are set, it indicates that the caller can handle both, hence
set what we have and return 0/1 for whether we managed to acquire
the unique one.

The !ret_handle && ret_mnt_id logic is removed. Let's not rely on
undocumented bizaare behavior and it's unused anyways.
path_get_mnt_id_at() exists for a reason...
2026-02-05 14:14:40 +01:00
Mike Yuan 56adac1193 mountpoint-util: port to xstatx(), support XAT_FDROOT 2026-02-05 14:14:39 +01:00
Mike Yuan 1cf84c5642 stat-util: introduce xstatx() 2026-02-05 14:14:39 +01:00
Mike Yuan 6b039272e9 basic: add generated statx_mask_one_to_name()/statx_attribute_to_name() 2026-02-05 14:14:39 +01:00
Mike Yuan 539e2b75aa fd-util: add generic resolve_xat_fdroot()
As suggested in
https://github.com/systemd/systemd/pull/40500#discussion_r2740921215
2026-02-05 14:14:39 +01:00
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