Commit Graph

80169 Commits

Author SHA1 Message Date
Matteo Croce
c154bb65ad condition: introduce ConditionVersion=/AssertVersion=
Add a new condition wich checks against systemd version.
Change condition_test_kernel_version() into a generic condition_test_version()
so most of the code can be reused.

    $ systemctl --version
    systemd 258 (258~devel-g53ca5f6)

    $ systemd-analyze condition 'ConditionVersion=systemd>255'
    test.service: ConditionVersion=>255 succeeded.

    $ systemd-analyze condition 'ConditionVersion=systemd>260'
    test.service: ConditionVersion=>260 failed.

    $ systemd-analyze condition 'ConditionVersion=systemd>=258'
    test.service: ConditionVersion=>=258 succeeded.

    $ systemd-analyze condition 'ConditionVersion=systemd>=257.1'
    test.service: ConditionVersion=>=257.1 succeeded.

    $ uname -r
    6.12.13-200.fc41.aarch64

    $ systemd-analyze condition 'ConditionVersion=kernel > 4.4'
    test.service: ConditionVersion=kernel > 4.4 succeeded.

    $ systemd-analyze condition 'ConditionVersion=kernel > 6.20'
    test.service: ConditionVersion=kernel > 6.20 failed.

    $ systemd-analyze condition 'ConditionVersion=kernel < 9.0'
    test.service: ConditionVersion=kernel < 9.0 succeeded.
