Commit Graph
3023 Commits
Author SHA1 Message Date
Yu Watanabe fd1351e3c8 udev-rules: add OPTIONS="dump-json" to dump current status in JSON format
This produces the output similar to 'udevadm test --json=short'.
2025-09-18 08:43:18 +09:00
Yu Watanabe 052b15f4fe udev-config: use secure_getenv() at one more place
Follow-up for b16c6076cb.
2025-09-17 21:51:36 +02:00
Luca Boccassi 9736f634c8 meson: fix link-udev-shared option
This doesn't work anymore, setting it to false still makes
udev link to libsystemd-shared, as an argument was mistakenly
dropped.

Follow-up for 6350d2dbd9
2025-09-17 19:37:54 +01:00
Yu Watanabe ef72263f06 udev: fix grammar
Follow-up for 7e50402aa3.
2025-08-26 06:00:03 +09:00
Yu Watanabe f78a482393 udev: fix typo
Follow-up for 32333754ae.
2025-08-26 04:49:03 +09:00
Yu Watanabe d858b1b10a udev-rules: add missing device name prefix in log message
Otherwise, it is hard to find the dump in journal. With this change,
we can find the entry by e.g.
journalctl -b -u systemd-udevd.service DEVICE=eth0

Follow-up for b4ffb77669.
2025-08-09 11:41:57 +01:00
Yu WatanabeandDeli Zhang 406d8cb029 udev/spawn: continue to read stdout even if the result buffer is full
Previously, when the stdout of a spawned process (e.g. dmi_memory_id) is
truncated, the event source was not re-enabled, that will cause the process
to remain in a write-blocked state if the stdout buffer is full, and the
process will time out:
```
Spawned process 'dmi_memory_id' [1116] timed out after 2min 59s, killing.
Process 'dmi_memory_id' terminated by signal KILL.
```

The solution is to continue enabling the event source so that on_spawn_io()
can continue reading the stdout buffer. When the result buffer is full, the
local `buf` variable will be used to drain remaining stdout.

Co-authored-by: Deli Zhang <deli.zhang@cloud.com>
2025-08-05 10:37:02 +02:00
Yu Watanabe 453e1375d0 udev/node: check the target device node of devlink on removal
If the removal of the devlink is requested due to this is a 'remove' event,
it is trivial that the devlink will not be owned by this device anymore.
Let's read the devlink and if it points to our device node, then we need
to update the devlink. If it points to another device node, then it is already
owned by another device, hence we should not touch it and keep it as is.

Fixes #37823.
2025-08-01 02:21:04 +09:00
Yu Watanabe 239c9a2e5f udev/node: split out link_search_and_update() and reduce indentation
No functional change, just refactoring and preparation for later change.
2025-08-01 02:10:10 +09:00
Zbigniew Jędrzejewski-Szmek 858cb6e49e tree-wide: use ERRNO_NAME almost everywhere
We had errno_to_name() which works for "known" errnos, and returns NULL for
unknown ones, and then ERRNO_NAME which always returns an answer, possibly just
a number as a string, but requires a helper buffer.

It is possible for the kernel to add a new errno. We recently learned that some
architectures define custom errno names. Or for some function to unexpectedly
return a bogus errno value. In almost all cases it's better to print that value
rather than "n/a" or "(null)". So let's use ERRNO_NAME is most error handling
code. Noteably, our code wasn't very good in handling the potential NULL, so
in various places we could print "(null)". Since this is supposed to be used
most of the time, let's shorten the names to ERRNO_NAME/errno_name.

There are a few places where we don't want to use the fallback path, in
particular for D-Bus error names or when saving the error name. Let's rename
errno_to_name() to errno_name_no_fallback() to make the distinction clearer.
2025-07-29 18:05:20 +02:00
Zbigniew Jędrzejewski-Szmek 0e031d5e0b meson: inline output file names
Before 7d247d3cb8, we needed the file name
twice. But now we only need it once, so no need to overcomplicate things
by defining a variable with a single use.

When a variable is used, it's also easier to make a mistake and e.g.
accidentally reuse the variable later.
2025-07-25 12:33:13 +02:00
Zbigniew Jędrzejewski-Szmek 56631ac8df udev: downgrade ENOMEDIUM warnings
I noticed similar warnings in many VM boots:
  fedora (udev-worker)[475]: sr0: Failed to open device node: No medium found
