Commit Graph
3645 Commits
Author SHA1 Message Date
Yu Watanabe d82827a107 sd-device: rename function arguments for storing results 2022-04-18 04:34:14 +09:00
Yu Watanabe c77c1cc201 sd-device: use correct type and parser for device node uid and gid 2022-04-18 04:34:14 +09:00
Yu Watanabe d37c69c1bf sd-device: shorten code a bit 2022-04-18 04:34:14 +09:00
Yu Watanabe ce1d08ba94 sd-device: use path_extract_filename() at one more place
This also does several cleanups.
2022-04-18 04:34:14 +09:00
Yu Watanabe 60e50fb20d sd-device: reset sysname and sysnum on renaming 2022-04-18 04:34:14 +09:00
Yu Watanabe f5a75f2027 sd-device: reduce indentation 2022-04-18 04:34:14 +09:00
Yu Watanabe ff58f2ae2a sd-device: verify new syspath on renaming 2022-04-18 04:34:14 +09:00
Yu Watanabe bd4297e761 udevadm: info: also show parent devices by --tree 2022-04-17 21:27:33 +02:00
Yu Watanabe b9d8209065 test: add tests for sd_device_get_sysnum() 2022-04-16 00:52:24 +09:00
Yu Watanabe 5fa9d220c2 sd-device: shorten code a bit 2022-04-16 00:52:24 +09:00
Yu Watanabe c58e0ce677 sd-device: use path_extract_filename() at one more place 2022-04-16 00:52:16 +09:00
Yu Watanabe cc41c084cd sd-netlink: use correct type of iterator 2022-04-15 17:37:52 +09:00
Lennart Poettering 4bcf5c11c8 Merge pull request #23011 from mrc0mmand/TEST-64-md
test: add MD-related tests to TEST-64
2022-04-13 22:26:50 +02:00
Yu Watanabe bd1f75d5fb Merge pull request #23070 from poettering/devnum-split
basic: some devnum handling tweaks and refactorings
2022-04-14 03:45:39 +09:00
Yu Watanabe 03b894fc09 sd-device: skip diskseq verification when ID_IGNORE_DISKSEQ property is set
Some drivers do not announce the diskseq change.
E.g. for md devices, the kernel increments the diskseq *after*
emitting a 'change' uevent when backing block devices are added to
a md device, and udevd does not receive no uevent which contains
the new diskseq.
2022-04-14 00:10:28 +09:00
Lennart Poettering 7176f06c9e basic: split out dev_t related calls into new devno-util.[ch]
No actual code changes, just splitting out of some dev_t handling
related calls from stat-util.[ch], they are quite a number already, and
deserve their own module now I think.

Also, try to settle on the name "devnum" as the name for the concept,
instead of "devno" or "dev" or "devid". "devnum" is the name exported in
udev APIs, hence probably best to stick to that. (this just renames a
few symbols to "devum", local variables are left untouched, to make the
patch not too invasive)

No actual code changes.
2022-04-13 16:26:31 +02:00
Lennart Poettering 00dfbf35fd sd-device: include parent devices in enumeration 2022-04-13 14:41:05 +02:00
Lennart Poettering 0b859c9773 sd-device: properly support some corner case syspath 2022-04-13 14:41:05 +02:00
Lennart Poettering be247835c7 sd-device: add some comments 2022-04-13 14:41:05 +02:00
Lennart Poettering 29a5428f1c sd-device: filter regular files when enumerating
Currently if enumerating with debug logging you'll likely see something
like this:

sd-device: the syspath "/sys/class/devcoredump/disabled" is not a directory.
sd-device: the syspath "/sys/class/firmware/timeout" is not a directory.
sd-device: the syspath "/sys/class/zram-control/hot_remove" is not a directory.
sd-device: the syspath "/sys/class/zram-control/hot_add" is not a directory.
sd-device: the syspath "/sys/class/drm/version" is not a directory.

