Commit Graph
100 Commits
Author SHA1 Message Date
Yu Watanabe b7622cbab6 sd-device: chase sysattr and refuse to read/write outside of sysfs (#36004) 2025-01-24 01:58:19 +09:00
Yu Watanabe e7fdc7644f udevadm: introduce cat command to show udev rules (#35893)
Closes #35818.
2025-01-24 01:49:42 +09:00
Yu Watanabe 1fe5b06363 sd-device: use device_in_subsystem() at more places 2025-01-23 22:54:11 +09:00
Yu Watanabe 640f8e9c4d sd-device: use specific setters for read entries from uevent file
Previously, if e.g. DRIVER=foo is specified in uevent file, the value is
only saved as property, but was not set to sd_device.driver.
That was inconsistent to the case when a device is created through
netlink uevent.

Let's always set when we get e.g. sd_device.driver when DRIVER=foo
from both uevent file and netlink uevent.
2025-01-23 22:54:11 +09:00
Yu Watanabe 17dc9ec4b6 sd-device: use sd_device_get_sysattr_value() to read uevent file
This also replaces the custom parser with strv_split_newlines_full().
No functional change, just refactoring.
2025-01-23 22:54:11 +09:00
Yu Watanabe 6ebbdcc0dd sd-device: use sd_device_get_sysattr_value() to read special symlinks
Then, cached result may be used. No functional change, just refactoring.
2025-01-23 22:54:11 +09:00
Yu Watanabe 8d89667aba sd-device: chase sysattr and refuse to read/write files outside of sysfs
This makes sd_device_get_sysattr_value()/sd_device_set_sysattr_value()
refuse to read/write files outside of sysfs for safety.

Also this makes
- use chase() to resolve and open the symlink in path to sysfs attribute,
- use delete_trailing_chars(),
- include error code in cache entry, so we can cache more error cases,
- refuse caching value written to uevent file of any devices, i.e.
  sd_device_set_sysattr_value(dev, "../uevent", "add") will also not
  cache the value "add".
2025-01-23 22:54:11 +09:00
Yu Watanabe 06503dd0df fileio: make read_virtual_file_at() accept O_PATH file descriptor
Then, merge read_virtual_file_at() and read_virtual_file_fd(), and make
the latter inline.
2025-01-23 22:54:07 +09:00
Yu Watanabe f3c5c2b001 fileio: make write_string_file_at() accept O_PATH fd and an empty filename
Then, introduce an inline wrapper write_string_file_fd().
2025-01-23 22:53:05 +09:00
Yu Watanabe 9e096259ce fileio: fix verification on failure in write_string_file_full()
Fixes a bug introduced by 0ab5e2a4b4.
2025-01-23 22:24:19 +09:00
Yu Watanabe 7f2175eabb udevadm: introduce cat command
This introduces 'udevadm cat' command, that shows udev rules files or
udev.conf, which may be useful for debugging.

Closes #35818.
2025-01-23 22:23:45 +09:00
Yu Watanabe bbe1ba5e87 bash-completion/udevadm-verify: suggest found udev rules files
This also fixes the issue that no suggestion is provided after a standalone
option is specified.
2025-01-23 22:23:45 +09:00
Yu Watanabe 7cb4508c5a udevadm-verify: chase specified paths
Also, when a filename is specified, also search udev rules file in
udev/rules.d directories.

This also refuses non-existing files, and file neither nor a regular
nor a directory, e.g. /dev/null.
2025-01-23 22:23:45 +09:00
Yu Watanabe 8e0f023548 udev-rules: log the first line number when continued 2025-01-23 22:23:45 +09:00
Yu Watanabe 86a08e70a8 udev: sort builtins
Then, 'udevadm test-builtin --help' lists builtins alphabetically.
2025-01-23 22:23:45 +09:00
Yu Watanabe c3d526d765 shell-completion/udevadm: add net_driver
Follow-up for 2b5b25f123.
2025-01-23 22:23:45 +09:00
Yu Watanabe eb86b4e63b tree-wide: use hash ops with destructor (#36107) 2025-01-23 22:20:42 +09:00
Yu Watanabe 38f7edd9d3 hashmap: drop hashmap_free_free() and friends 2025-01-23 18:22:53 +09:00
Yu Watanabe 58f0cd14a0 test: use hash ops with destructor 2025-01-23 18:22:53 +09:00
Yu Watanabe 06835cb397 remount-fs: use hash ops with destructor 2025-01-23 18:22:53 +09:00
Yu Watanabe 60cc858e9d exec-util: use hash ops with destructor 2025-01-23 18:22:52 +09:00
Yu Watanabe 04b7949ecf network: use hash ops with destructor 2025-01-23 18:22:47 +09:00
Yu Watanabe 938a6b49bd sd-journal: use hash ops with destructor 2025-01-23 18:19:28 +09:00
Yu Watanabe 2d23cadd19 journal-file: use hash ops with destructor
This also makes JournalFile.chain_cache allocated when necessary.
2025-01-23 18:19:28 +09:00
Yu Watanabe b87501ea3c sd-bus: use hash ops with destructor
This also makes vtable_methods and vtable_properties managed by Set,
as the key and value of each entry are equivalent.
2025-01-23 18:19:28 +09:00
Yu Watanabe 4516022833 delta: use hash ops with destructor
This also makes it use RET_GATHER().
2025-01-23 18:19:28 +09:00
Yu Watanabe c1bfee0bdb bootctl: use hash ops with destructor
This also makes the hashmap allocated when necessary.
2025-01-23 18:19:28 +09:00
Yu Watanabe 852c05c94f catalog: modernize code
- set destructors to catalog_hash_ops,
- acquire OrderedHashmap when necessary,
- gracefully handle NULL catalog directories and output stream,
- rename function output arguments,
- add many many assertions,
- use RET_GATHER().
2025-01-23 18:19:28 +09:00
Yu Watanabe 12006a7233 wait-online: use hash ops with destructor 2025-01-23 18:19:28 +09:00
Yu Watanabe a22620e39f udev: use hash ops with destructor 2025-01-23 18:19:28 +09:00
Yu Watanabe 57f15d05bf udevadm-monitor: use hash ops with destructor
This also make it use STATIC_DESTRUCTOR_REGISTER() macro, and logs OOM
error.
2025-01-23 18:19:00 +09:00
Yu Watanabe 0284fcc0ab hash-funcs: introduce several basic hash_ops with value destructor 2025-01-23 18:15:42 +09:00
Yu Watanabe 90cf374e45 run: add --job-mode= argument (#34708)
systemctl has a --job-mode= argument, and adding the same argument to
systemd-run is useful for starting transient scopes with dependencies.
For example, if a transient scope BindsTo a service that is stopping,
specifying --job-mode=replace will wait for the service to stop before
starting it again, while the default job mode of "fail" will cause the
systemd-run invocation to fail.
2025-01-23 18:11:30 +09:00
Yu Watanabe b6b8148459 core/device: do not drop backslashes in SYSTEMD_WANTS=/SYSTEMD_USER_WANTS= (#35869)
Let consider the following udev rules:
```
PROGRAM="/usr/bin/systemd-escape foo-bar-baz", ENV{SYSTEMD_WANTS}+="test1@$result.service"
PROGRAM="/usr/bin/systemd-escape aaa-bbb-ccc", ENV{SYSTEMD_WANTS}+="test2@$result.service"
```
Then, a device expectedly gains a property:
```
SYSTEMD_WANTS=test1@foo\x2dbar\x2dbaz.service test2@aaa\x2dbbb\x2dccc.service
```
After the event being processed by udevd, PID1 processes the device, the
property previously was parsed with
`extract_first_word(EXTRACT_UNQUOTE)`, then the device unit gained the
following dependencies:
```
Wants=test1@foox2dbarx2dbaz.service test2@aaax2dbbbx2dccc.service
```
So both `%i` and `%I` for the template services did not match with the
original data, and it was hard to use `systemd-escape` in `PROGRAM=`
udev rule token.

This makes the property parsed with
`extract_first_word(EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE)`, hence the
device unit now gains the following dependencies:
```
Wants=test1@foo\x2dbar\x2dbaz.service test2@aaa\x2dbbb\x2dccc.service
```
and `%I` for the template services match with the original data.

Fixes a bug caused by ceed8f0c8b (v233).

Fixes #16735.
Replaces #16737 and #35768.
2025-01-23 09:04:12 +09:00
Yu Watanabe ef199874ae mkosi: Update to latest (#36114) 2025-01-23 09:00:39 +09:00
Yu Watanabe af9e8ad4e8 pretty-print: fix handling of line continuation in cat_file() (#35886)
Fixes #35878.
2025-01-23 08:59:24 +09:00
Yu Watanabe 14887c14c6 network/ndisc: allow to configure route option preference (#35213)
Continuation of #35212.
Closes #35714.
2025-01-23 08:58:30 +09:00
Yu Watanabe 60ce6a3413 test-network: add test case for [IPv6RoutePrefix] Preference= 2025-01-22 20:48:31 +00:00
Yu Watanabe fe9753841f network/radv: add [IPv6RoutePrefix] Preference= setting 2025-01-22 20:48:31 +00:00
Yu Watanabe a10d6e0124 network/radv: modernize config_parse_router_preference() 2025-01-22 20:48:31 +00:00
Yu Watanabe c1b7db56e5 udevadm-test: allow to specify extra directories to load udev rules files
This adds -D/--extra-rules-dir=DIR switch for 'udevadm test' command.
When specified, udev rules files in the specified directory will be also
loaded. This may be useful for debugging udev rules by copying some udev
rules files to a temporary directory.
2025-01-22 20:46:42 +00:00
Yu Watanabe 4fd81d03e2 rpm: mark udevd for reloading when an rules file is installed/updated
Then, we can avoid using udevadm (especially udev control socket) in
processing rpm.
2025-01-22 20:44:38 +00:00
Yu Watanabe 41a1e3012e TEST-65-ANALYZE: add detailed test case for cat-config 2025-01-22 20:43:16 +00:00
Yu Watanabe 5e244e724f pretty-print: make cat_file() also highlight the trailing backslash for line continuation 2025-01-22 20:43:16 +00:00
Yu Watanabe e27fb39e07 pretty-print: fix handling of line continuation in cat_file()
Fixes #35878.
2025-01-22 20:43:16 +00:00
Yu Watanabe 42b71eb94e pretty-print: cleanups for cat_file()
- add one missing assertion,
- always logs on error,
- simplify the logic to make it easy to understand,
- add several more comments.

Preparation for later commits. No functional change.
2025-01-22 20:43:16 +00:00
Yu Watanabe 4c9da4dc91 test: add test cases for parsing SYSTEMD_WANTS=/SYSTEMD_USER_WANTS= 2025-01-22 20:41:00 +00:00
Yu Watanabe a467358b2a core/device: do not drop backslashes in SYSTEMD_WANTS=/SYSTEMD_USER_WANTS=
Let consider the following udev rules:
===
PROGRAM="/usr/bin/systemd-escape foo-bar-baz", ENV{SYSTEMD_WANTS}+="test1@$result.service"
PROGRAM="/usr/bin/systemd-escape aaa-bbb-ccc", ENV{SYSTEMD_WANTS}+="test2@$result.service"
===
Then, a device expectedly gains a property:
===
SYSTEMD_WANTS=test1@foo\x2dbar\x2dbaz.service test2@aaa\x2dbbb\x2dccc.service
===
After the event being processed by udevd, PID1 processes the device, the
property previously was parsed with extract_first_word(EXTRACT_UNQUOTE),
then the device unit gained the following dependencies:
===
Wants=test1@foox2dbarx2dbaz.service test2@aaax2dbbbx2dccc.service
===
So both '%i' and '%I' for the template services did not match with the original
data, and it was hard to use systemd-escape in PROGRAM= udev rule token.

This makes the property parsed with extract_first_word(EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE),
hence the device unit now gains the following dependencies:
===
Wants=test1@foo\x2dbar\x2dbaz.service test2@aaa\x2dbbb\x2dccc.service
===
and '%I' for the template services match with the original data.

Fixes a bug caused by ceed8f0c8b (v233).

Fixes #16735.
Replaces #16737 and #35768.
2025-01-22 20:41:00 +00:00
Yu Watanabe 9ddcccfad7 udev-dump: also show written sysfs attributes and sysctl entries
This should be useful to know what is changed by processing an event.
2025-01-23 01:50:13 +09:00
Yu Watanabe f3cbd4da12 udev-dump: voidify one function call
Fixes CID#1590377.
2025-01-23 01:50:13 +09:00
Yu Watanabe e887b3006c networkd-test: unconditionally stop previous invocation of networkd before starting new one
When networkd is already running, creating some .network files and
friends and starting networkd does not take any effect. Let's always
restart networkd when we want to start a new invocation.
2025-01-22 10:29:59 +00:00
Yu Watanabe e7e707f058 networkd-test.py: generate debugging logs of networkd 2025-01-21 09:48:17 +01:00
Yu Watanabe 25a2e4738b udevadm-control: allow to enable/disable trace logging in systemd-udevd
Should be useful for debugging udev rules.
2025-01-21 04:12:18 +09:00
Yu Watanabe 993b481ad1 udev-varlink: allow to enable/disable trace logging through varlink
This introduces io.systemd.Udev.SetTrace varlink method. With the
method, trace logging by udev worker can be dynamically controlled.
2025-01-21 04:12:18 +09:00
Yu Watanabe 695c592a03 udev-config: allow to enable trace logging through kernel command line
This adds udev.trace[=BOOL] kernel command line option to control trace
logging.
2025-01-21 04:12:18 +09:00
Yu Watanabe b5a10b2127 udev-control: move setting of log level to manager_adjust_config()
No functional change, just refactoring.
2025-01-21 04:12:18 +09:00
Yu Watanabe 5c4fa7b9b2 integritysetup: use dispatch_verb() 2025-01-21 03:42:38 +09:00
Yu Watanabe 50c0f5de8f veritysetup: use dispatch_verb() 2025-01-21 03:42:38 +09:00
Yu Watanabe a0b1ee2fca cryptsetup: use dispatch_verb() 2025-01-21 03:42:38 +09:00
Yu Watanabe 13a3b59144 cryptsetup: drop doubled space 2025-01-21 03:42:38 +09:00
Yu Watanabe 7e21105002 cryptsetup: use mangle_none() at one more place 2025-01-21 03:42:34 +09:00
Yu Watanabe a8fe005209 tree-wide: drop merely used _cleanup_ macros, and introduce several new ones (#36071) 2025-01-21 03:41:27 +09:00
Yu Watanabe d919a155c0 udev-varlink: add io.systemd.service.GetEnvironment
There is no reason to not support the method in udevd.

Follow-up for c8127075ae.
2025-01-20 00:21:45 +09:00
Yu Watanabe 901bfcd8c1 tree-wide: rely on sd_varlink_dispatch() for validating zero-argument method calls, too
Follow-ups for a7cc7038ac.
2025-01-20 00:21:31 +09:00
Yu Watanabe 848cdf56dc udev,network: drop unnecessary check for result of sd_listen_fds_with_names() 2025-01-19 23:54:41 +09:00
Yu Watanabe a75abf1ab9 udev-manager: rework initialization of device monitor
Let's determine the socket for device monitor based on its name.
2025-01-19 23:54:41 +09:00
Yu Watanabe 4a2c33847f udev-ctrl: use -EBADF for invalid file descriptor 2025-01-19 23:54:41 +09:00
Yu Watanabe ac440e47c5 udev: split out legacy control socket handling to udev-manager-ctrl.c
Mostly no functional change, except for that now the socket for device
monitor is determined by its name.
2025-01-19 23:53:45 +09:00
Yu Watanabe 2cf9635511 capability-util: rename output argument of capability_gain_cap_setpcap() 2025-01-19 14:00:16 +00:00
Yu Watanabe ed8a737e08 core: use usec_add() at one more place
Follow-up for 8af1b296cb.
Fixes CID#1590317.
2025-01-19 10:31:50 +01:00
Yu Watanabe 22d3a3dd20 Tweaks to generic "io.systemd.service" Varlink interface, and hook it up in all long-running Varlink daemons (#35914) 2025-01-19 11:54:10 +09:00
Yu Watanabe bcc057aa1d pid1,nspawn: enable usrquota on /tmp/ + /dev/shm/ (#36036)
Split out of #36010.

This simply enables the "usrquota" mount option on the two dirs if they
are backed by tmpfs.

#36010 contains a test that actually verifies that the mount option does
its thing.
2025-01-19 11:51:54 +09:00
Yu Watanabe 3fb71599d0 tree-wide: coding style fixlets done by coccinelle (#36074) 2025-01-19 11:51:12 +09:00
Yu Watanabe 99de29945f tree-wide: coding style fixlets done by coccinelle 2025-01-19 08:28:42 +09:00
Yu Watanabe 62123950c6 coccinelle: add .gitignore for cache files 2025-01-19 08:27:47 +09:00
Yu Watanabe dadd182317 TODO: fix typo
Follow-up for fb8d46cffe.
2025-01-19 04:25:22 +09:00
Yu Watanabe f0159e2b5b process-util: fix typo
Also rebreak comment.

Follow-up for 03b89cf213.
2025-01-19 04:24:08 +09:00
Yu Watanabe 4d090126ed login: fix typo
Follow-up for a6ad410ffa.
2025-01-19 04:22:16 +09:00
Yu Watanabe 7eabb5ca61 boot: introduce _cleanup_strv_free_ 2025-01-19 04:18:04 +09:00
Yu Watanabe 6ea99fd2cf boot: introduce _cleanup_file_close_ 2025-01-19 04:15:27 +09:00
Yu Watanabe 892b734c1c selinux-util: drop _cleanup_context_free_
It is used at only one place, not necessary.
2025-01-19 04:09:55 +09:00
Yu Watanabe 43e95ddbf4 capability-util: drop _cleanup_cap_free_charp_
Also moves cap_free_charpp() to test-cap-list.c, as it is used only
there.
2025-01-19 04:04:47 +09:00
Yu Watanabe fe5a1afb67 tree-wide: use _cleanup_hashmap_free_ and friends 2025-01-19 03:48:15 +09:00
Yu Watanabe b4ffb77669 udev-rules: introduce OPTIONS="dump" token
Should be useful for debugging.
2025-01-19 03:09:06 +09:00
Yu Watanabe 91d9f8f834 udev-dump: split out dump_event() from udevadm-test.c 2025-01-19 03:07:18 +09:00
Yu Watanabe f55a6fc1e3 udev: add --verbose option for 'udevadm test' and add more verbose logs (#36021)
split out of #35968.
2025-01-18 06:12:31 +09:00
Yu Watanabe c547b9e278 udev-rules: add trace logs for GOTO and parent conditions 2025-01-18 04:22:27 +09:00
Yu Watanabe 354d063fbc udev-rules: update log messages
This also adds trace logs about token result, and skipping assignment
caused by final value already assigned.
2025-01-18 04:22:23 +09:00
Yu Watanabe 68b1e1b61a udev-rules: ignore whole command result if it is too long and does not contain newline 2025-01-18 04:19:52 +09:00
Yu Watanabe a79cd8c2be udev-rules: introduce udev_replace_chars_and_log()
And logs about replacement only when trace logging is enabled.
2025-01-18 04:19:52 +09:00
Yu Watanabe 0febeccfdc udev-rules: add more trace logs for string match 2025-01-18 04:19:52 +09:00
Yu Watanabe a3ab06ab21 udev-rules: logs result of format substitution
This also drops redundant token string in log message on truncation.

No functional change, but should improve debuggability.
2025-01-18 04:19:52 +09:00
Yu Watanabe 6809bae643 udev-rules: show original token string in log_event_error() and friends
This also makes
- make many loggers refactored,
- log_event_error() and friends UdevEvent object,
- introduces log_event_trace().

No functional change, just refactoring and preparation for later
commits.
2025-01-18 04:19:52 +09:00
Yu Watanabe 8846df63fa udevadm-test: introduce -v/--verbose option to show verbose log messages
Currently this does not show any extra log messages. In later commits,
more verbose log messages will be added.
2025-01-18 04:19:52 +09:00
Yu Watanabe dd5a0f7d75 README: update requirements 2025-01-16 20:55:44 +00:00
Yu Watanabe 9c881fa867 fundamental-macro: conditionalize several gcc warning pragmas
This fixes the following error:

In file included from ../src/basic/macro.h:13,
                 from ../src/basic/env-util.h:9,
                 from ../src/nss-systemd/nss-systemd.c:7:
../src/fundamental/macro-fundamental.h:61:9: error: option ‘-Wzero-as-null-pointer-constant’ is valid for C++/ObjC++ but not for C [-Werror=pragmas]
   61 |         _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"")
      |         ^~~~~~~
../src/nss-systemd/nss-systemd.c:106:1: note: in expansion of macro ‘DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT’
  106 | DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
2025-01-17 04:35:09 +09:00
Yu Watanabe e722fe74ca random-util: fix compilation error
Fixes the following error:
```
../src/basic/random-util.c: In function "fallback_random_bytes":
../src/basic/random-util.c:45:26: error: initializer-string for array of "char" is too long [-Werror=unterminated-string-initialization]
   45 |                 .label = "systemd fallback random bytes v1",
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
```
2025-01-15 20:24:30 +01:00
Yu Watanabe b8980528c0 analyze: fix assignment of object_field
Prompted by #36000.
2025-01-16 03:34:11 +09:00
Yu Watanabe 7adf6ce3ca mkosi: disable multipathd by default
Hopefully fixes #36008.
2025-01-16 00:57:07 +09:00
Yu Watanabe 346ed75198 ptyfwd: fix wrong userdata passed to PTY forwarding
Fixes #35942.
2025-01-15 16:25:32 +01:00