This particular one is from src/udev/udev-builtin-uaccess.c:125, but I think the
same principle should be used in all places: if we are ignoring errors that the
device has been removed, we should also ignore ENOMEDIUM.
2025-07-24 10:42:50 +02:00
Yu Watanabe de69562623 tree-wide: add missing '=' in short comments for function argument 2025-07-22 03:05:54 +09:00
Yu Watanabe 7f6086d530 tree-wide: do not use %m with SYNTHETIC_ERRNO() 2025-07-22 03:05:54 +09:00
Yu Watanabe 4a58d8ed51 udevadm: fix memleak
Fixes a bug in a4a6e21673.

Fixes the following memleak:
```
$ sudo valgrind --leak-check=full build/udevadm cat /usr/lib/udev/rules.d
==3975939==
==3975939== HEAP SUMMARY:
==3975939==     in use at exit: 640 bytes in 1 blocks
==3975939==   total heap usage: 7,657 allocs, 7,656 frees, 964,328 bytes allocated
==3975939==
==3975939== 640 bytes in 1 blocks are definitely lost in loss record 1 of 1
==3975939==    at 0x4841866: malloc (vg_replace_malloc.c:446)
==3975939==    by 0x4ACA71F: malloc_multiply (alloc-util.h:92)
==3975939==    by 0x4ACF988: _hashmap_dump_entries_sorted (hashmap.c:2167)
==3975939==    by 0x4ACFC76: _hashmap_dump_sorted (hashmap.c:2209)
==3975939==    by 0x4AA60A4: hashmap_dump_sorted (hashmap.h:311)
==3975939==    by 0x4AA9077: dump_files (conf-files.c:397)
==3975939==    by 0x4AAA14E: conf_files_list_strv_full (conf-files.c:596)
==3975939==    by 0x42426A: search_rules_file (udevadm-util.c:301)
==3975939==    by 0x424768: search_rules_files (udevadm-util.c:334)
==3975939==    by 0x41287D: cat_main (udevadm-cat.c:110)
==3975939==    by 0x4A7B911: dispatch_verb (verbs.c:139)
==3975939==    by 0x427272: udevadm_main (udevadm.c:121)
==3975939==
==3975939== LEAK SUMMARY:
==3975939==    definitely lost: 640 bytes in 1 blocks
==3975939==    indirectly lost: 0 bytes in 0 blocks
==3975939==      possibly lost: 0 bytes in 0 blocks
==3975939==    still reachable: 0 bytes in 0 blocks
==3975939==         suppressed: 0 bytes in 0 blocks
==3975939==
==3975939== For lists of detected and suppressed errors, rerun with: -s
==3975939== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```
2025-07-11 22:07:41 +09:00
Yu Watanabe 4d7851380a Cleanups for missing_xyz.h headers (#37904)
Continuation of #37960.

The same concern as expalined in #37960 exists also in
missing_syscall.h. If we use enough new glibc, a function we want to use
may be already provided by glibc, but our baseline glibc may not. And it
is hard to detect in our daily development.

This moves all prototypes of syscalls to relevant headers, and missing
syscall functions are defined in relevant .c files of libc wrapper. This
way, we can use usual header as is, e.g. when we want to write code with
`move_mount()`, we can simply use sys/mount.h without checking if it is
supported by our baseline glibc.
2025-07-11 15:20:10 +09:00
Yu Watanabe 2b912d2066 tree-wide: several cleanups for generating symbol lists and gperf files
- pass our system include directories to make generators use our libc
  wrappers and latest kernel headers,
- include relevant headers in generated gperf file,
- use files() rather than find_program(), as the result of
  find_program() cannot be passed to 'input' of custom_target(),
- move generate-bpf-delegate-configs.py to src/core/, as it is only used
  by libcore.
2025-07-11 13:05:42 +09:00
Yu Watanabe 1a60b97524 include: move libc header wrappers to src/include/override/, and kernel headers to src/include/uapi/
Preparation for later changes.
2025-07-11 12:44:26 +09:00
Yu Watanabe ab1333b2b7 udev-rules: do not read udev rules files outside of specified root directory 2025-07-11 10:42:08 +09:00
Yu Watanabe a4a6e21673 udevadm: do not read udev rules files outside of the specified root directory
With this change, an invalid symlink and an empty file is silently
ignored. Hence, the test code is slightly updated.
2025-07-11 10:42:08 +09:00
Yu Watanabe 908b0ea15f udev: gracefully handle ENODEV or friends in opening device node
Fixes #38033.
2025-07-04 09:47:47 +02:00
Daan De Meyer ce06fad9c5 udev: Fix initializing varlink server from listen fd
manager_listen_fds() instructs sd_listen_fds_with_names() to unset
the environment which means that when sd_varlink_server_listen_auto()
is called from manager_start_varlink_server(), when it eventually calls
sd_listen_fds_with_names() it will return zero because the environment
has already been unset in manager_listen_fds().

Fix the issue by not using sd_varlink_server_listen_auto() but instead
keeping track of the varlink socket in manager_listen_fds() and returning
it and passing it to manager_start_varlink_server().
2025-07-03 11:22:34 +02:00
Yu Watanabe aada48970e udev-builtin-uaccess: open device node with O_PATH
Some device node refuses to be opened with read-write mode.
Let's not open with O_RDWR, but open with O_PATH, and use
FORMAT_PROC_FD_PATH().

Follow-up for 1abb592f2f.

Fixes #38033.
2025-07-03 12:46:35 +09:00
Yu Watanabe 4f18ff2e29 tree-wide: include unistd.h where necessary
We use symbols provided by unistd.h without including it. E.g.
open(), close(), read(), write(), access(), symlink(), unlink(), rmdir(),
fsync(), syncfs(), lseek(), ftruncate(), fchown(), dup2(), pipe2(),
getuid(), getgid(), gettid(), getppid(), pipe2(), execv(), _exit(),
environ, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, F_OK, and their
friends and variants, so on.

Currently, unistd.h is indirectly included mainly in the following two paths:
- through missing_syscall.h, which is planned to covert to .c file.
- through signal.h -> bits/sigstksz.h, which is new since glibc-2.34.
  Note, signal.h is included by sd-eevent.h. So, many source files
  indirectly include unistd.h if newer glibc is used.

Currently, our baseline on glibc is 2.31. We need to support glibc older
than 2.34, but unfortunately, we do not have any CI environments with
such old glibc. CIFuzz uses glibc-2.31, but it builds only fuzzers, and
many files are even not compiled.
2025-06-30 09:19:15 +02:00
Yu Watanabe b351ebdc97 Revert "tree-wide: use CONF_FILES_CHASE_BASENAME where root directory is specified"
This reverts commit 6b606f3586.

The commit was mistakenly merged without review, and has several issues.
Let's revert at least now.
2025-06-29 10:15:56 +09:00
Zbigniew Jędrzejewski-Szmek 7d247d3cb8 meson: drop explicit custom_target names
[1] says:
> Since 0.60.0 the name argument is optional and defaults to the basename of
> the first output
We specify >= 0.62 as the supported version, so drop the duplicate name in all cases
where it is the same as outputs[0], i.e. almost all cases.

[1] https://mesonbuild.com/Reference-manual_functions.html#custom_target
2025-06-28 17:14:50 +02:00
Yu Watanabe 6b606f3586 tree-wide: use CONF_FILES_CHASE_BASENAME where root directory is specified
Otherwise, the result may point to outside of the root directory.

This also sets CONF_FILES_REGULAR and CONF_FILES_FILTER_MASKED, as the
callers will call fopen() or friends for the result, thus the enumerated
results must be non-empty regular files.
2025-06-28 04:13:43 +09:00
Yu Watanabe fe3ada076e cpu-set-util: introduce config_parse_cpu_set()
Then, make parse_cpu_set() as a tiny wrapper of it.

Note, previously when an invalid CPU range, e.g. "3-0", is specified,
we ignore the range but allocate an empty set. But, with this commit,
now the conf parser simply ignore it without no side effect.
This potentially changes behavior of a system with such invalid setting,
but the change should be favorable for consistency with other parsers.
2025-06-24 00:20:20 +09:00
Yu Watanabe 16069d753e udev/net: several cleanups for config_parse_rps_cpu_mask()
- Previously, `LinkConfig.rps_cpu_mask == NULL` indicates setting RPS
  will be skipped, but now make the condition is changed to
  `LinkConfig.rps_cpu_mask.set == NULL`. Then, we can avoid allocating
  CPUSet when something configured.
- When "disable" or "all", now allocate a temporal object, and then
  replace with it.

No functional change, just refactoring.
2025-06-24 00:20:20 +09:00
Yu Watanabe 296fe3d511 cpu-set-util: rename cpu_set_reset() -> cpu_set_done()
This also introduces cpu_set_done_and_replace().

No functional change, just refactoring.
2025-06-24 00:20:20 +09:00
Yu Watanabe f4093f43fb cpu-set-util: rename cpu_set_add_all() and cpu_mask_add_all()
This renames
- cpu_set_add_all() -> cpu_set_add_set(),
- cpu_mask_add_all() -> cpu_set_add_all().

No functional change, just refactoring.
2025-06-24 00:20:20 +09:00
Lennart Poettering 9ea5a6e7d6 fs-util: replace symlink_atomic_full_label() by a flag to symlinkat_atomic_full()
More porting work to label_ops_pre()/label_ops_post()

This also enables labelling of the /etc/localtime symlink in
systemd-firstboot, which should address one small facet of #37857
2025-06-18 10:21:25 +02:00
Mike Yuan 85352c095e various: turn off SO_PASSRIGHTS where fds are not expected 2025-06-17 13:16:44 +02:00
Mike Yuan 718e7eb184 notify-recv: disable SO_PASSRIGHTS by default in notify_socket_prepare() 2025-06-17 13:16:43 +02:00
Mike Yuan 58f3be82ce udev-ctrl: enable SO_PASSCREDS on listening socket already rather than on accept()
This matches what systemd-udevd-control.socket does.
2025-06-17 13:16:07 +02:00
Lennart Poettering 0f64d570cb repart: fix CopyBlocks=auto for verity-sig partitions, even harder (#37704)
@DaanDeMeyer, this is for you.

Seems to work great here to duplicate ParticleOS onto another disk.
2025-06-06 16:06:26 +02:00
Lennart Poettering 188467dfd9 udev: add udev properties that point to verity/verity sig metadata partitions from data partitions
This extends the dissect_image builtin to actually add device node
references to the device nodes where the associated data is placed, if
we can find it.

This is kept very generic, and independent from the roothash properties
and suchlike, since it makes sense to make it possible to set these
properties also independently of the dissect-image builtin.

The device path is a /dev/disk/by-diskseq/ symlink, so that we have
stable reference that are not subject to dev_t reuses.
2025-06-06 12:37:41 +02:00
A. Wilcox 6b783209a8 tree-wide: basename -> path_extract_filename 2025-06-06 19:06:48 +09:00
Yu Watanabe 8c57161d65 udev-rules: skip loading /etc/shadow
We only require UID/GID, hence not necessary to load information from shadow.
2025-06-04 21:50:12 +09: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
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
Yu Watanabe 0436240dd2 udevadm: allow to specify device by device ID (#37636) 2025-06-02 18:02:36 +09: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 d0ba749e8c udevadm: allow to specify device by device ID
We have already exposed device ID in the output of device ID in J
fields. Also sd_device_get_device_id() and sd_device_new_from_device_id()
are already public. Hence, making udevadm accept device IDs may be
useful.

With this change, as we save several data in /run/udev with device ID,
we can call udevadm something like the following:
```
udevadm info $(ls /run/udev/tags/uaccess)
```
Then, we can show all devices that has uaccess tag.
2025-05-29 04:04:22 +09:00
Yu Watanabe 337f45d811 udevadm-info: use RET_GATHER() at one more place 2025-05-29 04:04:22 +09:00
Frantisek Sumsal a852f5c27d udevadm-info: make the error messages slightly more consistent
At least across the udevadm-info.c file. No functional changes.
2025-05-26 16:57:22 +02:00
Frantisek Sumsal 1420ffffc5 udevadm-info: print the original input on error
Print the original input value on error instead of the consumed string
(which will be empty).

Previously:
$ udevadm info /dev/block/251:0 -e --attr-match='foo=\'
Failed to parse key/value pair : Invalid argument
$ udevadm info /dev/block/251:0 -e --attr-match='foo'
Missing '=' in key/value pair (null).

Now:
$ build/udevadm info /dev/block/251:0 -e --attr-match='foo=\'
Failed to parse key/value pair foo=\: Invalid argument

(The second scenario can't be hit anymore since
d89b3004da due to an extra check before
calling parse_key_value_argument().)
2025-05-26 16:56:55 +02: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
Daan De Meyer 1e35e81b2c tree-wide: Clean up includes
Preparation for cleaning up includes in src/shared.
2025-05-22 21:10:15 +02:00