This is because these sysfs classes place regular files in these
directories, which we so far didn't expect.

Let's filter them early, and only bother with enumerated inodes if they
actually are dirs or symlinks, i.e. can be kobject dirs. Regular file
definitely never are kobject dirs...
2022-04-13 14:41:04 +02:00
Lennart Poettering e7c7d79d52 sd-device: split out checking of matches from enumerator_scan_dir_and_add_devices()
No change in behaviour, just some splitting out of code.
2022-04-13 14:41:04 +02:00
Lennart Poettering 5cf0ee31ec sd-device: generate e better error code when trying to allocate sd_device for non-dir
Currently, for sysfs paths outside of /sys/devices/ we do better
checking if something is a suitable path: we check if it's actually a
directory, and if not return ENODEV.

Let's make the codepath for nodes *inside* of /sys/device/ similar:
let's also return ENODEV if the path supplied is not a directory.

Previously, we'd return ENOTDIR in that case, which is quite confusing I
think.
2022-04-13 14:41:03 +02:00
Lennart Poettering a7910612a5 sd-device: don't accept non-sysfs paths
There are some file systems mounted below /sys/ that are not actually
sysfs, i.e. are not arranged in a sysfs/kobject style. Let's refuse
those early. (Example, /sys/fs/cgroup/ and similar.)

(Also, let's add an env var for this, so that it can be turned off for
test cases.)
2022-04-13 14:40:13 +02:00
Lennart Poettering 1793bb6112 sd-device: use chase_symlinks() O_PATH fd
chase_symlinks() can return its last O_PATH fd to us. Let's use that and
make the access() check a bit tighter by going via faccessat() on the
O_PATH fd.

This doesn't really change too much, but is nice in context of the next
commit, which uses the O_PATH fd in one other way.
2022-04-13 14:40:09 +02:00
Yu Watanabe fbae50904f sd-event: make inotify event work after the process is forked 2022-04-13 01:00:08 +09:00
Yu Watanabe 86587c93b0 sd-event: do not kill a child process from another child 2022-04-13 01:00:08 +09:00
Yu Watanabe 01e6af7374 sd-event: do not update signal fd after PID is changed
Otherwise, child event source will not work after the process is forked
and the event source is unref()ed on the child process.
2022-04-13 01:00:08 +09:00
Yu Watanabe 54988a27b9 sd-event: set pid to event source after all setup processes finished
Otherwise, the assertion in source_disconnect() may be triggered,
2022-04-13 01:00:08 +09:00
Yu Watanabe 91c700713f sd-event: rebreak comments 2022-04-13 01:00:08 +09:00
Lennart Poettering 9d41c62f6e sd-device: validate devnum parameters in device_set_devnum() 2022-04-11 16:27:40 +02:00
Lennart Poettering 4d960d0bdb sd-device: make device_set_syspath() more defensive
Simplify generated sysfs paths, since we might get data passed that
includes extra // in the middle.

Also, let's not assume /sys/ prefix without verification.
2022-04-11 16:26:58 +02:00
Lennart Poettering 09c24f76dc sd-device: simplify device_enumerator_scan_devices_and_subsystems() a bit
We can use enumerator_scan_devices_all() to shorten the code, and drop
some of the error handling complexities.
2022-04-11 16:25:48 +02:00
Yu Watanabe 08405125c3 sd-device: shorten code a bit 2022-04-11 19:56:38 +09:00
Yu Watanabe 9a81972b3b sd-device: minor may be NULL 2022-04-11 19:56:38 +09:00
Yu Watanabe a46f9cd049 sd-device: validate input parameter after creating sd-device object 2022-04-11 19:56:03 +09:00
Yu Watanabe bab34bc12e Merge pull request #22980 from keszybz/test-help-and-version-output
Test --help and --version output in more cases
2022-04-06 13:42:12 +09:00
Zbigniew Jędrzejewski-Szmek 8f04a1ca2b meson: also allow setting GIT_VERSION via templates
GIT_VERSION is not available as a config.h variable, because it's rendered
into version.h during builds. Let's rework jinja2 rendering to also
parse version.h. No functional change, the new variable is so far unused.

