Commit Graph

6406 Commits

Author SHA1 Message Date
Philip Withnall
6015c6cd6f test: Expand sysupdate test to cover split acquire/install updates
This essentially means the sysupdate tests are now run twice: once with
a monolithic update (`sysupdate update`) and once with a split update
(`sysupdate acquire; sysupdate install`).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-02-09 12:05:20 +00:00
Lennart Poettering
a1d3fd1202 test: add superficial test for list-registry 2026-02-09 10:54:18 +01:00
Daan De Meyer
7d4ea41bd1 bootctl parts of installer PR (#40447)
This contains the "bootctl install" related work from the #38764 split
out, but also includes the preparatory work already split out into
#40446.

I'll rebase this PR once the prep work is merged.

This has a simple CI test already, and has docs
2026-02-09 09:46:39 +01:00
Mike Gilbert
a304f6c9db meson: use printf instead of echo
The echo builtin provided by some shells (mksh) will interpret \x2d as
an escape sequence. This causes meson to fail:

```
test/fuzz/meson.build:93:52: ERROR: File fuzz-unit-file/dm-back-slash.swap does not exist.
```

Bug: https://bugs.gentoo.org/969789
2026-02-09 09:36:26 +01:00
Matteo Croce
c1bf450fa0 oomd: implement a prekill varlink event
When a cgroup is selected for termination, send varlink messages
to hooks registered in `/run/systemd/oomd.prekill-hooks/`.
oomd waits up to `PreKillHookTimeoutSec=` seconds for response
before proceeding with the kill.
2026-02-09 02:05:57 +01:00
Lennart Poettering
1dad3b6762 bootctl: add test case for bootctl install via varlink 2026-02-06 23:17:02 +01:00
Lennart Poettering
ab89fad427 test: bump disk sizes for some test cases
In my testing I switched building my locally run CI integration tests to
ArchLinux and realized that for that the default sizes don't work
anymore, the images are larger than the space allocated. Let's bump the
size by 50% for the relevant disk images.
2026-02-06 18:19:33 +01:00
Lennart Poettering
dd2676c1ab tests: don't use "dd" to allocate empty files
Let's use truncate -s … to create empty files (if they can be sparse)

Let's use fallocate -l … to create empty non-sparse files.

This should reduce the disk footprint of our tests a bit, given that in
most cases we won't use the allocate disk space in full, not even
remotely.
2026-02-06 18:19:33 +01:00
Cathy Hu
d3761f1509 journal-remote test: add -Z for mkdir in general
Otherwise on SELinux enabled systems with the "targeted" policy
the type is not set correctly when run via unconfined user and
the test fails.
2026-02-06 15:15:10 +09:00
Lennart Poettering
823054d079 pcrextend: fix varlink API to match what we actually take
(Change test case slightly, to ensure we don't regress on this)
2026-02-06 15:08:51 +09:00
Zbigniew Jędrzejewski-Szmek
e047394797 [metrics] Introduce metrics API (#39202)
See the [design
doc](https://github.com/systemd/systemd/issues/38023#issue-3192567450)
by @ikruglov

This PR introduces the metrics API framework, adds some basic system
wide/per unit/service metrics, and a basic CLI. The PR is broken into
two commits as described below.

### Deviations from the original design
- Introduced top level field "object" for ease of filtering. Instead of
having `fields: { unit: "foo", unit_type: "service" }`, we now have
`object: foo.service` as the top level field.


### First commit

The first commit includes:
- Metrics API definitions
- Code to set up the varlink server
- The describe method which shows all the metrics families
- The list method which lists all the metrics
- Type definitions related to MetricFamily
- Common code to build json objects

### Second commit
The second commit adds some basic metrics, a basic CLI (systemd-report)
which
lists the metrics, and integration tests.

**System wide metrics:**
- units_by_type_total
- units_by_state_total

**Two per unit metrics:**
- unit_active_state
- unit_load_state

**A service state metric:**
- nrestarts

### Sample outputs

**units_by_type_total**:

```
{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 52,
        "fields" : {
                "type" : "target"
        }
}
{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 82,
        "fields" : {
                "type" : "device"
        }
}
{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 2,
        "fields" : {
                "type" : "automount"
        }
}
```
**units_by_state_total**:
```
{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 216,
        "fields" : {
                "state" : "active"
        }
}
{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 0,
        "fields" : {
                "state" : "reloading"
        }
}
{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 120,
        "fields" : {
                "state" : "inactive"
        }
}
```
**unit_active_state**:
```
{
        "name" : "io.systemd.Manager.unit_active_state",
        "object" : "multi-user.target",
        "value" : "active"
}
{
        "name" : "io.systemd.Manager.unit_active_state",
        "object" : "systemd-sysusers.service",
        "value" : "inactive"
}
```
**unit_load_state**:
```
{
        "name" : "io.systemd.Manager.unit_load_state",
        "object" : "multi-user.target",
        "value" : "loaded"
}

```
**nrestarts**:
```
{
        "name" : "io.systemd.Manager.nrestarts",
        "object" : "user@0.service",
        "value" : 0
}
{
        "name" : "io.systemd.Manager.nrestarts",
        "object" : "user-runtime-dir@0.service",
        "value" : 0
}
```
2026-02-04 16:31:55 +01:00
Kai Lueke
23115eeaf1 sysext: Skip refresh if no changes are found
When the extensions for the final system are already set up from the
initrd we should avoid disrupting the boot process with the remount
(which currently isn't atomic) and the daemon reload for
systemd-confext and systemd-sysext. Similarly, when sysupdate ran and
updated extensions it's best to avoid the remount and daemon reload if
no changes are found.
To do this, encode the current extension state in more detail than
before where only the names of the extensions where encoded in the
overlay mount. This can also be used to provide more details about the
extension origin in "systemd-sysext status (--json=)". During the
refresh add a check whether the old state matches the new state and in
this case skip the refresh unless the user provides a flag to always
refresh. Besides the extension name and the resolved path the best
method for identification is the verity hash but that is not available
for plain image files or directories. Therefore, also include data to
check for file/directory replacements. The creation/modification times
are not always real on reproducible images or extracted archive content.
The file handle together with the unique mount ID is the next best
identifier we can use when we have no verity hash. Fall back to an inode
when we get no handle. With the creation/modification time and the path
this should be good enough. Using a unique mount ID is important (with
a fallback to the regular non-unique mount ID) instead of st_dev because
st_dev gets reused too easily, e.g., by a loop device mount and the
mount ID helps to catch this. For the mount ID to be valid it has to be
resolved before we enter the new mount namespace. Thus, it gets provided
by the image dissect logic and handed over to the sysext subprocess
which runs in a new mount namespace.
Luckily, we can rule out online modification of directories or image
files because this is anyway not well supported with overlay mounts, so
we don't do a file checksum nor do we recurse into a directory to look
for the most recently touched files.  But, as said, with the
always-refresh flag one can force a reload.
2026-02-04 00:05:24 +01:00
Yu Watanabe
eb5b797d7c journal: check validity of PID field in syslog/kmsg earlier
Then, let's make syslog_parse_identifier() returns PID as pid_t, rather
than the string.

This also makes the function refuse ridiculously long identifier.

Fixes #40456.
Fixes oss-fuzz#477990732 (https://issues.oss-fuzz.com/issues/477990732).
2026-02-03 21:55:49 +09:00
Yu Watanabe
0dcbb30f49 fuzz: assume all reproducers as binary
Even if parsers expect text data, reproducers may not be suitable
for being handled as a text file.
2026-02-03 21:43:17 +09:00
Yaping Li
c498f3790f [metrics] Add a basic CLI
systemd-report will list all the metrics.
2026-02-02 08:03:56 -08:00
Yaping Li
bb1ef2edf7 [metrics] Add basic system wide and per unit metrics
This commit adds some basic metrics and integration tests.

System wide metrics:
- units_by_type_total: target/device/automount etc.
- units_by_state_total: active/reloading/inactive etc.

Two per unit metrics which shows the current state of a unit:
- unit_active_state
- unit_load_state

A metric for service state:
- nrestarts

Here are some sample outputs:

units_by_type_total:

{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 52,
        "fields" : {
                "type" : "target"
        }
}
{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 82,
        "fields" : {
                "type" : "device"
        }
}
{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 2,
        "fields" : {
                "type" : "automount"
        }
}

units_by_state_total:

{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 216,
        "fields" : {
                "state" : "active"
        }
}
{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 0,
        "fields" : {
                "state" : "reloading"
        }
}
{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 120,
        "fields" : {
                "state" : "inactive"
        }
}

unit_active_state:

{
        "name" : "io.systemd.Manager.unit_active_state",
        "object" : "multi-user.target",
        "value" : "active"
}
{
        "name" : "io.systemd.Manager.unit_active_state",
        "object" : "systemd-sysusers.service",
        "value" : "inactive"
}

unit_load_state:

{
        "name" : "io.systemd.Manager.unit_load_state",
        "object" : "multi-user.target",
        "value" : "loaded"
}

nrestarts:

{
        "name" : "io.systemd.Manager.nrestarts",
        "object" : "user@0.service",
        "value" : 0
}
{
        "name" : "io.systemd.Manager.nrestarts",
        "object" : "user-runtime-dir@0.service",
        "value" : 0
}
2026-02-02 08:03:56 -08:00
Yu Watanabe
99f332ffb1 A few test fixes (#40524)
These are some patches we currently have in Ubuntu for the development
release. A couple are related to Ubuntu switching to uutils coreutils by
default.
2026-01-31 01:19:38 +09:00
Nick Rosbrook
7c9c34514a test: disable pipefail again in monitor_check_rr()
Partially reverts d6b3793704.

On Ubuntu 26.04 devel, TEST-75-RESOLVED often fails at this stage,
despite the matching query apparently being found:

 + monitor_check_rr '2025-12-18 16:02:54' 'follow10.so.close.signed.test IN CNAME follow11.yet.so.far.signed.test'
  + set +x
  Dec 18 16:02:54 ns1.unsigned.test resolvectl[552]: ← A: follow10.so.close.signed.test IN CNAME follow11.yet.so.far.signed.test
 + monitor_check_rr '2025-12-18 16:02:54' 'follow11.yet.so.far.signed.test IN CNAME follow12.getting.hot.signed.test'
  + set +x
  Dec 18 16:02:54 ns1.unsigned.test resolvectl[552]: ← A: follow11.yet.so.far.signed.test IN CNAME follow12.getting.hot.signed.test
 + monitor_check_rr '2025-12-18 16:02:54' 'follow12.getting.hot.signed.test IN CNAME follow13.almost.final.signed.test'
  + set +x
  Dec 18 16:02:54 ns1.unsigned.test resolvectl[552]: ← A: follow12.getting.hot.signed.test IN CNAME follow13.almost.final.signed.test
 + monitor_check_rr '2025-12-18 16:02:54' 'follow13.almost.final.signed.test IN CNAME follow14.final.signed.test'
  + set +x
  Dec 18 16:02:54 ns1.unsigned.test resolvectl[552]: ← A: follow13.almost.final.signed.test IN CNAME follow14.final.signed.test

Unsetting pipefail, as was done before d6b3793704, appears to fix the
problem.
2026-01-30 09:36:53 -05:00
Yu Watanabe
3762ada7e3 repart: Restore early fstab/crypttab generation (#40473)
fstab/crypttab generation were moved to the late stage to support
'fixate-volume-key' option. This, however, broke the use-case when
fstab/crypttab are put to the generated partition/image.

Fixes #40444
2026-01-30 23:32:07 +09:00
Nick Rosbrook
9dcfd6e8fe test: cope with uutils coreutils flag parsing for date command
With GNU coreutils, one can pass an argument to the "set" flag like:

 date -s "-3 days"

With uutils coreutils, that gives an error:

 error: unexpected argument '-3' found
    tip: to pass '-3' as a value, use '-- -3'

That's a bug (https://github.com/uutils/coreutils/issues/9679), but both
implementations accept --set="-3 days" just fine, so use that instead.
2026-01-30 09:30:20 -05:00
Nick Rosbrook
a8efad14f8 test: use journalctl -n option instead of piping to head
On Ubuntu's test infrastructure for the development series, this test
often fails when piping the journal output to head. The cause is
unclear, but possibly related to Ubuntu's use of uutils coreutils.

Workaround this by just using journalctl's -n flag, which removes the
need for piping output to head.
2026-01-30 09:30:20 -05:00
Yu Watanabe
43b6eb09be discover-image: Follow symlinks in a given root (#39843)
This is needed to set up extension images from the initrd with
`systemd-sysext --root=/sysroot/ merge`.

- vpick: Don't use openat directly but resolve symlinks in given root
    
With systemd-sysext --root= all symlinks should be followed relative to
    the given root and direct openat usage doesn't work.
    Remove the openat call and let pin_choice do the work with the chase
    helper function to resolve the symlink in the given root.
- discover-image: Follow symlinks in a given root
    
    So far systemd-sysext with --root= specified didn't follow extension
symlinks (such as the "current" symlinks managed by systemd-sysupdate).
The main use case is running systemd-sysext --root=/sysroot for setting
    up the overlay mounts already from the initrd.
    
Resolve symlinks correctly but don't defend against later symlink races
    that would access a path outside of the given root. Malicous live
modifications are not a realistic threat model and anyway for that one
would need to rework how the image entry is passed over up to the point
when the loop device is set up. This change here does not introduce this
weakness nor does it expose it more than before. Thus, make it explicit
    that setting up the extensions for a given --root= implies a certain
trust into this given root tree that it does not try do race conditions
with symlinks to trick systemd-sysext to mount a file outside --root=.
Without a strict --image-policy= set we would anyway mount filesystems
right away which is another attack vector but, again, the main use case
    is to do this for the final system which is trusted at this stage.
- sysext: Use correct image name for extension release checks
    
For the extension release check the image name is needed and was derived
    from the backing file of the loop device. However, this can have a
different name when symlinks were resolved. The surprising behavior was
that it worked when the target name started with the extension name and
_ because that's what's supported to chop off version suffixes. However,
we should not have such strict requirements for the target name and also
allow - as version separator and entirely different names/prefixes, the
    same way as we also do for directories instead of raw images.
    
    Do not use the image name derived from the backing file of the loop
    device but directly the extension name we have at hand.
- test: Add tests for handling symlinks with systemd-sysext
    
    When we now allow following symlinks inside a --root= we should also
test that it works in various cases from simple relative and absolute
    symlinks to .v being a symlink itself or its contents, both for
directory and for .raw image extensions. While at it, also add a simple
    test for .v without symlinks which wasn't there for direct usage of
    systemd-sysext.
2026-01-30 22:36:20 +09:00
Vitaly Kuznetsov
7a4b51ce4c TEST-58-REPART: Add a test for fstab/crypttab inclusion
Check that generated fstab/crypt are generated early and thus can
be put to the created volume.
2026-01-30 13:21:57 +01:00
David Tardon
a11278ce63 test: fix test with -Dnetworkd=false
User and group systemd-network are created from
sysusers.d/systemd-network.conf, which is only copied into the test
image when building with -Dnetworkd=true. This means that if
-Dnetworkd=false is used, the user and the group don't exist, which
causes the test to fail.

Use a locally created user and group to avoid that.
2026-01-29 21:12:34 +09:00
Kai Lueke
da6d189aa5 test: Add tests for handling symlinks with systemd-sysext
When we now allow following symlinks inside a --root= we should also
test that it works in various cases from simple relative and absolute
symlinks to .v being a symlink itself or its contents, both for
directory and for .raw image extensions. While at it, also add a simple
test for .v without symlinks which wasn't there for direct usage of
systemd-sysext.
2026-01-28 12:24:57 +01:00
Lennart Poettering
2e38c56c73 test: perform /usr/share/ sysext unmount lazily
/usr/share/ is a directory commonly accessed by various tools, hence we
really should make sure we umount it lazily (MNT_DETACH), since
otherwise there's a good chance that the umount might simply fail.

I noticed this there:

https://github.com/systemd/systemd/actions/runs/21321690161/job/61372465563?pr=40446
2026-01-26 11:49:37 +00:00
Mike Yuan
24c73c7920 core/exec-invoke: switch PRIVATE_USERS_FULL to direct "0 0 UINT32_MAX" mapping
This was intended for v259. Let's get it done now, in v260.
2026-01-23 19:29:48 +01:00
Daan De Meyer
824fcb95c9 portable: Enable unpriv operation
This does not yet support directory images properly
as systemd itself does not support unpriv directory
images properly yet.

The user profiles are a copy of the system profiles but without
DynamicUser=yes (can't be used by user managers) and without
ProtectHome=yes (this masks /home which breaks StateDirectory= which
is lcoated inside /home)
2026-01-21 15:09:46 +01:00
DaanDeMeyer
180875da36 test: Set SYSTEMD_NSS_LOG_LEVEL=info
Currently, our test logs are flooded with useless NSS varlink debug
logs coming from nss-systemd talking to each varlink userdb service
individually. Let's set SYSTEMD_NSS_LOG_LEVEL=info to get rid of these
verbose logs.
2026-01-21 12:03:07 +01:00
Lennart Poettering
d0badc0a61 sysupdate: add simple "freshness" validation to systemd-sysupdate
In order to make "freeze" attacks against the update logic harder let's
add the ability to encode a "Best Before" date into SHA256SUMS directory
listings: if the current time is already beyond that time, we'll ignore
the SHA256SUMS as "stale" and fail the upgrade. Or in other words: the
freeze attack will now result in a client-side error eventually, instead
of success state.

The best before data is encoded in an optional pseudo-file listed in SHA256SUMS:
any file named BEST-BEFORE-YYYY-MM-DD.
2026-01-20 21:22:35 +01:00
Yu Watanabe
9503cc3b6d resolve: include current DNS server in JSON again (#40396)
Fixes a regression caused by c6b6ac63ea.
2026-01-20 09:41:51 +09:00
Lennart Poettering
9316e02c9d Introduce 'fixate-volume-key' option to repart/cryptsetup to pin the exact LUKS volume key hash (#40343)
Add an option to generate the expected volume key hash for LUKS volumes
by systemd-repart
and put it to crypttab, make systemd-cryptsetup check it upon attaching.
The format of the hash
matches what's currently being measured to TPM2 PCR with
tpm2-measure-pcr=.

Closes #40123
2026-01-19 21:59:47 +01:00
Nick Rosbrook
e06ee11150 test: check that currentServer field is set in resolvectl JSON status 2026-01-19 13:48:07 -05:00
Vitaly Kuznetsov
398acccb2a TEST-58-REPART: Add a test for fixate_folume_key
The test checks that the expected hash is correctly recorded to the
generated crypttab and also checks that systemd-cryptsetup handles
the option correctly.
2026-01-19 17:50:25 +01:00
Yu Watanabe
3d2284c7db journal/audit: do not use strjoina() for arbitrary length of received string
Otherwise, when a long message is received, the assertion in strjoina()
may be triggered.

Fixes oss-fuzz#476768320 (https://issues.oss-fuzz.com/issues/476768320).
Fixes #40388.
2026-01-20 01:29:32 +09:00
Luca Boccassi
d059615492 portable: pin attached image via image-policy
When attaching images generate a policy in the portable drop-in
that matches the partition types and content found while dissecting,
so that it can no longer be changed later without a reattach.
2026-01-19 15:54:12 +01:00
Yu Watanabe
67040ea2bc More legacy kernel support removal; follow-ups for XAT_FDROOT (#40384) 2026-01-19 23:10:17 +09:00
zefr0x
985a6fa44b busctl: handle --limit-messages option under the wait verb
Main focus was to not introduce breaking change or duplicated argument.
The `--limit-messages=` option that is used under the `monitor` verb is
reused here. However, both `wait` and `monitor` have contradicting
default behaviors, so it's not the cleanest thing to do.

There was some post-commit discussion about the API in #33961, but the
final name adopted in #34928 wasn't that flexible either to fit nicely
here in the `wait` verbe.

Additionally, there wasn't consideration in #34555 for having uniform
behavrious, so we ended with `wait` verb and `--limit-messages=` option,
rather than `receive` verb with default of continuously receving signals
withtout exit so `--limit-messages=` make more sence and be expectable.
2026-01-19 22:41:33 +09:00
Mike Yuan
1a0df07843 core/cgroup: obsolete DefaultMemoryMin/Low=
Now that our kernel baseline is v5.7 and memory_recursiveprot
is universally enabled, remove userspace workarounds.
2026-01-19 13:33:28 +01:00
Heran Yang
c55aadc13e core/unit: re-find dropin paths of a unit after writting settings
Fixes: ab932a622d ("core: simplify unit_need_daemon_reload() a bit")
Fixes #35710

Co-authored-by: Jian Wen <wenjianhn@gmail.com>
2026-01-18 14:14:24 +09:00
Yu Watanabe
7d23749ddd mkfs-utils: also set $E2FSPROGS_FAKE_TIME if $SOURCE_DATE_EPOCH is set
Follow-up for 7bf0d0c46e.

To support e2fsprogs older than v1.47.1 (released 2024-05-21).

Suggested-by: ZauberNerd <zaubernerd@zaubernerd.de>
2026-01-17 08:45:50 +09:00
Yu Watanabe
b5100a4569 conf-files: several cleanups and fixlets (#40290)
Fixes #40313.
Closes #40285.
2026-01-17 02:51:17 +09:00
Yu Watanabe
d5a7f58d1a Also drop SysV rc.local script support (#40295)
Continuation of #39770.
2026-01-17 02:50:08 +09:00
Luca Boccassi
3e2a5dc2e1 dissect: support mount options when going through mountfsd, requiring privileges via polkit (#39394)
RootImageOptions=/ExtensionImages=/MountImages= all support custom
mount options, but mountfsd does not support it. Add varlink
parameters to allow callers to specify mount options so that
those directives can work as expected. Require additional privs via
polkit.
2026-01-16 14:55:02 +00:00
Yu Watanabe
782569afd0 udevadm: gracefully handle when a maked file is specified to udevadm verify/cat
Previously, since 7cb4508c5a, if a masked
file is specified, the commands failed.
Let's warn that the file is masked and ignore the file.
2026-01-16 23:05:33 +09:00
Yu Watanabe
d207be293c Drop support for SysV rc-local script support
As already announced for several years.
2026-01-16 22:56:28 +09:00
Zbigniew Jędrzejewski-Szmek
3a5b37e162 Split up the giant switch statement in homectl's parse_argv (#40059)
This is in preparation for later changes. The 1500+ line switch statement was very
hard to work with and had quite a bit of duplicated code. This is a rework that
splits outs parts into functions. I split this up into a bunch of commits so that it
can be reasonably reviewed. When viewed as one giant commit, diff just shows
a giant block of removed code and a giant block of added code.

In some cases I wasn't sure why one or the other of the identity arrays is used…
I preserved existing behaviour in all cases.
2026-01-16 14:31:08 +01:00
Luca Boccassi
1bbeb78ea2 manager: add EnqueueMarkedJobs varlink method
Same as the D-Bus method. Returns array of job IDs.
2026-01-16 12:45:48 +00:00
Yu Watanabe
18de7dd90f integration tests: do not adjust log level of udevd in the test script
Similar to 5c60d3011f, but for udevd.
2026-01-14 16:32:38 +01:00
ZauberNerd
7bf0d0c46e mkfs-util: set hash_seed to seed derived value for reproducibility
When creating ext2/ext3/ext4 filesystems, mke2fs generates a random
hash_seed for htree directory indexing. This causes non-reproducible
images even when SOURCE_DATE_EPOCH is set and the same filesystem UUID
is used.

Set the hash_seed explicitly to match the filesystem UUID, ensuring
that repeated builds with the same seed produce bit-for-bit identical
images.

Also add a test case in TEST-58-REPART to verify ext4 reproducibility
by creating the same partition twice and comparing the results.

See https://vdwaa.nl/mkosi-reproducible-arch-images.html

I used claude ai to help me with this change.
2026-01-12 16:57:44 +01:00