Commit Graph
7385 Commits
Author SHA1 Message Date
Daan De Meyer 52ecf376fa tree-wide: Migrate to pidref_safe_fork()
Let's migrate all remaining callers of safe_fork()
to pidref_safe_fork() and get rid of safe_fork().
2026-01-02 20:08:41 +01:00
Daan De Meyer e6703a9aa4 process-util: Use ret as output parameter name
There's only one output parameter for all these
functions, so let's just name it ret following the
coding style.
2026-01-02 19:44:18 +01:00
DaanDeMeyer 47d22e41e4 unit-def: Clean up whitespace 2026-01-02 06:28:39 +09:00
Daan De Meyer aec52c1e6e string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends
Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes
2026-01-02 04:05:45 +09:00
Daan De Meyer daff8ea8bb tree-wide: Introduce DECLARE_TRIVIAL_REF_UNREF_FUNC() and friends 2026-01-02 04:04:19 +09:00
Lennart Poettering ceaa36c21e terminal-util: use the right ANSI ST sequence
There are multiple ways to encode ANSI ST, and we generally prefer ESC \
for it, for reasons explained in terminal-util.h. Hence, let's actually
follow this rule in the terminal reset logic, and use the ANSI_ST macro.

This will change the byte sequence generated (as it means we use ESC \
rather than BEL), but it doesn't change behaviour, as the two sequences
should be equivalent.
2025-12-24 09:40:43 +01:00
Jörg Behrmann 1afe5c7b4b terminal-util: also send ANSI_NORMAL in terminal_reset_ansi_seq
Certain terminal emulators (alacritty, ghostty and kitty) require ANSI_NORMAL
to be sent to reset the colours.

Followup for 3d97db8f3c.

Fixes: #40163
2025-12-24 07:59:42 +01:00
Luiz Amaral c1c787651b Add support for binding a unit to a network iface 2025-12-24 07:37:58 +01:00
Daan De Meyer 5b830eda79 signal-util: Use act instead of __act in comment
The clang-tidy check ignores trailing and
preceeding underscores, so let's just use act
instead of __act.
2025-12-21 19:21:08 +01:00
Lennart Poettering b6aa78f707 recursedir: introduce new RECURSE_DIR_UNLINK callback return value
This introduces RECURSE_DIR_UNLINK + RECURSE_DIR_UNLINK_GRACEFUL as new
return values for recurse_dir() callbacks. If either is returned the
inode currently processed will be removed and iteration continues with
the next item.

This is useful to have in the recurse_dir() mechanism itself (rather
than implement in the callback itself), due to ordering: we want to pin
the inodes via an fd while calling the callbacks, but we have to close
it before removal of the inodes. By moving this into the recurse_dir()
infra, we can implement this easily.
2025-12-21 07:04:42 +01:00
Mike Yuan f3c6660b9c pidref: several follow-ups for pidref_wait_for_terminate_full()
Follow-up for e74b571004

* Do not reuse si
* Refuse timeout == 0
* Use usec_add()
* Rename ret to ret_si - unlike others this one is not so obvious
2025-12-20 21:41:01 +01:00
Mike Yuan eb17c37df7 process-util: drop unused sched_priority_is_valid() 2025-12-20 18:38:56 +01:00
Matt Fleming 4dcbfbb1ad process-util: Add support SCHED_EXT scheduling policy
Allow CPUSchedulingPolicy to be set to "ext". SCHED_EXT is a new
scheduling policy in Linux v6.12 that allows processes to be scheduled
using custom BPF schedulers instead of the default in-kernel ones.

Selectively setting the SCHED_EXT policy is useful for systems running
in "partial mode" where not all processes are run using a custom
scheduler.

Fallback to SCHED_OTHER and print an error message for systems where
SCHED_EXT isn't available.
2025-12-20 18:31:55 +01:00
Daan De Meyer fbd276cb86 tree-wide: Use pidref_wait_for_terminate_and_check()
Let's use the pidref variants for waiting and
checking a process everywhere and get rid of the
non pidref variants.
2025-12-20 15:50:47 +01:00
Daan De Meyer e74b571004 pidref: Add pidref_wait_for_terminate_full()
We can use this to replace wait_for_terminate_with_timeout(). Because
we poll a pidfd, we don't need to block SIGCHLD anymore in umount.c.
2025-12-20 15:49:26 +01:00
Daan De Meyer 8c367868ee process-util: Use pidref_wait_for_terminate_and_check in pidref_safe_fork()
Note that we still have to block SIGCHLD so that
we can be certain the process is not reaped before
we get the pidfd to it. safe_fork() and friends are
used in libsystemd where we don't control how the
SIGCHLD signal is configured. Specifically, kernel
autoreaping could be enabled which is why we have
to block SIGCHLD until we get the pidfd so that the
kernel cannot autoreap the process before we get
the pidfd.
2025-12-20 15:44:20 +01:00
Daan De Meyer a1e5d7f865 sd-event: Clean up SIGCHLD conditions for sd_event_add_child()
First, don't require blocking SIGCHLD for WEXITED. We watch for WEXITED
via pidfd instead of signalfd, so no need to insist on blocking SIGCHLD
anymore if we're only watching for WEXITED.

