Commit Graph

7245 Commits

Author SHA1 Message Date
Yu Watanabe
9b414a38fa tree-wide: drop unused libcap dependencies 2025-10-24 01:52:59 +09:00
Yu Watanabe
a98f710fdf capability-util: use capability_get() and _apply() in capability_quintet_enforce() 2025-10-24 01:52:59 +09:00
Yu Watanabe
6e5f07756f capability-util: use capability_get() and _apply() in change_capability() 2025-10-24 01:52:59 +09:00
Yu Watanabe
69eb331b6c capability-util: use capability_apply() in drop_privileges() 2025-10-24 01:52:59 +09:00
Yu Watanabe
256d6f3f2f capability-util: rework capability_gain_cap_setpcap() and capability_bounding_set_drop()
This makes the functions use CapabilityQuintet, capability_get(), and
capability_apply().
2025-10-24 01:52:59 +09:00
Yu Watanabe
aa8ab67a6d capability-util: introduce capability_apply() and use it in capability_ambient_set_apply() 2025-10-24 01:52:59 +09:00
Yu Watanabe
e1c134ba9c capability-util: introduce capability_get() and use it in have_effective_cap()
capability_get() is a wrapper of capget() syscall and converts its
result to CapabilityQuintet.

This also introduce have_inheritable_cap(), which is similar to
have_effective_cap(). It is currently unused, but will be used later.
2025-10-24 01:52:59 +09:00
Yu Watanabe
e804256b80 capability-util: several coding style updates
- rebreak comments,
- add short comment for constant arguments,
- drop unnecessary {},
- use BIT_SET() macro.
2025-10-24 01:52:59 +09:00
Yu Watanabe
2038ad725d capability-util: introduce capability_quintet_equal() helper function
Currently unused, but will be used later.
2025-10-24 01:52:59 +09:00
Yu Watanabe
50053a0212 capability-util: move several definitions 2025-10-24 01:52:59 +09:00
Yu Watanabe
4c0cdc4a2c capability-util: tighten requirement for CAP_LAST_CAP off by one
Otherwise, we cannot use UINT64_MAX as 'unset'.
2025-10-24 01:52:18 +09:00
Yu Watanabe
2a6b084cc6 capability-list: make capability_list_length() return unsigned 2025-10-23 23:46:49 +09:00
Zbigniew Jędrzejewski-Szmek
0bb0316f5e Do not use "critical assert_return" in libsystemd or libudev
Previously, when compiled in developer mode, a call into libsystemd with
invalid parameters would result in an abort. This means that it's effectively
impossible to install such libsystemd in a normal system, since various
third-party programs may now abort. A shared library should generally never
abort or exit the calling program.

In python-systemd, the test suite calls into libsystemd, to check if the proper
return values are received and propagated through the Python wrappers.
Obviously with libsystemd compiled from git, the test suite now fails
in a nasty way.

