Commit Graph
7000 Commits
Author SHA1 Message Date
Jelle van der Waa 93117b0fbd cgroup-util: rename 'fsfd' -> 'cgroups_fd'
Makes the header and implementation consistent.
2025-06-04 10:45:54 +02:00
Lennart Poettering d483ac1d0d compress: avoid a bunch of div-by-zeroes
Follow-up for #37706. Implements the same logic for all compression
algorithms we have.
2025-06-03 18:27:02 +02:00
Yu Watanabe a491eca403 Bugprone argument comment 8 (#37678)
Follow up from https://github.com/systemd/systemd/pull/37556
2025-06-03 10:58:52 +09:00
Alexandjinyaoguo 2584f745e0 compress: prevent divide-by-zero when no data is read (#37706)
If the first call to `loop_read()` returns 0 (no input), `total_in`
remains 0, causing `total_out/total_in` to potential divide by zero.

We add a check before logging the compression ratio to skip the
percentage calculation when total_in is zero.

Co-authored-by: jinyaoguo <guo846@purdue.edu>
2025-06-03 10:51:00 +09:00
Jelle van der Waa fa6f4484e8 io-util: rename 'nfds' -> 'n_fds' 2025-06-02 18:05:45 +02:00
Jelle van der Waa 8821a312a8 uid-range: correct argument comment 2025-06-02 17:39:44 +02:00
Jelle van der Waa d4f938aec1 env-util: rename 'n' -> 'length' 2025-06-02 17:39:43 +02:00
Zbigniew Jędrzejewski-Szmek b83f69952b Deduplicate error string patterns (#37676)
I wanted to see if moving moving out constant string arguments our of
error messages results in smaller binary sizes. Turns out it does, but
the savings are not consistent. Sometimes we get a few kB in a single
binary, sometimes there is no size change.
2025-06-02 15:34:17 +02:00
Adrian Vovk 554130faf3 Define uid range for greeter
In multi-seat scenarios, a display manager might need to start multiple
greeter sessions. But systemd allows at most one graphical session per
user. So, display managers now have a range of UIDs to dynamically
allocate users for their greeter sessions.
2025-06-02 11:19:12 +02:00
Zbigniew Jędrzejewski-Szmek 42ba99748d various: do not include file names directly in error messages
git grep -l 'Failed to open /'|xargs sed -r -i 's|"Failed to open (/[^ ]+): %m"|"Failed to open %s: %m", "\1"|g'
git grep -l $'Failed to open \'/'|xargs sed -r -i $'s|"Failed to open \'(/[^ ]+)\': %m"|"Failed to open %s: %m", "\\1"|g'
git grep -l "Failed to open /"|xargs sed -r -i $'s|"Failed to open (/[^ ]+), ignoring: %m"|"Failed to open %s, ignoring: %m", "\\1"|g'
+ some manual fixups.
2025-06-02 11:10:38 +02:00
Lennart Poettering 1105f8d20f tree-wide: only use .si_pid field in siginfo_t, if .si_code indicates that's safe
Fixes: #37498
2025-05-31 14:48:37 +02:00
Yu Watanabe 3ec92f2f74 terminal-util: fix typo
Follow-up for 5321b957b4.
2025-05-31 04:44:34 +09:00
Mike Yuan 4d67fcabed env-util: add missing assertions 2025-05-29 21:01:43 +02:00
Mike Yuan a9b053deb1 env-util: modernize *_is_valid() 2025-05-29 21:01:43 +02:00
Mike Yuan c51379e6d8 Use DCS sequence to query terminal name and set $TERM automatically (#37538)
This code seems to work quickly and nicely for a bunch of modern
terminals. Setting $TERM automatically removes an common annoyance for
users. This code will not work for all terminal emulators, but by adding
it in systemd we'll entice maintainers of those terminals to add support
for the sequences. For the terminals that don't support the sequence, we
get a bit of a slowdown of `< 1 ms`, which seems hardly noticeable. The
user can always set TERM explicitly to avoid this if upgrading to a
newer terminal emulator is not possible.

Closes https://github.com/systemd/systemd/issues/36994.
2025-05-29 21:01:01 +02:00
Zbigniew Jędrzejewski-Szmek f256e48d4e basic/terminal-util: drop now-unused default_term_for_tty 2025-05-29 19:20:31 +02:00
Zbigniew Jędrzejewski-Szmek ad6ca4a612 core: use terminal DCS sequence to set $TERM
query_term_for_tty() is used in two places: in fixup_environment(),
which affects PID1 itself, and in build_environment(), which affects
spawned services. There is obviously some cost to the extra call,
but I think it's worthwhile to do it. When $TERM is set incorrectly,
basic output works OK, but then there are various annoying corner
cases. In particular, we get the support for color (or lack of it)
wrong, and when output is garbled, users are annoyed. Things like
text editors are almost certain to behave incorrectly. Testing in
test-terminal-util indicates that the time required to make a successful
query is on the order of a dozen microseconds, and an unsuccessful
query costs as much as our timeout, i.e. currently 1/3 ms. I think
this is an acceptable tradeoff.

No caching is used, because fixup_environment() is only called once,
and the other place in build_environment(), only affects services
which are connected to a tty, which is only a handful of services,
and often only started in special circumstances.

Fixes https://github.com/systemd/systemd/issues/36994.
2025-05-29 19:20:31 +02:00
Zbigniew Jędrzejewski-Szmek e3b050a5c2 basic/terminal-util: add a heuristic check whether terminfo file exists 2025-05-29 19:20:31 +02:00
Zbigniew Jędrzejewski-Szmek 5321b957b4 basic/terminal-util: query terminal name by DCS
As requested in https://github.com/systemd/systemd/issues/36994,
use DCS + q name ST. This works, but has limited terminal support:
xterm, foot, kitty.
2025-05-29 19:20:31 +02:00
Mike Yuan cd3435fc0b cgroup-util: drop CGROUP_MASK_EXTEND_JOINED
Also kill the "compat pair invalidation" logic in unit_invalidate_cgroup()
2025-05-28 00:53:24 +02:00
Mike Yuan 9e73d37512 cgroup-util: move CGROUP_CPU_SHARES/BLKIO* to nspawn-oci
These are only used for translation from OCI metadata
to cgroup v2 values.
2025-05-28 00:21:37 +02:00
Yu Watanabe ae6420c923 cgroup-util: minor cleanups (#37630) 2025-05-28 02:19:21 +09:00
Jan Vaclav a8a39e23bb in-addr-util: use s6_addr* macros everywhere
Currently, the code in in-addr-util.c uses a mix of accessing the
in6_u members directly, as well as using the s6_addr* macros.
Let's unify it so that the s6_addr macros are used everwhere.
2025-05-27 22:33:57 +09:00
Mike Yuan a941822d1c cgroup-util: assert on attribute for cg_{get,set}_attribute()
It makes zero sense to ever perform IO operations on cgroup dirs.
2025-05-27 14:31:06 +02:00
Mike Yuan 606ef91a40 cgroup-util: make cg_get_attribute_as_bool() return 0/1 directly
As with getenv_bool() and getxattr_at_bool(), to match
our usual style.
2025-05-27 14:28:08 +02:00
Mike Yuan 7b4022bdb0 cgroup-util: rename cg_get_xattr_malloc -> cg_get_xattr
This is not a trivial wrapper around user-created-buffer-based
syscall, so do not use _malloc suffix. Most of our functions
return an internally allocated buffer and this one's not special.
2025-05-27 14:28:08 +02:00
Daan De Meyer c5d7a2d000 basic,shared: mark eligible functions with _pure_/_const_ (#37623) 2025-05-27 14:24:30 +02:00
Zbigniew Jędrzejewski-Szmek 976295bf8b repart: Copy fs-verity status for CopyFiles= (#35401)
When populating a filesytem with CopyFiles=, we first copy the files to
a temporary directory. Make sure we use the (new) COPY_FS_VERITY flag
when doing that copy so that the `mkfs` that we invoke can see the files
with fs-verity enabled.

Closes #35352
2025-05-27 14:01:05 +02:00
Allison Karlitskaya 56a279a7f7 copy: add support for copying fs-verity status
Add a new member to CopyFlags to request copying of fs-verity status.

If copying of fs-verity is requested then we query the descriptor from
each regular file.  If it has one, we use it to setup fs-verity on the
destination, using the same parameters.

Signatures don't seem to be a particularly well-loved (or used) feature
of fs-verity and we don't bother to query them here.  Support for that
could be added later, if desired.

This change means that, with the correct combination of flags, we might
end up calling `fsync()` on a read-only file descriptor.  This is
permitted by POSIX and supported on Linux.

Nothing uses this yet.

Signed-off-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
2025-05-27 08:08:34 +02:00
Mike Yuan 7f436569c1 fs-util: prefer linkat(AT_EMPTY_PATH) over /proc/self/fd/ shenanigans
The permission check got relaxed in kernel v6.10, so let's
switch the fallback order around.

This also effectively reverts 94d94f0c0a,
as I just realized that link_fd() involves multiple paths and
we can't tell which one tripped ENOENT...
2025-05-27 12:19:22 +09:00
Mike Yuan b823f7bb6a cgroup-util: remove now unused cg_read_event()
cg_get_keyed_attribute() is a more generic version of this,
and cg_is_empty_recursive() was the only user of this function,
which got converted in the previous commit.
2025-05-26 22:59:48 +02:00
Mike Yuan c3f900770d cgroup-util: drop handcrafted cg_is_empty(), always check cgroup.events populated field
This effectively renames cg_is_empty_recursive() to cg_is_empty().
Note that all existing code calls the former and not the latter,
hence with cgv1 support being dropped it's trivial to consult
cgroup.events directly for populated state everywhere.

Additionally, use more generic cg_get_keyed_attribute() helper
rather than cg_read_event().
2025-05-26 22:59:48 +02:00
Daan De Meyer f1ee656d4d tree-wide: Handle EINVAL as not supported for chattr_xxx()
F2FS returns EINVAL from FS_IOC_SETFLAGS when trying to set
FS_NOCOW_FL. Let's handle this by treating EINVAL as not supported.
While we're at it, make sure we use ERRNO_IS_IOCTL_NOT_SUPPORTED()
across the tree instead of ERRNO_IS_NOT_SUPPORTED() when calling any
of the chattr_xxx() functions.

Fixes #37593
2025-05-26 21:59:08 +02:00
Daan De Meyer 8cf13c8752 socket-util: Move getsockopt_int() to implementation file
And switch back to negative_errno() at the same time.
2025-05-26 21:28:10 +02:00
Mike Yuan 180341e732 basic,shared: mark eligible functions with _pure_/_const_
Following the recent witch hunt done to static inline functions
I figure we should at least give the compiler some more hint
on optimizations.
2025-05-26 20:26:58 +02:00
Mike Yuan 5a881f7f71 errno-list: errno_from_name() is pure but not const
Follow-up for 0c15577abe
2025-05-26 20:24:43 +02:00
Mike Yuan 82775307c5 fd-util: group close_fd_ptr() with fd funcs, not FILE/DIR stream ones 2025-05-26 20:21:22 +02:00
Daan De Meyer 0c15577abe basic + fundamental: Clean up includes
Split out of #37344.
2025-05-25 10:06:07 +02:00
Daan De Meyer e6e6131a2c login-util: Mark session_id_valid() as pure 2025-05-25 10:05:47 +02:00
Daan De Meyer 1aabcd7454 basic: Move userns_supported() to namespace-util.h 2025-05-25 10:00:54 +02:00
Daan De Meyer 01655aec3b strv: Drop unnecessary macros 2025-05-25 09:58:09 +02:00
Daan De Meyer b4736d9a25 basic: Move LogRatelimit struct to log-ratelimit.h as well 2025-05-25 09:40:26 +02:00
Daan De Meyer 4cfd024e73 forward: Move ChaseFlags forward declaration to forward.h 2025-05-24 20:44:12 +02:00
Daan De Meyer b416ac0e15 basic: Move ratelimit logging functions to log-ratelimit.h 2025-05-25 03:28:50 +09:00
Jelle van der Waa 3ce64b0fbe cgroup-util: rename 'kill_log' -> 'log_kill'
Rename according to the implementation.
2025-05-24 17:13:39 +02:00
Jelle van der Waa 684cd01f0e cgroup-util: rename 's' -> 'killed_pids' 2025-05-24 16:58:56 +02:00
Yu Watanabe 9d75fb9647 linux: update kernel headers from v6.15-rc7 2025-05-24 03:04:22 +09:00
Lennart Poettering ceed11e465 path-util: invert PATH_STARTSWITH_ACCEPT_DOT_DOT flag
As requested: https://github.com/systemd/systemd/pull/37572#pullrequestreview-2861928094
2025-05-23 06:51:45 +02:00
Lennart Poettering 482107724f cgroup: port some code over to path_startswith_full() 2025-05-23 06:51:43 +02:00
Lennart Poettering ee19edbb9f path-util: add flavour of path_startswith() that leaves a leading slash in place 2025-05-23 06:50:30 +02:00