Commit Graph
7560 Commits
Author SHA1 Message Date
Lennart Poettering b34ff170d1 tmpfile-util: don't log about lack of O_TMPFILE support
It's a very common case (vfat...), and it's just too much noise. After
all the whole function exists primarily to deal with O_TMPFILE not being
availeble everywhere...
2026-03-27 11:55:32 +00:00
Lennart Poettering 6e2a452118 fundamental: move strv_isempty() into src/fundamental/ 2026-03-27 09:54:28 +01:00
Zbigniew Jędrzejewski-Szmek 2d2dc38f00 basic/proc-cmdline: extend comments
Inspired by the discussion in #41161.

Also change the order of flags to be more logical. First the option
to specify at what fields we look, then the option to specify how we
return their name, the the value, and finally what to do if the value
is missing.
2026-03-26 18:53:40 +01:00
Mike Yuan de68e23ff1 creds: minor cleanups for --newline= handling (#41329)
Prompted by #41325

Fixes #41348
2026-03-26 18:36:51 +01:00
Mike Yuan 82bfcc37e2 cleanup-util: include assert-fundamental.h instead of -util
The split was initially done to reduce transitive includes,
and for assert() only the former is needed.
2026-03-26 15:55:50 +01:00
Lennart Poettering 23b4c833a4 fileio: add WRITE_DATA_FILE_MODE_0400 mode 2026-03-26 14:34:56 +01:00
Lennart Poettering e7b3a7bb24 memory-util: move memeqbyte() & friends to src/fundamental/ 2026-03-25 14:50:19 +01:00
Lennart Poettering 588c22b04d macro.h: move DEFER_VOID_CALL() to cleanup-util.h
For some reason the IMDS PR for the first time triggers an issue with
the DEFER_VOID_CALL() logic relying on assert() and being places in
macro.h, let's hence move this elsewhere.
2026-03-25 11:52:33 +01:00
Lennart Poettering 172ae47e65 stat-util: introduce inode_unmodified_hash_ops
This is almost the same as inode_hash_ops, but also hashes + compares
all attributes that could affect the contents of a file. It ignores
"superficial"/"external" attributes such as ownership or access mode
however.
2026-03-24 21:24:47 +01:00
Lennart Poettering cf6f65c5ea stat-util: also include inode type in hash ops
This doesn't really have any major benefit, but it does make this nicely
mirror stat_inode_same() which also checks this triplet for identifying
identical inodes.
2026-03-24 21:21:10 +01:00
Daan De Meyer 8878df45c1 ssh: handle VMADDR_CID_ANY in a couple places (#41230)
Originally reported in Ubuntu as
https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/2145027.
2026-03-22 20:07:53 +01:00
Zbigniew Jędrzejewski-Szmek 77549ac1c4 Stop disabling -Wattributes (#41174)
In one of the reviews one of the LLMs noticed that the pragma is set but
never unset, so it remains in effect for the rest of the translation
unit. From the comment, it's not clear how old those "old compilers"
were, so let's try if things work without this workaround.
2026-03-20 17:10:10 +01:00
Nick Rosbrook 83359c4da0 socket-util: filter out VMADDR_CID_ANY in vsock_get_local_cid()
It has been observed on some systems[1] that ssh-issue may print out:

 Try contacting this VM's SSH server via 'ssh vsock%4294967295' from host.

i.e. it suggests connecting with VMADDR_CID_ANY, which is not valid. It
seems that IOCTL_VM_SOCKETS_GET_LOCAL_CID may return VMADDR_CID_ANY in
some cases, e.g. when vsock is not full initialized or so.

Treat VMADDR_CID_ANY as special in vsock_get_local_cid(), the same as
VMADDR_CID_LOCAL and VMADDR_CID_HOST, and return an error.

[1] https://launchpad.net/bugs/2145027
2026-03-20 11:37:31 -04:00
Lennart Poettering 7876bd5cfc env-file: add parse_env_data() helper 2026-03-20 16:34:58 +01:00
Lennart Poettering 56f3ae9292 iovec-util: introduce IOVEC_MAKE_BYTE() helper 2026-03-20 11:53:33 +01:00
Lennart Poettering 6738762688 fileio: introduce write_data_file_atomic_at() helper
This is very similar to write_string_file_atomic(), but is intentionally
kept separate (after long consideration). It focusses on arbitrary
struct iovec data, not just strings, and hence also doesn't do stdio at
all. It's hence a lot more low-level.

We might want to consider moving write_string_file*() on top of
write_data_file_atomic_at(), but for now don't.
2026-03-20 11:53:33 +01:00
Zbigniew Jędrzejewski-Szmek a0eae2ab7b Stop disabling -Wattributes
In one of the reviews one of the LLMs noticed that the pragma is set but
never unset, so it remains in effect for the rest of the translation
unit. From the comment, it's not clear how old those "old compilers" were,
so let's try if things work without this workaround.
2026-03-19 11:46:30 +01:00
Dylan M. Taylor 7a858878a0 userdb: add birthDate field to JSON user records
Add a birthDate field to the JSON user record, stored internally as a
struct tm with INT_MIN/negative sentinels for unset fields. The field
is serialized as a YYYY-MM-DD string in JSON and validated via
parse_birth_date(), which shares its core logic with
parse_calendar_date() through a new parse_calendar_date_full()
function.

For birth dates, timegm() is called directly (rather than
mktime_or_timegm_usec) to support pre-epoch dates. The wday field is
used to distinguish timegm() failure from a valid (time_t) -1 return.

birthDate is excluded from user_record_self_modifiable_fields(), so
only administrators can set or change it via homectl. The field
remains in the regular (non-privileged) JSON section, keeping it
readable by the user and applications.
2026-03-18 17:33:22 -04:00
Dylan M. Taylor 770958e24a time-util: extract parse_calendar_date() from sysupdate
Move the YYYY-MM-DD date parsing and validation logic from
sysupdate-resource.c into a shared parse_calendar_date() function
in time-util, so it can be reused by other subsystems.
2026-03-18 09:39:06 -04:00
Luca Boccassi cd1f2f2ff9 sd-dlopen: make macros to generate .notes.dlopen sections public API (#41047)
If this new scheme of adding dependencies is supposed to be used more
widely we need to start making it easy to add them. So add a new
self-contained header that projects can simply include without the need
to link against libsystemd itself. This will allow them to generate
`.notes.dlopen` sections:

```
> readelf -p .note.dlopen ./l2md

String dump of section '.note.dlopen':
  [     a]  |@FDO
  [    10]  [{"feature":"manifest-json","description":"Manifest-based change detection via gzip and JSON parsing","priority":"suggested","soname":["libz.so.1","libsystemd.so.0"]}]
  [    c2]  |@FDO
  [    c8]  [{"feature":"manifest-http","description":"HTTP transport for lore.kernel.org manifest fetch","priority":"suggested","soname":["libcurl.so.4"]}]
```
2026-03-18 12:33:58 +00:00
Nandakumar Raghavan a4aae32478 ansi-color: fix SYSTEMD_COLORS=true regression when output is piped
The SYSTEMD_COLORS=true/1/yes no longer forced colors
when stdout was not a TTY (e.g. piped), because the COLOR_TRUE bypass
of the terminal_is_dumb() check was accidentally dropped.

Restore the old behavior by guarding the TTY check with
`m != COLOR_TRUE`, so an explicit boolean "true" value continues to
unconditionally force color output regardless of whether stdout is a TTY
or whether $NO_COLOR is set.
2026-03-18 12:03:38 +01:00
Christian Brauner 8b12350b75 dlfcn-util: migrate to public SD_ELF_NOTE_DLOPEN() API
Switch all internal callers from the private ELF_NOTE_DLOPEN() macro to
the new public SD_ELF_NOTE_DLOPEN() API from sd-dlopen.h, and remove
the now-redundant macro definitions from dlfcn-util.h.

Signed-off-by: Christian Brauner <brauner@kernel.org>
2026-03-18 10:28:11 +00:00
Luca Boccassi 69e4ba69d6 udev: ensure there is space for trailing NUL before calling sprintf
sprintf will write 5 characters, as it adds a trailing NUL byte.

Reported on yeswehack.com as:
YWH-PGM9780-62

Follow-up for 8cfcf9980a
2026-03-10 21:29:14 +00:00
Zbigniew Jędrzejewski-Szmek dc0b438836 various: use asprintf_safe in more places 2026-03-06 17:46:59 +01:00
Zbigniew Jędrzejewski-Szmek 52abc9fe96 basic/stdio-util: introduce asprintf_safe
asprintf is nice to use, but the _documented_ error return convention is
unclear:
> If  memory  allocation  wasn't possible, or some other error occurs,
> these functions will return -1, and the contents of strp are undefined.

What exactly "undefined" means is up for debate: if it was really
undefined, the caller wouldn't be able to meaningfully clean up, because
they wouldn't know if strp is a valid pointer. So far we interpreted
"undefined" — in some parts of the code base — as "either NULL or a
valid pointer that needs to be freed", and — in other parts of the
codebase — as "always NULL". I checked glibc and musl, and they both
uncoditionally set the output pointer to NULL on failure.

There is also no information _why_ asprintf failed. It could be an
allocation error or format string error. But we just don't have this
information.

Let's add a wrapper that either returns a good string or a NULL pointer.
Since there's just one failure result, we don't need a separate return
value and an output argument and can simplify callers.
2026-03-06 17:46:59 +01:00
Zbigniew Jędrzejewski-Szmek d1278e1847 basic/alloc-util: make realloc0 non-inline
It's actually only used in one place in libsystemd and moving it even makes
libsystemd smaller (in a non-optimized build):

$ ls -l build/libsystemd.so.0.43.0*
-rwxr-xr-x 1 zbyszek zbyszek 5763336 Mar  3 09:54 build/libsystemd.so.0.43.0-old
-rwxr-xr-x 1 zbyszek zbyszek 5763216 Mar  3 09:54 build/libsystemd.so.0.43.0

Also, move the definitions in the .h file so that similar functions are
grouped together and then move the definitions around in the .c file so
that they are in the same order as in the header.
2026-03-06 17:46:59 +01:00
Zbigniew Jędrzejewski-Szmek 3abe1e53f6 basic/allow-util: make free_many non-inline
Definition of free_many is moved to the .c file, no particular reason
for it to be inline and we can make the header file shorter.
2026-03-06 17:46:59 +01:00
Yu Watanabe 8903e6b5f7 tree-wide: suppress misc-use-internal-linkage warnings
Suppress warnings like the following from clang tidy:
```
../src/boot/addon.c:11:19: error: function 'efi_main' can be made static to enforce internal linkage [misc-use-internal-linkage,-warnings-as-errors]
   11 | EFIAPI EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *system_table);
      |                   ^
```

Some warnings are suppressed simply by setting comments to ignore the warning,
some are by making global variables static, or include a suitable header.
2026-03-05 20:23:24 +01:00
Mike Yuan df51a04a75 path-util: drop unused paths_check_timestamp() 2026-03-06 02:39:39 +09:00
Frantisek Sumsal 90f5d2a202 tree-wide: various fixlets suggested by Coccinelle 2026-03-05 10:27:58 +01:00
Lennart Poettering 5f85409f93 tpm2-util: also load libtss2-tcti-device.so.0 in dlopen_tpm2()
This TCTI module is the one we need to actually access a Linux TPM
device, we'll hence pretty much always need it if we do TPM at all.
Given that we nowadays turn off dlopen() after fork() in the child,
let's explicitly load it as part of dlopen_tpm2() so that it is
available whenever TPM2 is used.
2026-03-04 08:28:29 +01:00
Mike Yuan 36d30330f7 ansi-color: in 256 mode, always set the fallback color first
Linux console is very weird when it comes to ANSI color sequences.
Not only that it isn't aware of ':' separator (c.f.
https://github.com/systemd/systemd/pull/40878#issuecomment-3979826739),
it even skips the whole CSI-m sequence if it contains parts it cannot
parse. Hence when color mode is set to 256 (i.e. default when no
extra info is available) let's always emit two distinct CSI-m sequences,
and set the fallback 16 color first in case the terminal doesn't have
complete support for the 256 one.

Replaces #40905
2026-03-03 23:56:05 +01:00
Mike Yuan 085f92730a tree-wide: use ALPHANUMERICAL where appropriate
Prompted by 43116c5662
2026-03-04 07:36:10 +09:00
Yu Watanabe 43116c5662 tree-wide: use DIGITS and friends 2026-03-03 22:18:26 +01:00
Lennart Poettering d2b27a7a8c xstatx_full(): add flag to acquire STATX_MNT_ID_UNIQUE if we can, with fallback. 2026-03-03 08:49:23 +01:00
Lennart Poettering 2e9208199f stat-util: teach statx_mount_same() STATX_MNT_ID_UNIQUE
So far statx_mount_same() assumed STATX_MNT_ID_UNIQUE didn't exist.
However it does exist, hence do something useful if we see it set. Note
that this creates a certain ambiguity: if we compare one statx struct
with STATX_MNT_ID_UNIQUE and one without it (but with the regular mnt
id), then we cnanot really come to a clear conclusion, hence need to
introduce a third, unknown state.

Note that we don't request STATX_MNT_ID_UNIQUE yet wherever we call
statx_mount_same(). THis will be added in a later commit.
2026-03-03 08:48:01 +01:00
Lennart Poettering e4206858ad fd-util: minor shortcut 2026-03-03 08:48:01 +01:00
Lennart Poettering 4023840ffa fd-util: rename fds_are_same_mount() fds_inode_and_mount_same()
The old name suggested this would only check if the two inodes are on
the same mount, but it actually checks if they are the same inodes too.

Let's rename it to make this clearer, in particular as we have
both statx_inode_same() and statx_mount_same() already, and they are
even used here, and hence very confusing.

This also drops two checks from the test case, which are simply wrong.
Given they apparently weren't load bearing (since no CI tripped up),
let's just drop them.
2026-03-03 08:48:01 +01:00
Lennart Poettering 0384875582 chase: drop wrong optimization
The same optimization is already applied in the very similar
dir_fd_is_root() check a few lines up – with the exception that it
doesn't accept AT_FCWD there. And frankly turning off
CHASE_AT_RESOLVE_IN_ROOT if we operate on AT_FCWD is simply wrong. Hence
remove this code.
2026-03-03 08:48:01 +01:00
Lennart Poettering 3538b77f9d chase: tighten checks on ".." once we hit the root of an CHASE_AT_RESOLVE_IN_ROOT root tree
Let's harden things in case concurrent access is allowed to a root tree
passed via CHASE_AT_RESOLVE_IN_ROOT: let's not just validate via the
path if we hit the root of the tree, but also by comparing inodes +
mount ids.

Hardening opportunity reported by Sebastian Wick.
2026-03-03 08:48:01 +01:00
Lennart Poettering c8031ff37e chase: port to statx()
In one of the next commits we want to acquire .stx_mnt_id from statx()
for each inode we traverse (plain fstat() doesn't provide that field).
Hence let's port chase() over to statx() as preparation for that.

No change in behaviour.
2026-03-03 08:48:01 +01:00
Lennart Poettering 004e60e0fc chase: put limit on overall chase cycles
Let's add some protections in case we deal with inodes owned by an
untrusted person, with concurrent access: let's put a limit on how long
we traverse, and fail eventually so that live changes cannot send us in
circles indefinitely.

This reworks the current CHASE_MAX logic so that it not only applies to
symlinks transitions, but to any transitions.

This also bumps CHASE_MAX a bit, given that it's now bumped on every
single iteration of the loop.
2026-03-03 08:48:01 +01:00
Lennart Poettering 97fe03e12f stat-util: add statx() flavours of stat_verify_regular() + stat_verify_socket() 2026-03-03 08:48:01 +01:00
Lennart Poettering 36d7e177ad fd-util: make use of XAT_FDROOT in path_is_root_at() 2026-03-03 08:48:01 +01:00
Mike Yuan a12a4bdc9a pidref: do not tamper with pidref_acquire_pidfd_id() retval
If a pidfd id is passed to us, it must have originated from
somewhere, i.e. pidfs should be supported on the system.
Hence let's be honest about -EOPNOTSUPP, which might indicate
some bigger problems under the hood, rather than allowing
it to be turned into mild -ESRCH.
2026-03-02 15:25:53 +09:00
Yu Watanabe 5ae3bb09c6 mountpoint-util: add overlay check to fstype_is_blockdev_backed() and simplify fstype_is_api_vfs() (#40866) 2026-03-02 13:15:14 +09:00
Mike Yuan abffc0ef43 process-util: leave actual log fd closing to close_all_fds() if the latter will be done anyways 2026-03-01 13:18:19 +01:00
Lennart Poettering d423ec258c nss-systemd,strv: use a common definition of a non-NULL but empty strv
Follow-up for: 239903d44c
2026-03-01 08:51:14 +01:00
Pontus Lundkvist 352bb934fe mountpoint-util: remove duplicate check in fstype_is_api_vfs()
devtmpfs is part of the @basic-api filesystem-set
2026-02-27 14:10:27 +01:00
Pontus Lundkvist d4acc09d9d mountpoint-util: add exempt for overlay in fstype_is_blockdev_backed()
This allows `systemd-mount` to be used with --type overlay
2026-02-27 14:06:09 +01:00