Second, do a proper check to see if the kernel autoreaping logic is
enabled. That has nothing to do with SIGCHLD being blocked for the current
thread or not. Instead, the kernel autoreaping logic is enabled either if
the disposition is set to SIG_IGN or if the SA_NOCLDWAIT flag is enabled.
2025-12-20 15:27:22 +01:00
Mike Yuan 73c40aa1f6 process-util: synchronously wait for namespace_enter() before returning
Additionally, report actual errors using errno pipe too.
2025-12-20 14:27:46 +01:00
Mike Yuan ed0f6758c8 process-util: revamp flags handling in namespace_fork()
* Specifying all 3 of FORK_DEATHSIG_SIG{KILL,TERM,INT} for
  the middle man makes zero sense. Use SIGKILL only.
* Make sure operations on except_fds work sensibly - close/pack/
  de-ocloexecify fds only in the second level, so that the namespace
  fds remain usable across first safe_fork().
* Fire FORK_NEW_*NS after attaching to the desired namespaces,
  not already in the outer process.
* Insist on PDEATHSIG being enabled to ensure propagation of killing.
* Suppress more redundant flags.
2025-12-20 14:14:24 +01:00
Daan De MeyerandMike Yuan 8c007f68ff process-util: Migrate namespace_fork() to PidRef
Co-authored-by: Mike Yuan <me@yhndnzj.com>
2025-12-20 13:45:22 +01:00
Mike Yuan 3532691d72 process-util: trivial cleanup for read_errno() 2025-12-20 13:45:22 +01:00
Mike Yuan e48e098db1 process-util: dedup restore_sigsetp() with block_signals_reset() 2025-12-20 13:45:21 +01:00
Lennart Poettering 627e583c64 Use ANSI CSI 18 to query console size (#39833) 2025-12-18 20:49:26 +01:00
Daan De Meyer 30465f789c test: introduce test-sleep and use it in several integration tests (#40086) 2025-12-18 17:47:57 +01:00
Zbigniew Jędrzejewski-Szmek d91a184509 core: use terminal_get_size_by_csi18 to query terminal size
This allows us to query the window size without moving the cursor. We have
various reports about the cursor being in an unexpected position and/or state.

Closes https://github.com/systemd/systemd/issues/37526.
2025-12-18 10:47:19 +01:00
Mike Yuan 8f397d5922 core/unit: add unit_fork_helper_process_full() that takes ForkFlags 2025-12-16 21:30:36 +01:00
Mike Yuan 29a823b3b6 process-util: add a flag for retaining dlopen()-ability
While blocking dlopen() in child generally makes sense, it does
also lead to misery - in the very case of extension/cred refreshing
it then enforces loading of libcryptsetup/libacl in pid1, which
are otherwise never used. Let's add a flag to opt out hence, but
still prohibit it in namespace_fork/enter().
2025-12-16 21:07:20 +01:00
Luca Boccassi f9a6c04d14 basic: add GUEST_MEMFD_MAGIC from 6.19
1/1815 systemd:kernel-filesystem-magics FAIL 0.05s exit status 1
――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――
stderr:
kernel knows additional filesystem magics: GUEST_MEMFD_MAGIC
2025-12-16 11:44:43 +00:00
Yu Watanabe 78385b8e94 time-util: make usleep_safe() support USEC_INFINITY 2025-12-15 18:09:21 +09:00
Yu Watanabe b8241d3ca5 time-util: continue sleeping when clock_nanosleep() fail with EINTR
The function clock_nanosleep() provides remaining time when failed with
EINTR. Let's continue sleeping in that case.
2025-12-15 17:50:19 +09:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Alexis-Emmanuel Haeringer 595d88cdc8 conf-files: include the expected suffix in the 'unexpected suffix' debug message. 2025-12-13 11:46:37 +01:00
David Tardon 94446e4f5a tree-wide: flatten nested error checks 2025-12-10 18:59:44 +09:00
Zbigniew Jędrzejewski-Szmek 12391431c2 machined: add description to varlink server, unify error messages
manager_varlink_init_resolve_hook and manager_varlink_init_userdb are very
similar, but one didn't set a description and the other one had an error
message which didn't print the offending path.

Define constants for the paths, and also change other similar constants
to have slightly shorter names. (It's an "address" and "path", but we don't
need to have both parts in the name, esp. that it makes the name very long.)
2025-12-05 12:17:06 +01:00
Luca Boccassi a3b6ad69ab cgroup-util: fix cg_pid_get_user_unit() to actually query user units
Refactor switched to the wrong implementation for this inline,
breaking querying for user units

Fixes https://github.com/systemd/systemd/issues/39949

Follow-up for 015025cba2
2025-12-02 10:50:41 +09:00
Daan De Meyer 6a9f0641cd tree-wide: Fix declaration/definition parameter name mismatches 2025-11-26 19:02:31 +09:00
Yu Watanabe b7f892b390 core/mount: comprehensively disable mount unit support if no libmount (#39884) 2025-11-26 16:29:30 +09:00
Daan De Meyer 9a6a8f35eb tree-wide: Small fixes for various clang-tidy warnings 2025-11-26 16:22:00 +09:00
Mike Yuan f76f91b7c9 dlfcn-util: fix potential dl handle leak
Follow-up for 2c7bdaf9f1
2025-11-26 01:41:51 +01:00
Zbigniew Jędrzejewski-Szmek 1d26bac43f tree-wide: Fix constness issues with newer glibc (#39896)
Latest glibc uses _Generic to have strstr() and other functions return
const char* or char* based on whether the input is a const char* or a
char*. This causes build failures as we previously always expected a
char*.

Let's fix the compilation failures and add our own macros similar to
glibc's to have string functions that return a mutable or const pointer
depending on the input.
2025-11-26 00:32:54 +01:00
Daan De Meyer 0bac1ed242 tree-wide: Fix constness issues with newer glibc
Latest glibc uses _Generic to have strstr() and other functions return
const char* or char* based on whether the input is a const char* or a
char*. This causes build failures as we previously always expected a char*.

Let's fix the compilation failures and add our own macros similar to glibc's
to have string functions that return a mutable or const pointer depending on
the input.
2025-11-25 20:49:39 +01:00
Daan De Meyer 33b0642e6a tree-wide: sizeof() fixes
- TIME_T_MAX is always time_t so the check in time-util.c was redundant
- quota-util.c was zero-ing a pointer
- smbios11.c was calling sizeof(pointer)
2025-11-25 17:34:48 +01:00
Daan De Meyer c36942916b run0: Give --empower its own color, title and emoji
When in --empower mode, all created files will be owned by the current
user, which could be problematic when creating files outside of the
current user's home directory, as other processes running as the same
user would be able to edit those files.

While this is a bit of an edge case since users already have to go through
the effort of writing --empower to indicate they want a privileged session
as the current user, it's not unphatomable to think they could start an
empowered session which they later return to and continue using. Currently,
it's not easy to differentiate a regular run0 session and an empowered session
at a glance, so users might think they're using a regular run0 session when
they're actually using an empowered session.

To address this problem, let's give empowered session their own identify, by
making the background orange, using the pumpkin emoji as the shell prompt
prefix and giving them an orange circle as the PTY title.
2025-11-25 17:15:30 +01:00
Yu Watanabe 05afbcc377 process-util: fix typo
Follow-up for a08f2ea02d.
2025-11-25 22:52:10 +09:00
Zbigniew Jędrzejewski-Szmek 7fd5f7aade Adjust code to query terminal size and other attributes (#39832) 2025-11-25 11:43:26 +01:00
Zbigniew Jędrzejewski-Szmek e698ee5705 basic/terminal-util: ignore failures in cleanup
Some of the functions were ignoring failure in cleanup, others weren't. If we
got a reply, it's better to use it, so ignore failures in cleanup everywhere.
2025-11-24 21:48:28 +01:00
Zbigniew Jędrzejewski-Szmek 46f6742911 basic/terminal-util: operate on one fd in get_default_background_color()
This moves the open call earlier, so that we do any state-changing operations
if we actually managed to open the nonblocking fd. The code is easier to follow
this way and might be more robust.

Suprisingly, this fixes https://github.com/systemd/systemd/issues/39055: it
seems that run0 chowns /dev/stdin (in my case /dev/pts/0) to root:root, and the
second run0 can read and write stdin/stdout throught the already-open fds,
but fd_reopen fails.

Fixes https://github.com/systemd/systemd/issues/39055.
2025-11-24 21:47:57 +01:00
Lennart Poettering c746488537 block dlopen() once we transition into some foreign namespace (#39824)
Let's make sure we never accidentally end up loading code from a foreign
namespace.
2025-11-24 14:14:16 +01:00
Yu Watanabe f866ff3df8 tree-wide: replace tab with space, adjust missing or duplicated space 2025-11-24 12:45:06 +01:00
Lennart Poettering a08f2ea02d process-util: also disable dlopen() in safe_fork() 2025-11-24 11:56:47 +01:00