I guess this will make partial rebuilds a bit slower, but it's useful
to be able to use the full version string.
2022-04-05 22:18:31 +02:00
Yu Watanabe c7749367e3 test-sd-device: ignore several errors when running on non-host network namespace
Fixes https://github.com/systemd/systemd/commit/93e04eb43bed6cd1cea344f8fb1002b62155fae2#commitcomment-70387367.
2022-04-05 14:33:19 +09:00
Yu Watanabe b1d723228e test-sd-device: allow several devices removed during running test
To make the test stabler.
2022-04-05 14:29:52 +09:00
Yu Watanabe 901fa9a4c9 test-sd-device: device ID requires subsystem 2022-04-05 14:29:49 +09:00
Yu Watanabe 04d1fbd564 test-sd-device: log earlier which device is handled
To make debugging the test easier.
2022-04-05 14:29:41 +09:00
Lennart Poettering 1ce0d04059 sd-device: actually read diskseq if told so
sd_device_get_diskseq() actually called device_read_uevent_file() but
that function didn't actually parse DISKSEQ= so far. Fix that.
2022-04-04 18:21:41 +02:00
Lennart Poettering d4df6ce215 sd-device: rename return parameter of sd_device_get_devpath() to ret 2022-04-04 18:21:41 +02:00
Franck Bui 4bb37be07b journald: make sure journal_file_open() doesn't leave a corrupted file around after failing
This can be problematic especially when there's no more free disk
space. Consider the following:.

When disk space becomes sparse, writting to the system journal can lead to
error. In this case journald attempts to make room by rotating the journals,
which consists in archiving online journals and opening new ones.

However opening new files is likely to fail too and in this case
journal_file_open() leaves half initialized file around but in online
state. Then the error is propagated and journald switches into volatile mode.

Next time a new message is received by journald, it tries to open the
persistent system journal file to switch automatically back to persistent
mode.

When opening the system journal, journal_file_open(), called by
managed_journal_file_open_reliably(), finds the persistent system journal left
previously and assumes that it was uncleanly closed and considers it as
corrupted. The error is reported to managed_journal_file_open_reliably(), which
backs the file up and attempts to create a new system file, which fails and
leaves a corrupted system file again.

Since this is done for each message received by journald, /var/log/message can
be filled with backup files pretty quickly.

To prevent this, the patch makes sure to delete the newly created file in case
of error.
2022-04-04 17:51:10 +02:00
Yu Watanabe 798931160e tree-wide: add a space after if, switch, for, and while 2022-04-01 22:48:42 +09:00
Yu Watanabe 9534d6c9ea test: add test for sd_device_open() 2022-04-01 15:20:48 +09:00
Yu Watanabe f9a726abef sd-device: introduce sd_device_open()
We usually open() device node obtained by sd_device_get_devname().
However, the device node corresponds to the sd-device object may be
already removed, and another device node with the same path may be
created, hence an unexpected device may be opened.

The sd_device_open() opens device node, and checks the devnum and
diskseq of opened devnum, to avoid the above possibility.

Prompted by https://github.com/systemd/systemd/issues/22906#issuecomment-1082736443.
2022-04-01 15:13:18 +09:00
Yu Watanabe 209294ad24 test: add more tests for sd_device_new_from_xxx() 2022-04-01 15:13:14 +09:00
Yu Watanabe e418f9658b sd-device: introduce sd_device_new_from_devname()
and sd_device_new_from_path() which takes devname or syspath.
2022-04-01 15:03:33 +09:00
Yu Watanabe df88f02bb1 sd-device: do not ignore critical errors in device_new_from_child() 2022-03-31 07:25:24 +09:00