summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-device
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: convert more cases do DEVNUM_FORMAT_STR()/DEVNUM_FORMAT_VAL()Lennart Poettering2023-04-211-3/+3
| | | | | | Let's use our nice macros a bit more. (Not comprehensive)
* string-util: add strstrafter()Lennart Poettering2023-04-141-2/+1
| | | | | | | | | strstrafter() is like strstr() but returns a pointer to the first character *after* the found substring, not on the substring itself. Quite often this is what we actually want. Inspired by #27267 I think it makes sense to add a helper for this, to avoid the potentially fragile manual pointer increment afterwards.
* udev,sd-device: use CMSG_FIND_DATA() moreLennart Poettering2023-04-131-4/+2
|
* sd-device: absolute devlink must start with /dev/Yu Watanabe2023-04-121-27/+37
| | | | | | | | This also makes device node path is handled with the same logic. Addresses https://github.com/systemd/systemd/pull/27169#discussion_r1162739511. Follow-up for 2c5f119c3cc78bd7da0c7c56b57eca43bac464c1.
* sd-device: manage cached sysattr values with path_hash_opsYu Watanabe2023-04-081-1/+1
| | | | As here keys are relative paths to sysattrs.
* sd-device,udev: tag must be a valid filenameYu Watanabe2023-04-082-1/+3
| | | | | | | | | | | All tags are managed under /run/udev/tags, and the directories there are named with tags. Hence, each tag must be a valid filename. This also makes all validity check moved to sd-device side, and makes failure caused by setting invalid tags non-critical. With this change, an empty string cannot be assigned to TAG=, hence the test cases are adjusted.
* sd-device,udev: refuse invalid devlink and store in normalized formYu Watanabe2023-04-082-7/+31
| | | | | | | | This is especially for the case that the path contains "..". Prompted by https://github.com/systemd/systemd/pull/27164#issuecomment-1498863858. This also makes SYMLINK= gracefully handle paths prefixed with "/dev/", and manage devlink paths with path_hash_ops.
* devnum-util: add new devnum_is_zero() helperLennart Poettering2023-03-291-1/+1
|
* chase-symlinks: Rename chase_symlinks() to chase()Daan De Meyer2023-03-241-3/+3
| | | | | | | | | Chasing symlinks is a core function that's used in a lot of places so it deservers a less verbose names so let's rename it to chase() and chaseat(). We also slightly change the pattern used for the chaseat() helpers so we get chase_and_openat() and similar.
* log: Add key/value support to the log contextDaan De Meyer2023-03-211-1/+1
| | | | | | | | Now that we have reference counting, it's useful to be able to push single key values onto the log context separately, so that we don't have to allocate new storage to join the separate string together into a single field which means we won't be able to reuse a context containing the same field.
* log: Avoid pushing the same fields more than once on the log contextDaan De Meyer2023-03-211-1/+1
| | | | | | | | | | | | | Let's try to optimize against pushing the same fields multiple times onto the log context. To achieve this we make the log context reference counted and return an existing context object if it's using the same fields. A consequence of this is that we have to make sure attaching/detaching is coupled to the lifetime of the context object, so we make the attach and detach functions private for now. If we need independent attach/detach in the future, we can make that work with some extra complexity but since we don't need it yet, let's not support it for now.
* tree-wide: simplify x ? x : y to x ?: y where applicableFrantisek Sumsal2023-03-181-1/+1
|
* tree-wide: use unlink_and_freep() moreoverLennart Poettering2023-02-231-2/+3
|
* Merge pull request #23309 from DaanDeMeyer/log-contextLuca Boccassi2023-01-203-0/+82
|\ | | | | basic: Add log context
| * device-monitor: Add extra fields to the log context before callbackDaan De Meyer2023-01-083-0/+82
| |
* | udev: support '-=' operator for SYMLINKFranck Bui2023-01-172-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For some (corner) cases, it might be desirable to disable the generation of some persistent storage symlinks that 60-persistent-storage.rules creates. For example on big setups with a high number of partitions which uses the same label name, this can result in a noticeable slow-down in the (re)start of the udevd as there are many contenders for the symlink /dev/disk/by-partlabel. However it's currently pretty hard to overwrite just some specific part of the rule file. Indeed one need to copy and modify the whole rule file in /etc but will lost any upcoming updates/fixes that the distro might release in the future. With this simple patch, one can now disable the generation of the "by-partlabel" symlinks (for example) with the following single rule: $ cat /etc/udev/rules.d/99-no-by-partlabel.rules ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK-="disk/by-partlabel/$env{ID_PART_ENTRY_NAME}" Closes #24607.
* | sd-device: introduce device_get_property_int()Yu Watanabe2023-01-102-0/+21
| |
* | udev: move device_rename() from device-private.cYu Watanabe2023-01-092-46/+0
| | | | | | | | The function is used only by udevd.
* | sd-device: do not directly access entry in sd-device objectYu Watanabe2023-01-091-5/+9
| | | | | | | | No functional change, just refactoring.
* | sd-device: make device_set_syspath() clear sysname and sysnumYu Watanabe2023-01-092-4/+4
|/ | | | | | Otherwise, when a new syspath is assigned to the sd-device object, sd_device_get_sysname() or _sysnum() will provide an outdated device name or number.
* tree-wide: use -EBADF moreYu Watanabe2022-12-211-2/+2
|
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-193-4/+4
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* test: name_assign_type sysattr never exists for enumerated devicesYu Watanabe2022-12-121-7/+8
| | | | As we filtered out network devices in the test.
* sd-device: fix double-freeYu Watanabe2022-12-121-2/+7
| | | | | | | | | | If an attribute is read but the value is not used (i.e. ret_value is NULL), then sd_device_get_sysattr_value() mistakenly frees the read data even though it is cached internally. Fixes a bug introduced by acfc2a1d15560084e077ffb3be472cd117e9020a. Fixes #25702.
* nulstr-util: Declare NULSTR_FOREACH() iterator inlineDaan De Meyer2022-11-112-2/+1
|
* basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-082-2/+0
| | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* Merge pull request #25137 from yuwata/sd-device-drop-device-copy-propertiesZbigniew Jędrzejewski-Szmek2022-10-273-39/+1
|\ | | | | sd-device: drop unused device_copy_properties()
| * sd-device: make device_shallow_clone() staticYu Watanabe2022-10-262-2/+1
| |
| * sd-device: drop unused device_copy_properties()Yu Watanabe2022-10-263-37/+0
| |
* | test-sd-device: check if /run/udev/ existsLuca Boccassi2022-10-251-1/+1
|/ | | | | | | When running the tests in a chroot /sys/ might be writable, but it doesn't mean udev will be running Assertion 'sd_event_add_inotify(event, NULL, "/run/udev" , IN_DELETE, on_inotify, NULL) >= 0' failed at src/libsystemd/sd-device/test-sd-device.c:352, function test_sd_device_enumerator_filter_subsystem(). Aborting.
* sd-device-monitor: dynamically allocate receive bufferYu Watanabe2022-10-171-29/+51
| | | | | | | If udevd broadcasts a processed device with huge amount of properties, then clients cannot receive the device. Fixes #24987.
* Merge pull request #24812 from yuwata/udev-drop-netlinkYu Watanabe2022-09-272-0/+20
|\ | | | | udev: drop workaround for slow read of phys_port_name sysattr
| * sd-device: introduce device_get_sysattr_int()Yu Watanabe2022-09-252-0/+20
| |
* | Merge pull request #24757 from yuwata/sd-device-get-child-firstLennart Poettering2022-09-264-1/+196
|\ \ | |/ |/| sd-device: introduce sd_device_get_child_first() and _next()
| * test-sd-device: add tests for sd_device_get_child_first() and _next()Yu Watanabe2022-09-231-0/+51
| |
| * sd-device: introduce sd_device_get_child_first() and _next()Yu Watanabe2022-09-233-0/+144
| | | | | | | | | | | | | | These functions provide a high-level interface for enumerating child devices. Suggested at https://github.com/systemd/systemd/pull/24731#discussion_r973987065.
| * sd-device: refuse to get a parent device by sd_device_new_child()Yu Watanabe2022-09-231-1/+1
| |
* | tree-wide: use the term "initrd" at most places we so far used "initramfs"Lennart Poettering2022-09-231-4/+2
|/ | | | | | | | | | | | In most cases we refernced the concept as "initrd". Let's convert most remaining uses of "initramfs" to "initrd" too, to stay internally consistent. This leaves "initramfs" only where it's relevant to explain historical concepts or where "initramfs" is part of the API (i.e. in /run/initramfs). Follow-up for: b66a6e1a5838b874b789820c090dd6850cf10513
* sd-device: use fd_reopen() at one more placeYu Watanabe2022-09-201-2/+2
| | | | It provides recognizable error if /proc is not mounted.
* sd-device: use device_opendir()Yu Watanabe2022-09-191-17/+3
|
* sd-device: introduce device_opendir()Yu Watanabe2022-09-192-0/+33
|
* sd-device: re-implement device_sysattrs_read_all() without recursionYu Watanabe2022-09-191-4/+23
|
* sd-device: use faccessat()Yu Watanabe2022-09-191-15/+16
| | | | No functional changes, just refactoring.
* sd-device: use fstatat()Yu Watanabe2022-09-191-6/+2
| | | | No functional changes, just refactoring.
* sd-device: use path_hash_ops to store sysattrsYu Watanabe2022-09-191-1/+4
| | | | | | As the stored values are actually path. Just for safety. This also drops unnecessary duplication of path.
* sd-device: refuse block device without subsystemYu Watanabe2022-09-181-2/+2
| | | | | Previously, even if sd_device_get_subsystem() returns -ENOENT for block device, we accepted that. This makes the check slightly stricter.
* uid-range: tie up number and array of uid range entriesYu Watanabe2022-09-161-7/+4
| | | | | | This renames UidRange -> UidRangeEntry, and reintroduces UidRange which contains the array of UidRangeEntry and its size. No fucntional changes, just refactoring.
* sd-device-monitor: do not trigger assertion when uid_map is not emptyYu Watanabe2022-09-161-0/+1
| | | | Follow-up for c0aa23cf1ed4b3cbbcaf8b19d47e6e29dc28c9a0.
* tree-wide: use ASSERT_PTR moreDavid Tardon2022-09-131-3/+1
|
* sd-device: move device_new_from_watch_handle_at() to udev-watch.cYu Watanabe2022-09-124-147/+0
| | | | And drop unused watch handle related functions.