Commit Graph
3191 Commits
Author SHA1 Message Date
Lennart Poettering 941a9ff40c tree-wide: relax access mode of private Varlink sockets a bit 2026-06-23 23:10:02 +02:00
jmestwa-coder 0f2e5bf95f cdrom_id: zero scsi response buffers before parsing 2026-06-21 12:27:31 +02:00
Luca Boccassi 99109e0dc7 udev: fix build failure due to concurrent merge
Follow-up for 60686a33c3
2026-06-19 19:49:19 +01:00
Lennart Poettering d3d68a2937 network: hook up "machine tag" concept, also with .network/.link/.netdev files
Follow-up for: 461ec6facc
2026-06-19 20:38:13 +02:00
Luca Boccassi 60686a33c3 udev: run workers in sibling cgroup and use cgroup.kill
Since a1f4fd3876 udev processes
run in an 'udev' subcgroup, to avoid killing control processes
when clearing workers. But the main process is still in the same
cgroup, so the atomic cgroup.kill cannot be used.

If the main subcgroup exists, try to create a sibling 'workers'
cgroup, and use it for workers processes, and use cgroup.kill if
available.

This is especially useful as rules can spawn arbitrary programs/scripts
and TasksMax= is set to unlimited.
2026-06-19 19:36:44 +01:00
Daan De Meyer 1dc599ce41 udev-builtin-blkid: keep probing the boot disk when it needs a loop device
Since 4e0eabd401 ("udev: also trigger loop device for boot disk when
partition scanning is unsupported"), builtin_blkid() bails out entirely as
soon as probe_gpt_boot_disk_needs_loop() reports that a loop device is
needed, skipping all superblock probing. As a result whole-disk properties
such as ID_PART_TABLE_UUID and ID_FS_* are no longer set.

This regresses any whole disk whose partitions the kernel cannot expose
itself but which is otherwise perfectly probeable, most notably
device-mapper multipath disks: kernel partition scanning is disabled on them
(their partitions are managed in userspace by kpartx), so they are now
flagged as needing a loop device and lose their ID_PART_TABLE_UUID.

The early return was never necessary. The original intent was only to skip
root partition discovery on the device, and that already happens on the loop
device instead: find_gpt_root() bails when the kernel can't scan partitions,
blkid probes at the device's own logical sector size so a GPT written for a
different sector size is simply not detected, and PART_ENTRY_* is only
emitted for partitions the kernel actually registered, of which a
loop-needing whole disk has none. So keep probing the device for its
whole-disk properties unconditionally and let partition and root discovery
happen on the loop device.

Co-developed-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-15 16:00:39 +02:00
Luca Boccassi b0ede9f9ee tree-wide: convert dlopen_*() callers to DLOPEN_* wrapper macros
Switch the executable-owned call sites from the plain dlopen_<lib>()
helpers to the new DLOPEN_<LIB>() macros, so that each binary that loads
an optional library at runtime now carries its own .note.dlopen note
instead of relying solely on libsystemd-shared. Each call site passes a
priority reflecting whether it hard-depends on the library (required) or
degrades gracefully without it (recommended).

Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 18:46:24 +01:00
Chris Patterson 779a3a13ae udev: preserve rule-set properties on failed network interface rename
When rename_netif() failed for a reason other than -EBUSY (e.g. -EEXIST
because NAME= conflicts with an existing interface), the revert path
rewrote the on-disk udev database from dev_db_clone (the pre-rules
snapshot) and then returned the error. The caller in
udev_event_execute_rules() bailed out before reaching the final
device_update_db(dev), so every property the rules had attached to the
device during this event (including ENV{}= assignments made alongside
the failing NAME=) was silently dropped from /run/udev/data/.

Persist 'dev' from inside the revert block, after its syspath and
INTERFACE have been restored. The cloned snapshot is still written
first to clear ID_RENAMING/ID_PROCESSING; the subsequent dev write
keeps the rule-applied properties without resurrecting the new name.
Only persist when r < 0, since the -EBUSY path returns success and the
caller will write the DB itself.

Add a TEST-17-UDEV.rename-netif regression test that pre-creates the
rename target, then triggers rules that set three ENV{}= properties
(one on a rule line before the failing NAME=, one on the same line as
NAME=, and one on a rule line after) and asserts all three are still
visible via udevadm info on the source interface. The neighbouring
test_netif_renaming_conflict already exercises the same -EEXIST revert
path but only checks the SYSTEMD_ALIAS broadcast, which is why this
regression went unnoticed.

Verified against unpatched origin/main (b4aff10ac0): the new test
fails, udevadm reports only kernel-supplied fields for the source
interface, and /run/udev/data/n<ifindex> is 0 bytes. With this patch
applied all three properties survive regardless of whether they were
set before, on, or after the failing NAME= rule line.

Downstream impact (NetworkManager managing an interface that rules had
marked NM_UNMANAGED=1): https://redhat.atlassian.net/browse/RHEL-178481

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

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 02:08:24 +09:00
Yu Watanabe e329ef572d udev: ignore errors in adding property with spurious value
Since a62cd5a153, when an invalid property
is being added, device_add_property() refuses it with -EINVAL.
Before the commit, the function could fail with only -ENOMEM, and if it fails,
processing udev rules was aborted.

Let's not hard fail when udev rules or udev builtins try to add an invalid
property, and let's just log and ignore the failure.

Follow-up for a62cd5a153.

Fixes #41339 and #41296.
2026-05-27 04:04:47 +09:00
Daan De Meyer 74d392ed1b tree-wide: standardize header names across src/fundamental, src/basic and src/shared
Drop the -fundamental suffix from src/fundamental/ headers in favor of names
that match their src/basic/ or src/shared/ counterparts (e.g.
macro-fundamental.h -> macro.h, assert-fundamental.h -> assert-util.h,
cleanup-fundamental.h -> cleanup-util.h). Rename src/basic/{btrfs,label}.{c,h}
to use the -util suffix to match the existing shared/btrfs-util and
shared/label-util siblings. Rename src/shared/mkdir-label.{c,h} to mkdir.{c,h}
and src/shared/tmpfile-util-label.{c,h} to tmpfile-util.{c,h} to match the
corresponding src/basic names.

This saves us from having to come up with separate names for files that do
the same thing across tiers, and it makes it easier to move stuff between
src/fundamental, src/basic and src/shared: consumers just #include "foo.h"
and pick up whichever tier their -I path resolves to first, so call sites
don't need to be updated when an API moves between layers.

Where a higher-tier wrapper exists (e.g. src/basic/macro.h wrapping
src/fundamental/macro.h), the wrapper uses an explicit "../fundamental/foo.h"
or "../basic/foo.h" relative include for the lower-tier header. We can't use
GCC's #include_next directive for this — when the wrapper is reachable both
via same-dir-as-source lookup and via -I (e.g. -Isrc/shared) for the
directory it lives in, #include_next advances by exactly one slot in libcpp's
internal directory chain and lands on the same physical directory it was
already in, never reaching the lower-tier sibling (see make_cpp_dir() in
gcc/libcpp/files.cc:1986).

To make sure the right headers are always picked up, the include directories
are reordered so that e.g. src/shared always takes priority over src/basic and
similar for the other directories.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 10:33:03 +09:00
Quentin Deslandes 7dfbbfb90d udev/net: add IRQAffinityNUMA= option for NUMA-aware filtering
Add support for filtering IRQ affinity to CPUs on a specific NUMA node
via the new IRQAffinityNUMA= option in .link files. The option accepts:
- "local": use the NUMA node local to the NIC's PCIe slot
- Explicit node number (0, 1, 2, ...): use CPUs on the specified node

When both IRQAffinity= and IRQAffinityNUMA= are specified, their
intersection is used. If the intersection is empty, an error is logged
and IRQ affinity configuration is skipped.

When "local" is specified but the device's NUMA node cannot be
determined (numa_node shows -1), a warning is logged and IRQ affinity
configuration is skipped.
2026-05-20 11:39:11 +02:00
Quentin Deslandes a9e821549b udev/net: add IRQAffinity= option to filter eligible CPUs
Add IRQAffinity= option to .link files that filters the set of CPUs
eligible for IRQ placement. This works in conjunction with
IRQAffinityPolicy= to constrain which CPUs receive network IRQs.

When specified with spread policy, only the listed CPUs are considered
for IRQ distribution. When specified with single policy, IRQs are
pinned to the first CPU in the allowed set instead of CPU 0.
2026-05-20 11:39:10 +02:00
Quentin Deslandes cf32bd9e7c udev/net: implement IRQAffinityPolicy=spread with topology awareness
Implement the spread policy for IRQ affinity distribution using a
topology-aware algorithm. The algorithm:

1. Discovers CPU topology from sysfs (NUMA node, package, die/L3, core)
2. Groups CPUs by L3 cache domain (die) with equidistant ordering
3. Round-robins across dies, spreading IRQs across the system
4. Uses first hyperthread of each core before second hyperthreads
5. Applies IRQ affinity via /proc/irq/<n>/smp_affinity

When there are more IRQs than CPUs, queues wrap around using round-robin.
2026-05-20 11:39:10 +02:00
Quentin Deslandes 66892d877c udev/net: add IRQAffinityPolicy= option for .link files
Add support for configuring IRQ affinity for network interfaces via
systemd .link files. For now, the new IRQAffinityPolicy= option in the [Link]
section only accepts "single", which pins all MSI IRQs to CPU 0.

This allows declarative IRQ affinity configuration for network devices
during udev processing, which is useful for optimizing network
performance on multi-core systems.

Further commits will expand the options supported by IRQAffinityPolicy=.
2026-05-20 11:39:10 +02:00
Jiri Pirko 1f7d0a4674 udev-builtin-net_id: name auxiliary sub-function (SF) host network devices
Some drivers (currently mlx5_core) expose sub-functions (SFs) of a PCI
Physical Function as auxiliary devices. Each SF carries a host network
interface that sits below the aux device in sysfs:

  /sys/devices/.../<PF BDF>/mlx5_core.sf.<idx>/net/eth<N>

Because the network device's immediate parent is the aux device and not
a PCI device, names_pci() bails out and these interfaces fall through
to the kernel-assigned eth<N> name, which is not stable across reboots,
module reloads or topology changes.

The naming applies when the SF network device's direct sysfs parent is
the aux device that exposes sfnum, i.e. the kernel driver passes the
aux device to SET_NETDEV_DEV(). mlx5_core does so. ice's
ice_sf_cfg_netdev() currently passes the parent PF's PCI device, so ice
SF network devices sit as siblings of the PF rather than below the aux
device and fall outside this precondition; pending a kernel change in
ice to mirror mlx5's SET_NETDEV_DEV(netdev, &adev->dev), they continue
to receive the kernel-assigned name as they do today.

The aux device exposes 'sfnum', the user-defined sub-function number
(the value passed to "devlink port add ... sfnum N"), which is stable
and unique within its parent PF. The aux device's direct sysfs parent
is the PF's PCI device.

Treat an SF host network device analogously to an SR-IOV VF host
network device: walk to the parent PCI function, derive the base name
from there, then append a single-character "S<sfnum>" suffix. Lowercase
's' is already taken (slot) and the existing grammar uses one character
per token, so 'S' is the best option.

E.g. for an SF whose parent PF is at PCI 0000:c1:00.0 and which was
added with "sfnum 88":

  ID_NET_NAME_PATH=enp193s0f0S88
  ID_NET_NAME_SLOT=enp193s0f0S88

This is parallel to how SR-IOV VFs get a "v<N>" suffix on top of the
parent PF's name.

Gate the new behaviour behind NAMING_SUBFUNC and NAMING_V261. Document
the new suffix in both the ID_NET_NAME_SLOT and ID_NET_NAME_PATH
grammars in systemd.net-naming-scheme(7) and add a v261 history entry.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-19 14:39:20 +02:00
Jiri Pirko 477f84cf91 udev-builtin-path_id: emit 'sf-<N>' token for auxiliary sub-functions
Some drivers expose sub-functions (SFs) of a PCI Physical or Virtual
Function as auxiliary devices that carry a stable 'sfnum' sysfs
attribute — the user-defined sub-function number (e.g. the value
passed to "devlink port add ... sfnum N"). The SF's leaf devices
(uverbs, infiniband, net, ...) sit below this aux device in sysfs:

  /sys/devices/.../<PF or VF BDF>/<sf aux>/.../<leaf>

Currently path_id walks straight past the aux device, so all leaf
devices below an SF end up sharing ID_PATH=pci-<BDF> with their
parent PF or VF. For uverbs this causes a /dev/infiniband/by-path/
symlink collision, and for any other consumer of ID_PATH/ID_PATH_TAG
it makes PF and SF (or VF and VF-SF) indistinguishable.

Recognise the 'auxiliary' subsystem in path_id's walk: when the aux
device exposes 'sfnum', prepend an 'sf-<N>' token; otherwise leave
it untokenised. The result for an SF whose parent PF is at PCI
0000:c1:00.0 and which was added with "sfnum 88" is:

  ID_PATH=pci-0000:c1:00.0-sf-88
  ID_PATH_TAG=pci-0000_c1_00_0-sf-88

This is parallel to how net_id's NAMING_SUBFUNC scheme appends 'S<N>'
on top of the PF base name. Aux devices without 'sfnum' keep the
pre-patch behaviour: the walk skips over them with no token. Existing
ID_PATH values for PF and VF leaf devices are therefore unchanged,
the change is purely additive, and there is no need to gate it behind
a naming scheme (path_id itself is unversioned).

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-19 14:39:20 +02:00
Daan De Meyer bdbcff6530 Various dlopen/linking cleanups from #42100 (#42166)
- **bpf-util: rename from bpf-dlopen, unify version-specific symbol
handling**
- **cryptsetup: dlopen libcryptsetup in tokens**
- **tree-wide: dlopen libpam in pam plugins**
- **test-bus-marshal: dlopen() glib and libdbus instead of linking
directly**
- **lock-util: Simplify timeout for lock_generic_with_timeout()**
- **color-util: simplify hsv_to_rgb, fix rgb_to_hsv negative-hue wrap**
- **tree-wide: Use our own macros instead of fabs()/fmax()/fmin()**
- **locale-util: dlopen() libintl instead of linking against it**
- **home: Use log2u64() over log2()**
- **meson: drop libdl, threads, and librt dependencies**
- **libc: Use dlsym() from a constructor instead of weak symbols**
- **libc: Make sure C23 versions of strtol(), sscanf() are not used**
2026-05-19 08:54:27 +02:00
Daan De Meyer a14adac423 meson: drop libdl, threads, and librt dependencies
Our baseline glibc is 2.34, which merged libdl, libpthread (the
dependency('threads') target), and librt into libc. Empty .so/.a stubs
remain for backward compatibility with old binaries, but new builds
resolve dl_*, pthread_*, mq_*, timer_*, etc. directly from libc.
On musl the same libraries are likewise empty stubs.

Drop the libdl, threads, and librt entries from every meson.build, and
remove the now-stale 'Libs.private: -lrt -pthread' from libudev.pc.in
since both flags resolve to empty link-time stubs on glibc 2.34+ and
musl.

Verified with readelf -d that libsystemd.so, libudev.so, and systemd no
longer carry DT_NEEDED entries for libdl/libpthread/librt.
2026-05-18 21:17:38 +00:00
Yu Watanabe 2a1a026d72 udev-builtin-input-id: drop unused value 2026-05-18 02:55:56 +09:00
Yu Watanabe 6f72bb7bc9 tree-wide: use device_get_sysattr_unsigned() and friends 2026-05-18 02:55:56 +09:00
Yu Watanabe 6ad682d70f udev-builtin-usb_id: make set_usb_iftype() and friends return const char* 2026-05-18 02:55:56 +09:00
Yu Watanabe 23c93e2cd6 udev-builtin-usb_id: use device_get_sysattr_unsigned() and friends
This also fix the parser of bInterfaceClass from safe_atoi() to
safe_atou_full() as it is unsigned hex.
2026-05-18 02:55:56 +09:00
Yu Watanabe 06d687ffac tree-wide: use device_get_sysattr_safe_string()
The obtained strings are passed to another function, e,g, handled as a
path and opened, printed to the terminal, written to a file, saved to
udev database as udev property, exposed through DBus, passed to logger,
and so on. Hence, these should not contain any malicious characters.
2026-05-18 02:55:56 +09:00
Yu Watanabe fdce4d4687 udev-builtin-net_id: quote strings in log messages 2026-05-18 02:55:56 +09:00
Yu Watanabe 35edd031b9 udev-builtin-net_id: use EINVAL when we get unexpected sysattr value
The results are completely ignored or only checked if it is negative or
not. Hence, this does not change anything.
2026-05-18 02:55:56 +09:00
Yu Watanabe c5a04f59d9 udev: drop redundant checks
This partially reverts 16325b35fa,
as bad characters are already filtered.
2026-05-18 02:55:56 +09:00
Yu Watanabe c6ea72e39a Revert "udev-builtin-net-id: print cescaped bad attributes"
This reverts commit 7c4047957e.

This is not necessary, as bad characters are already filtered.
2026-05-18 02:55:56 +09:00
Yu Watanabe d0e48e2601 udev: use device_get_sysattr_safe_string() in device_get_sysattr_value_filtered()
Then, renamed to device_get_sysattr_safe_string_filtered().
2026-05-18 02:55:56 +09:00
Yu Watanabe 5768f1dd6f Final batch of conversions to option and verb macros (#42127) 2026-05-17 03:50:48 +09:00
Zbigniew Jędrzejewski-Szmek d512d3c6d3 treewide: get rid of remaing getopt/getopt_long stuff 2026-05-16 18:37:12 +02:00
Zbigniew Jędrzejewski-Szmek 39a3647539 tree-wide: get rid of old dispatch_verb
Also rename dispatch_verb_with_args to dispatch_verb.
2026-05-16 18:37:10 +02:00
Zbigniew Jędrzejewski-Szmek 8bc7cf64d1 udev: drop leftover includes of getopt.h
Not sure why those were left and why clang-tidy didn't complain.
2026-05-16 18:36:08 +02:00
Yu Watanabe 3b64024464 udev/node: drop support of old file format in /run/udev/links/
The new file format in /run/udev/links/ has been introduced in
377a83f0d8 (v250, released on 2021-12-23).
Let's drop the old format support, to simplify the logic.
2026-05-15 13:47:45 +02:00
Yu Watanabe dfe0e81de6 udev/watch: use mapping from device ID -> watch on restart
The mapping from device ID to watch handle has been introduced by
e7f781e473 (v249, released on 2021-07-07).
Let's drop the runtime upgradability of udevd from an ancient version.
2026-05-15 13:47:45 +02:00
Zbigniew Jędrzejewski-Szmek 62a489fbf9 tree-wide: rename unref_and_replace_full to unref_and_replace_new_ref
We have a number of *_unref_and_replace macros. One could think that
they are like the various free_and_replace variants, but they actually
create a new ref to the passed object. The free_and_replace variants
take ownership of the argument. This inconsistency is surprising. Rename
all those functions to have "_new_ref" at the end to make the difference
clear.
2026-05-08 11:14:13 +02:00
Zbigniew Jędrzejewski-Szmek 72fedd6037 Couple of coverity fixes (#41951) 2026-05-05 22:45:13 +02:00
Lennart Poettering fc8d547642 udev-builtin-tpm2-id: gracefully skip tpm2 identification if tss2-libs are not installed
Fixes: #41714
2026-05-05 17:21:48 +02:00
Luca Boccassi 83436d4b7e scsi_id: fix memory leak of option_get_synopsis() return value
option_get_synopsis() returns a heap-allocated string. Capture it in
a _cleanup_free_ variable so it is freed after being used in the log
message.

CID#1657828

Follow-up for 05fea7df1b
2026-05-05 13:55:00 +01:00
Zbigniew Jędrzejewski-Szmek f7434671bd shared/help-util: automatically append ":" in sections 2026-05-05 11:14:33 +02:00
Lennart Poettering 99ce7a0770 options: get rid of "on_error" parameter to FOREACH_OPTION
I am really not a fan of full code lines passed to macros as parameters.
Let's get rid of the 3rd parameter of FOREACH_OPTION() hence:

1. Let's return errors just as a regular value (though a negative one),
   that can be handled via a OPTION_ERROR case statement for the switch.
   This normalizes handling of the error, just like any other event
   returned by the option parser.

2. In order to avoid exploding the amount of boilerplate in each use
   (that just propagates the error on OPTION_ERROR), let's then
   introduce an explicit FOREACH_OPTION_OR_RETURN(), that returns from
   the calling function on its own (and makes that clear in the name).

Together this cleans up, normalizes the logic and shortens the code.
2026-04-30 11:12:33 +01:00
Zbigniew Jędrzejewski-Szmek 13f6feda78 udevadm: convert verb dispatch to VERB macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 15:28:05 +02:00
Zbigniew Jędrzejewski-Szmek fcfd42a30c udev-builtin-hwdb: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 15:28:05 +02:00
Zbigniew Jędrzejewski-Szmek 408d18f4d2 udev-builtin-blkid: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00
Zbigniew Jędrzejewski-Szmek c86ba4e037 udevadm-info: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00
Zbigniew Jędrzejewski-Szmek 222b417494 udevadm-trigger: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00
Zbigniew Jędrzejewski-Szmek 5656636a41 udevadm-wait: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00
Zbigniew Jędrzejewski-Szmek 0257deff36 udevadm-control: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00
Zbigniew Jędrzejewski-Szmek a00de0b648 udevadm-lock: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00
Zbigniew Jędrzejewski-Szmek ed2b92e205 udevadm-settle: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00
Zbigniew Jędrzejewski-Szmek 5a2144f9bc udevadm-monitor: convert to OPTION macros
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:00:41 +02:00