2025-03-18 18:36:59 +09:00
Yu Watanabe
f91273f4fc condition: align string table 2025-03-18 18:36:59 +09:00
Yu Watanabe
a483c39fc2 analyze-condition: rewrite condition parser
No functional change, just a refactoring.
2025-03-18 18:36:55 +09:00
Sonia Zorba
147511c643 hwdb: fix backspace not working on HP Pavilion laptop (#36777)
PR #34685 moved the handling of keys 66/65 from specific models to
generic HP laptops.

Key 66 has been linked to the `pickup_phone` function; however, this
action key is not available on all HP laptop models, particularly older
versions. On my HP Pavilion laptop, key 66 is mapped to the `backspace`
function, which caused the backspace key to stop working after the
change.

The following PR fixes the issue on my **HP Pavilion Laptop 15-eg0xxx**.
I have placed the modifications under the Pavilion section, but I cannot
guarantee that this solution will apply to all Pavilion models.

Additionally, I have included a line that checks for "HP" instead of
solely searching for "Hewlett-Packard," as my model is simply labeled as
HP.
2025-03-18 09:25:51 +09:00
Yu Watanabe
c9c2679a62 some user record fixes (#36776)
Fixes: https://github.com/systemd/systemd/issues/36775
2025-03-18 09:24:05 +09:00
Mike Yuan
2b983b43c6 run: Ref() the unit again after reconnecting to the bus
Follow-up for c8f59296bf

Currently, the unit is only reffed in transient_unit_set_properties()
via AddRef(), which however would be dropped if a reconnection
is attempted. Make sure to explicitly re-add reference in that case.
2025-03-18 09:23:44 +09:00
Yu Watanabe
8e29a5b9b3 nsresourced,vmspawn: allow unpriv "tap" based networking in vmspawn (#36688)
This extends nsresourced to also allow delegation of a network tap
device (in addition to veth) to unpriv clients, with a strictly enforced
naming scheme.

also tightens security on a couple of things:

* enforces polkit on all nsresourced ops too (though by default still
everything is allowed)
* put a limit on delegated network devices
* forcibly clean up delegated network devices when the userns goes away
2025-03-18 07:34:03 +09:00
Lennart Poettering
91d11d53a1 tree-wide: refuse user/group records lacking UID or GID
userdb allows user/group records without UID/GID (it only really
requires a name), in order to permit "unfixated" records. But that means
we cannot just rely on the field to be valid. And we mostly got that
right, but not everywhere. Fix that.
2025-03-17 22:37:14 +01:00
Lennart Poettering
d43a440767 nspawn: go via user_record_home_directory() accessor for .home_directory UserRecord field
Fixes: #36775
2025-03-17 22:23:18 +01:00
Lennart Poettering
ca4560f6a8 tree-wide: go via user_record_gid() accessor for UserRecord's .gid field
Sometimes we went for the field directly, where we really should go via
the accessor. Fix it.
2025-03-17 22:21:58 +01:00
Lennart Poettering
2f3314bce6 update TODO 2025-03-17 21:39:06 +01:00
Lennart Poettering
ef197d6ab2 test: add test for nsresourced 2025-03-17 21:39:05 +01:00
Lennart Poettering
6e09c46a51 nsresource: turn feature absence error into EOPNOTSUPP
Let's make it easy for local clients to treat feature absence as a
simple EOPNOTSUPP check.
2025-03-17 16:03:18 +01:00
Lennart Poettering
3b6d1fb49f varlink: add full introspection comments for io.systemd.NamespaceResource 2025-03-17 16:03:18 +01:00
Lennart Poettering
d2f3ddfc65 nsresourced: check polkit before executing our operations
Let's tighten rules on namespace operations: let's always ask PK for
permission before doing anything.

Note that if polkit is absent we'll still allow things, and the default
PK policy will also still allow things, but there's now a clear way how
people can not allow things if they want, by modifying the PK policy.
2025-03-17 16:03:18 +01:00
Lennart Poettering
b2c43674a7 nsresourced: put a limit on delegated network interfaces too 2025-03-17 16:03:18 +01:00
Lennart Poettering
7d2e2900f1 nsresourced: explicitly remove network interfaces when their userns goes away
Let's tighten the screws a bit on the network interfaces we delegate,
and explicitly destroy them, just like we destroy delegated cgroups.

Ideally, this should happen automatically because the userns goes away
that pins the veth, or because the client holding an fd for a tap device
goes away as the userns goes away. But you never know who keeps a
reference, hence let's explicitly destroy this too.
2025-03-17 16:03:18 +01:00
Lennart Poettering
e29d5385b6 vmspawn: support unpriv tap networking 2025-03-17 16:03:18 +01:00
Lennart Poettering
716bf93c4b nsresource: add client-side wrapper for creating tap links 2025-03-17 16:03:18 +01:00
Lennart Poettering
19ac01efef network: also manage namespace tap links 2025-03-17 16:03:18 +01:00
Lennart Poettering
1365034727 nsresourced: add ability to delegate tap device 2025-03-17 16:03:18 +01:00
Lennart Poettering
00b1f67313 nsresourced: permit differing uid/gid 2025-03-17 16:03:18 +01:00
Lennart Poettering
5c9327e353 namespace: simplify apply_one_mount() a bit
Drop a bunch of unnecessary casts, format strings, and {} blocks.
2025-03-17 16:03:18 +01:00
Lennart Poettering
783b40bd73 namespace-util: introduce userns_acquire_self_root()
This is a simple helper for creating a userns that just maps the
callers user to UID 0 in the namespace. This can be acquired unpriv,
which makes it useful for various purposes, for example for the logic in
is_idmapping_supported(), hence port it over.

(is_idmapping_supported() used a different mapping before, with the
nobody users, but there's no real reason for that, and we'll use
userns_acquire_self_root() elsewhere soon, where the root mapping is
important).
2025-03-17 16:03:18 +01:00
Lennart Poettering
6431c34b8a namespace-util: make "setgroups" users property writable via userns_acquire()
Unprivileged namespaces are only allowed if the "setgroups" file is set
to "deny" for processes. And we need to write it before writing the
gidmap. Hence add a parameter for that.

Then, also patch all current users to actually enable this. The usecase
generally don't need it (because they don't care about unprivileged
userns), but it doesn't hurt to enable the concept anyway in all current
users (none of them actually runs complex userspace in them, but they
mostly use userns_acquire() for idmapped mounts and similar).

Let's anyway make this option explicit in the function call, to indicate
that the concept exists and is applied.
2025-03-17 16:03:18 +01:00
Lennart Poettering
0201114bb7 better support for $COLORTERM (#36770)
I recently noticed that our serial/VM terminals did not get fedora's
color shell prompt, nor got color support in "ls".

I spend a bit of time investigating and it's all a bit of a mess. If we
don't have any idea what kind of terminal we are talking to via serial
or hypervisor console then we so far just set TERM=vt220 as a reasonable
fallback: vt220 is quite universally defined in terminfo/termcap, and it
supports pageup/pagedown (unlike vt100).

However, real vt220 DEC terminals did not support color, and hence
termcap/terminfo says "no color, sorry". Which sucks, but actually
neither coreutils' "ls" (via `dircolors`) nor fedora's color shell
prompt actually care for termcap/terminfo. So why don't we get color?

In the coreutils case: it has it's own mini-database of terminals. A
very skewed one, where TERM=vt100 enables colors (and DEC vt100
definitely never ever had color support!), but vt220 does not. However,
what it actually does is check $COLORTERM. If that's set then it would
enable color.

In the fedora color prmpt case: it tries to derive color support by
looking for the word "color" in $TERM. Horrible hack if you ask me...

In order to make things better I did a bunch of things:

1. I think the idea of actually having a fully correct and up-to-date
termcap/terminfo database is kinda illusionary these days. But
apparently regarding color support $COLORTERM kinda took it place.
coreutils cares, and systemd itself cares too. To some point at least:
we consume it to determine color support, but we never propagate it in
nspawn, run0 and so on. So this PR fixes that.

2. Also, we are kinda stuck with vt220 I guess as default fallback for
serial terminals. But let's tweak it, and set $COLORTERM=truecolor as
default too. this means we default to a vt220 terminal, but with color.
Which is an ahistorical thing to do, but I think it's the best way out.

3. I also filed a bug against util-linux asking them to treat $COLORTERM
like $TERM, and let it propagate from getty into login shell:
https://github.com/util-linux/util-linux/issues/3463 – With that we
should get color support in ls by default now.

4. I also asked coreutils to treat vt220 the same as they already treat
vt100 and simply do color, even if though that's ahistorical:
https://github.com/coreutils/coreutils/issues/96

5. I then asked the fedora color prompt package to check $COLORTERM:
https://bugzilla.redhat.com/show_bug.cgi?id=2352650

6. I also asked the fedora ssh package to propagate $COLORTERM to remote
hosts by default, like they already cover $TERM. terminal emulators set
both these days generally, hence this would make sense.
https://bugzilla.redhat.com/show_bug.cgi?id=2352653

7. while at it, I figured it makes sense to not only propagate/consume
$COLORTERM at the same time as $TERM, but also consider $NO_COLOR. In
contrast to $COLORTERM for which no spec seems to exist, that one
actually does have a spec: https://no-color.org/

It might make sense for those interested in other distros than Fedora to
maybe ask for similar changes for their ssh and color shell prompt
packages (if they have something coresponding).
2025-03-17 13:17:06 +01:00
Luca Boccassi
3d278519fa build: add C23 support (#35085)
To support C23, this introduces UTF8() macro to define UTF-8 literals,
as C23 changed char8_t from char to unsigned char.
This also makes pointer signedness warning critical, and updates C
standards table for tests.
2025-03-17 11:29:33 +00:00
Lennart Poettering
aeb06708ca udev: several follow-ups and cleanups for builtin commands (#36768) 2025-03-17 10:42:55 +01:00
Daan De Meyer
8065d02e26 copy: Fix error handling in fd_copy_directory() 2025-03-17 10:42:04 +01:00
Lennart Poettering
afdca6c6c2 nspawn,run,machinectl,socket-activate: propagate $COLORTERM + $NO_COLOR
When we pass information about our calling terminal on to some service
or command we invoke, propagate $COLORTERM + $NO_COLOR in addition to
$TERM, in order to always consider the triplet of the three env vars the
real deal.
2025-03-17 10:17:54 +01:00
Lennart Poettering
19aff5f775 main: explicitly pick up $COLORTERM + $NO_COLOR from kernel cmdline where we pick up $TERM
I think we should work towards always picking up the triplet of $TERM +
$COLORTERM + $NO_COLOR where we so far picked up $TERM only. I think
it's safe to say that at this time, $TERM is not enough anymore to
clearly communicate terminal feature support. Hence, teach PID 1 to pick
$COLORTERM + $NO_COLOR wherever we pick up $TERM.
2025-03-17 10:17:51 +01:00
Lennart Poettering
728dbaeffb exec: when we have no $TERM configuration, and we default to vt220, also set $COLORTERM
When we configure a serial or VM terminal and have no $TERM
configuration, then we default to vt220 as a fallback. This is a pretty
safe bet, since the termcap/terminfo definitions for vt220 are
relatively widely available (much like vt100), and (in contrast to
vt100) it supports pageup/pagedown keys. vt220 is a terminal without
color support however, but we do want color support, because in 2025
there's really no terminal emulator without color in this world.

The $COLORTERM env var is used my many emulators and tools to
communicate that ANSI color support is available, despite what $TERM
says. Hence, let's tweak systemd's logic to also set $COLORTERM in case
we set the vt220 $TERM fallback.

This means we define an ahistoric frankenterminal: a vt220 (that
historically definitely didn't have color) that is explicitly configured
to have color.

One effect of this is that coreutils' dircolors command will start to
output color sequences in systemd's serial or VM terminals. (Since it
actually honours $COLORTERM).

Also note that systemd itself checks $COLORTERM since a long time, hence
it makes sense for us to also set it.

Note that this unfortunately doesn't have the desired effect of
propagating $COLORTERM into any getty shell sessions yet. That's because
util-linux' login package currently fiters $COLORTERM (but lets $TERM
though). I filed a bug about that here:

https://github.com/util-linux/util-linux/issues/3463
2025-03-17 10:15:51 +01:00
Yu Watanabe
8b75e15a94 TEST-17-UDEV: add more test cases for udev builtins 2025-03-17 12:42:28 +09:00
Yu Watanabe
6f2f4ceadf shell-completion: add factory_reset udev builtin command 2025-03-17 12:42:28 +09:00
Yu Watanabe
6cfb5866fe udev-builtin-btrfs: refuse to call for irrelevant device node
If btrfs builtin command is called, then check if the specified device
node is owned by the device.
This also allows the command is called specifying any device node.
2025-03-17 12:42:28 +09:00
Yu Watanabe
73a2912092 udev-builtin: make btrfs builtin command only check arguments when run in test mode 2025-03-17 12:42:28 +09:00
Yu Watanabe
80ffdb8d54 udev-builtin: add missing UDEV_RELOAD_BUILTIN_FACTORY_RESET 2025-03-17 12:42:28 +09:00
Yu Watanabe
f1ad44d688 udev-builtin: align builtins table 2025-03-17 12:42:28 +09:00
Y T
58b33eee41 po: Translated using Weblate (Japanese)
Currently translated at 100.0% (261 of 261 strings)

Co-authored-by: Y T <yi818670@gmail.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/main/ja/
Translation: systemd/main
2025-03-17 12:30:36 +09:00
Yu Watanabe
db2db8cc60 run: trivial followups (#36765) 2025-03-17 12:27:49 +09:00
Mike Yuan
2fb10b3cfb run: refuse --pty-late for Type=oneshot services
Such combination makes no sense, as by the time the start job
of the oneshot service finishes the main process has already
exited.

Addresses https://github.com/systemd/systemd/pull/36691#discussion_r1988116881
2025-03-17 01:37:29 +01:00
Mike Yuan
647ff4b65e run: void'ify sd_event_exit() call 2025-03-17 01:37:29 +01:00
Mike Yuan
99a7386a9e run: "trigger" consists of more than timer units 2025-03-17 01:37:29 +01:00
Yu Watanabe
369c232538 nspawn: introduce --cleanup option (#34776)
This is useful when the previous invocation is unexpectedly killed.

Otherwise, if systemd-nspawn is killed forcibly, then unix-export
directory is not cleared and unmounted, and the subsequent invocation
will fail. E.g.
```
[   18.895515] TEST-13-NSPAWN.sh[645]: + machinectl start long-running
[   18.945703] systemd-nspawn[1387]: Mount point '/run/systemd/nspawn/unix-export/long-running' exists already, refusing.
[   18.949236] systemd[1]: systemd-nspawn@long-running.service: Failed with result 'exit-code'.
[   18.949743] systemd[1]: Failed to start systemd-nspawn@long-running.service.
```
2025-03-17 06:53:46 +09:00
Jordan Petridis
8285c97b97 meson: Check for lxml before generating indicies
Followup to c0cc01de8a

The targets that create indicies have
`install : want_html and have_lxml` but some other
code like the `install_symlink` was not gated by
accident.

We ican put the whole loop behind have_lxml as its
required for all the indicies.
2025-03-17 06:51:52 +09:00
Mike Yuan
cd1af37263 cgroup v1 preliminaries (#36622) 2025-03-16 20:27:48 +01:00
Mike Yuan
08395f86e1 man: remove libsystemd reference to legacy hierarchy 2025-03-16 18:02:08 +01:00
Mike Yuan
b66fd12135 cgroup-util: drop is_cgroup_fs()
No need to bother with any cgroup v1 stuff anymore.
2025-03-16 18:02:08 +01:00
Mike Yuan
399791eaf0 core/taint: we know we're always running on cgv2 now 2025-03-16 18:02:07 +01:00
Mike Yuan
2b61489e5a core/main: refuse bootup with legacy cgroup hierarchy
First step towards a unified-only future (rework of internals
coming soon (TM))
2025-03-16 15:30:39 +01:00