So rework the code to set assert_return_is_critical similarly to how we handle
mempool enablement: the function that returns true is declared as a week
symbol, and we "opt in" by linking a file that provides the function in
libsystemd-shared. Effectively, libsystemd and libudev always have
assert_return_is_critical==false, and our binaries and modules enable it
conditionally.
2025-10-22 10:10:24 +02:00
Zbigniew Jędrzejewski-Szmek
882dfbde1c basic/mempool: mark mempool_enabled as _pure_
The function internally does caching which means that the result must
always be the same, the definition of a pure function. The compiler might
be able to optimize some repeated calls to the function.
2025-10-22 10:06:07 +02:00
Daan De Meyer
cbbc7e51ec core: adding cgroup/invocationid lookups to io.systemd.Unit.List (#38032) 2025-10-20 17:15:34 +02:00
Ivan Kruglov
366f57bff4 basic: pidref_is_set_or_automatic() 2025-10-20 02:10:00 -07:00
Yu Watanabe
d10596a6e0 iovec-wrapper: introduce iovw_put_string_fieldf() 2025-10-19 10:01:46 +09:00
Yu Watanabe
a5cdc2be70 iovec-wrapper: introduce iovw_replace_string_field() 2025-10-19 10:01:46 +09:00
Yu Watanabe
0c37508494 pidfd-util: expose pidfd_get_info() 2025-10-19 10:01:46 +09:00
Luca Boccassi
5ee8ffb5c5 Assorted coverity fixes (#39355) 2025-10-17 20:30:09 +01:00
Luca Boccassi
b62c681b11 log: add underflow assert guard
We often use ssize_t in log_error macros, but typically return int
which confuses coverity, as technically there is no guarantee that
int and ssize_t have the same range. Add an assert to enforce it.
2025-10-18 01:11:49 +09:00
Luca Boccassi
05d45875f7 efivars: fix potential memory leak
If 'ret' is not passed, 'x' is leaked

Follow-up for c8d60ae79d

CID#1621673
2025-10-17 16:44:15 +01:00
Daan De Meyer
f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Lennart Poettering
4cae0e9a78 importd: change untar logic to be based on libarchive rather than shelling out to gnu tar (#39143)
Let's use libarchive consistently everywhere, both for tarring and
untarring.

Note that there's an existing test case that validates untarring. Now,
it will validate libarchive rather than gnu tar.

Split out of #38728
2025-10-15 11:12:23 +02:00
Zbigniew Jędrzejewski-Szmek
e63917abe1 core: allow split /usr/local/s?sbin with merged /usr/s?bin
Previously, we used either the fully split path or the fully merged path,
treating "split sbin" as a boolean condition. The idea was that conversion to
to merged bin would be a single event, so we don't need to care about the
details of the transition. But it turns out that some systems may be converted
in disparate steps. In https://bugzilla.redhat.com/show_bug.cgi?id=2400220,
there was a lengthy discussion about a coreos system where
/usr/local/{bin,sbin} were created as separate directories. Since /usr/local is
not part of the packaged system, it might remain split for a longer time. So
check /usr/local/s?bin separately and stop adding /usr/sbin to $PATH if only
/usr/local/s?bin is split. (I don't think it makes sense to handle the reverse
case, i.e. only /usr/s?bin being split, since that should be much rarer.)

Inspired by https://bugzilla.redhat.com/show_bug.cgi?id=2400220.
2025-10-14 18:30:06 +02:00
Lennart Poettering
8be204df2b stat-util: add fd_verify_symlink() helper 2025-10-14 11:21:46 +02:00
Lennart Poettering
90fae0b46c stat-util: add helper inode_type_can_hardlink() 2025-10-14 11:21:46 +02:00
Lennart Poettering
b2fa6d0945 xattr: add helper that detect special purpose xattrs 2025-10-14 11:21:46 +02:00
Mike Yuan
cb1c039fbc core/service: properly handle freezer action -> watchdog propagation (#39222) 2025-10-14 00:49:12 +02:00
Yu Watanabe
608fc3fa2c pidfd-util: add missing trailing argument for ioctl(PIDFD_GET_*_NAMESPACE)
Otherwise, it always fails with EINVAL.
2025-10-11 00:13:26 +02:00
Mike Yuan
e4c0741bef basic/log-context: mark global vars as static 2025-10-07 15:53:45 +02:00
Mike Yuan
1cbbb05bc7 unit-def: introduce freezer_state_objective()
No functional change, preparation for later commits.
2025-10-06 02:40:01 +02:00
Yu Watanabe
8431368668 tree-wide: stop assigning colon prefixed timezone to $TZ
glibc (and also musl, though we do not officially support it yet)
silently ignores colon prefix in $TZ. Let's always not prefix the
timezone.

tzset(3) states:
> A nonempty value of TZ can be one of two formats, either of which can
> be preceded by a colon which is ignored.

Addresses https://github.com/systemd/systemd/pull/38876#discussion_r2384347594.
2025-09-28 11:14:00 +09:00
Yu Watanabe
514fa9d39a time-util: fix issues in parse_timestamp() and optimize performance
Previously, an input string ends with short timezone spec e.g. WET,
was parsed by setting $TZ environment variable to the timezone.
But the timezone might be different from the original local timezone,
thus the result might not follow the timezone change in the original
local timezone.

This makes the check of the short timezone spec with tzname[] earlier,
then it is not necessary to load another timezone file for e.g. WET,
and provides expected time.

This also make it use SAVE_TIMEZONE macro and drop use of forking
process. This makes greatly improve performance when parsing string
that contains timezone different from the current local timezone.

Unfortunately, there is still one corner case that our test fails.
When tzdata is built with rearguard enabled, then at least
Africa/Windhoek timezone does not provide correct time, but time shifted
1 hour from the original.
2025-09-27 11:52:24 +09:00
Yu Watanabe
23407c1806 time-util: introduce parse_gmtoff() helper function 2025-09-27 11:52:24 +09:00
Yu Watanabe
e3f561a624 time-util: introduce SAVE_TIMEZONE macro 2025-09-27 11:51:06 +09:00
Lennart Poettering
abf518a8dc runtime-scope: add runtime_scope_to_socket_mode() helper 2025-09-25 22:43:59 +02:00
Lennart Poettering
015025cba2 cgroup-util: add pidref+full counter parts for cg_pid_get_user_unit()
This completes the set of functions for getting the user unit of a
process, mirroring the four functions we already have for the system
unit.
2025-09-25 14:09:55 +02:00
Lennart Poettering
ece4df0293 tmpfile: minor modernizations 2025-09-25 14:07:22 +02:00
Lennart Poettering
71f3f1818f macro: add simple DEFER_VOID_CALL() helper 2025-09-24 15:46:30 +02:00
Lennart Poettering
30aeab7883 terminal-util: add terminal_get_cursor_position() helper 2025-09-24 15:46:30 +02:00
Lennart Poettering
74b8ab014b glyph-util: add more emojis 2025-09-24 15:45:28 +02:00
Luca Boccassi
696b1263dc fs-util: prefer glibc's fchmodat() if possible
Since v2.39 glibc's fchmodat() will call into the kernel's fchmodat2()
if flags are passed:

https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=65341f7bbea824d2ff9d37db15d8be162df42bd3;hp=c52c2c32db15aba8bbe1a0b4d3235f97d9c1a525

On older versions, if the flag is anything other than AT_SYMLINK_NOFOLLOW,
it returns EINVAL, so we can detect it and call the kernel syscall directly
ourselves.

Using the glibc wrappers when possible is prefereable so that programs
like fakeroot can intercept its calls and redirect them.

Follow-up for adecfb3bc0
2025-09-24 08:48:42 +02:00
Lennart Poettering
3d97db8f3c ptyfwd: reset tty when exiting
Let's do a "soft" reset of the TTY when a ptyfwd session ends. This is a
good idea, in order to reset changes to the scrolling window that code
inside the session might have made. A "soft" reset will undo this.

While we are at it, make sure to output the ansi sequences for this
*after* terminating any half-written line, as that is still somewhat
contents of the session, even if it's augmented.
2025-09-22 14:39:05 +09:00
Lennart Poettering
e6a05af50b glyph-util: add missing ascii represenations of some emojis 2025-09-22 14:38:43 +09:00
Lennart Poettering
2f5fb752a6 repart: tweak byte value output
So far, when outputing information about copy progress we'd suppress the
digit after the dot if it is zero. That makes the progress bar a bit
"jumpy", because sometimes there are two more character cells used than
other times. Let's just always output one digit after the dot here
hence, to avoid this.
2025-09-19 16:46:07 +02:00
Daan De Meyer
8796164189 tree-wide: Remove unused includes (#39023) 2025-09-19 16:07:04 +02:00
Daan De Meyer
9adb4685df tree-wide: Remove unused includes 2025-09-19 14:46:55 +02:00
Mike Yuan
01184496a2 virt: revert to detect chroot by comparing with / rather than /proc/PID/root
This partially reverts d6267b9b18

So, arch-chroot currently uses a rather cursed setup:
it sets up a PID namespace, but mounts /proc/ from the outside
into the chroot tree, and then call chroot(2), essentially
making it somewhere between chroot(8) and a full-blown
container. Hence, the PID dirs in /proc/ reveal the outer world.
The offending commit switched chroot detection to compare
/proc/1/root and /proc/OUR_PID/root, exhibiting the faulty behavior
where the mentioned environment now gets deemed to be non-chroot.

Now, this is very much an issue in arch-chroot. However,
if /proc/ is to be properly associated with the pidns,
then we'd treat it as a container and no longer a chroot.
Also, the previous logic feels more readable and more
honestly reported errors in proc_mounted(). Hence I opted
for reverting the change here. Still note that the culprit
(once again :/) lies in the arch-chroot's pidns impl, not
systemd.

Fixes https://gitlab.archlinux.org/archlinux/packaging/packages/systemd/-/issues/54
2025-09-19 13:09:34 +02:00
Yu Watanabe
c3c42b30dd firewall-util: remove iptables/libiptc backend support (#38976)
This removes iptables/libiptc backend support in firewall-util, as
already announced by 5c68c51045.
Then, this drops meaningless `FirewallContext` wrapper.
2025-09-19 19:54:17 +09:00