summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-device
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: drop socket.h when socket-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop missing.hYu Watanabe2019-10-311-1/+1
|
* fileio: introduce read_full_virtual_file() for reading virtual files in ↵Franck Bui2019-10-251-1/+1
| | | | | | | | | | | | | | | | | | | sysfs, procfs Virtual filesystems such as sysfs or procfs use kernfs, and kernfs can work with two sorts of virtual files. One sort uses "seq_file", and the results of the first read are buffered for the second read. The other sort uses "raw" reads which always go direct to the device. In the later case, the content of the virtual file must be retrieved with a single read otherwise subsequent read might get the new value instead of finding EOF immediately. That's the reason why the usage of fread(3) is prohibited in this case as it always performs a second call to read(2) looking for EOF which is subject to the race described previously. Fixes: #13585.
* Merge pull request #13836 from systemd/assert-cleanups-and-constificationYu Watanabe2019-10-251-4/+4
|\ | | | | Assert cleanups and constification
| * sd-device: allow sd_device_get_devtype to be called with NULL arg and do not ↵Zbigniew Jędrzejewski-Szmek2019-10-241-4/+4
| | | | | | | | | | | | | | assert We shouldn't call assert() on user-specified arguments in public functions. While at it, let's return 1 if the type exists, and 0 otherwise.
* | basic/fs-util: change CHASE_OPEN flag into a separate output parameterZbigniew Jędrzejewski-Szmek2019-10-241-2/+2
|/ | | | | | | | | | | | | chase_symlinks() would return negative on error, and either a non-negative status or a non-negative fd when CHASE_OPEN was given. This made the interface quite complicated, because dependning on the flags used, we would get two different "types" of return object. Coverity was always confused by this, and flagged every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it would this that an fd is returned). This patch uses a saparate output parameter, so there is no confusion. (I think it is OK to have functions which return either an error or an fd. It's only returning *either* an fd or a non-fd that is confusing.)
* sd-device: voidify and simplify calls to ordered_hashmap_iterate()Zbigniew Jędrzejewski-Szmek2019-07-171-10/+2
| | | | Coverity CID#1402356 and CID#1402335.
* tree-wide: use PROJECT_FILE instead of __FILE__Zbigniew Jędrzejewski-Szmek2019-07-041-1/+1
| | | | This replaces the internal uses of __FILE__ with the new macro.
* sd-device: introduce dump_device_action_table()Yu Watanabe2019-06-292-0/+5
| | | | Will be used in later commits.
* Merge pull request #12870 from yuwata/tree-wide-further-path-join-cleanupsLennart Poettering2019-06-252-7/+5
|\ | | | | tree-wide: further path_join() and path_joina() cleanups
| * tree-wide: replace strjoina() with prefix_roota()Yu Watanabe2019-06-252-7/+5
| |
* | sd-device: don't accept /sys as a device pathLubomir Rintel2019-06-251-0/+4
|/ | | | | | | | | | | Because it's not a device path and (slightly) bad things happen if it gets confused with one: $ udevadm info /sys/ Assertion 'device->devpath[0] == '/'' failed at ../src/libsystemd/sd-device/sd-device.c:958, function sd_device_get_devpath(). Aborting. Aborted (core dumped)
* Merge pull request #12836 from yuwata/tree-wide-replace-strjoinLennart Poettering2019-06-222-2/+2
|\ | | | | tree-wide: replace strjoin() with path_join()
| * tree-wide: replace strjoin() with path_join()Yu Watanabe2019-06-212-2/+2
| |
* | tree-wide: drop alloca() in loopYu Watanabe2019-06-201-2/+4
|/
* sd-device: use xsprintf() where appropriateLennart Poettering2019-04-021-1/+1
|
* Remove variable only used for an assertZbigniew Jędrzejewski-Szmek2019-03-281-3/+1
| | | | | | When compiled with -DNDEBUG, we get warnings about set-but-unused variables. In general, it's not something we care about, but since removing those variables arguably makes the code nicer, let's just to it in this case.
* headers: remove unneeded includes from util.hZbigniew Jędrzejewski-Szmek2019-03-272-1/+4
| | | | | This means we need to include many more headers in various files that simply included util.h before, but it seems cleaner to do it this way.
* util: split out nulstr related stuff to nulstr-util.[ch]Lennart Poettering2019-03-141-1/+1
|
* util: split out sorting related calls to new sort-util.[ch]Lennart Poettering2019-03-131-1/+1
|
* sd-device: store parsed ACTION= and SEQNUM= udev propertiesYu Watanabe2019-03-124-62/+116
|
* sd-device: move device_action_from_string() and friends to device-private.hYu Watanabe2019-03-072-16/+18
|
* Remove now-unused refcnt.hZbigniew Jędrzejewski-Szmek2019-03-041-1/+0
|
* sd-device: split device_read_db_internal() into two partYu Watanabe2019-02-262-18/+27
| | | | The new device_read_db_internal_filename() will be used by a fuzzer.
* Merge pull request #11478 from yuwata/enumerate-match-parentLennart Poettering2019-02-182-21/+47
|\ | | | | sd-device-enumerator: support multiple parents
| * sd-device-enumerator: support multiple parentsYu Watanabe2019-01-232-21/+47
| | | | | | | | | | | | | | | | | | | | | | When sd_device_enumerator_add_match_parent() is called multiple times, then previously set parents are discarded. This adds device_enumerator_add_match_parent_incremental() to make sd-device-enumerator scan devices under all specified parents. Note that for backward compatibility, sd_device_enumerator_add_match_parent() and udev_enumerate_add_match_parent() still discard previous assignments.
* | sd-device: also store properties read from udev database to ↵Yu Watanabe2019-02-171-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sd_device::properties_db Follow-up for a3ce813697bcc1c4644e097a2f1cd0459326d6ee and 5ce41697bd3ddc19cd6e1e6834751082ca0c8b02. Before a3ce813697bcc1c4644e097a2f1cd0459326d6ee, all properties in src->properties and src->properties_db are mixed and copied to dst->properties_db by device_copy_properties(). So, it is not necessary to store data from udev database file to sd_device::properties_db before copying properties. But now, properties are not mixed. So, the read data need to be stored to also ::properties_db. Fixes #11721.
* | test: add a test case for issue #11652Yu Watanabe2019-02-061-0/+10
| |
* | sd-device: fix device_copy_properties()Yu Watanabe2019-02-061-2/+2
| | | | | | | | | | | | This fixes a bug introduced by a3ce813697bcc1c4644e097a2f1cd0459326d6ee. Fixes #11652.
* | test: add test for sd_device_monitor_filter_remove()Yu Watanabe2019-01-231-3/+33
| |
* | sd-device-monitor: use SO_DETACH_FILTER to remove BPF programYu Watanabe2019-01-231-1/+1
|/ | | | Fixes #11529.
* sd-device: do not save e.g., DEVPATH or INTERFACE properties to udev databaseYu Watanabe2019-01-223-3/+15
| | | | | | | | | | | | Previously, device_copy_properties() copies all properties to both sd_device::properties and ::properties_db. Thus, on move uevent, also tentative properties, e.g. DEVPATH or INTERFACE, are stored to ::properties_db, and saved to udev database. This makes such tentative properties be copied to only ::properties, and thus not saved to udev database. Fixes #9426.
* sd-device-monitor: fix ordering of setting buffer sizeYu Watanabe2019-01-111-8/+2
| | | | | | | | | | | | | | | | By b1c097af8df58a94cba031a347061b7cb9b62d9b (#10239), the receive buffer size for uevents was set by SO_RCVBUF at first, and fallback to use SO_RCVBUFFORCE. So, as SO_RCVBUF limits to the buffer size net.core.rmem_max, which is usually much smaller than 128MB udevd requests, uevents buffer size was not sufficient. This fixes the ordering of the request: SO_RCVBUFFORCE first, and fallback to SO_RCVBUF. Then, udevd's uevent buffer size can be set to 128MB. This also revert 903893237a2105b05671fe87b8f5d5e7417040d2. Fixes #11314 and #10754.
* sd-device: modernize code a bitZbigniew Jędrzejewski-Szmek2019-01-081-53/+18
| | | | | | | | | | Empty line between setting the output parameter and return is removed. I like to think about both steps as part of returning from the function, and there's no need to separate them. Similarly, if we need to unset a pointer after successfully passing ownership, use TAKE_PTR and do it immediately after the ownership change, without an empty line inbetween.
* test: add test for sending/receiving an invalid deviceYu Watanabe2019-01-021-27/+54
|
* Revert "sd-device: ignore bind/unbind events for now"Yu Watanabe2019-01-021-9/+0
| | | | | | This reverts commit 56c886dc7ed5b2bb0882ba85136f4070545bfc1b. Fixes #11277 and #11299.
* sd-device: fix segfault when error occurs in device_new_from_{nulstr,strv}()Yu Watanabe2018-12-301-0/+3
| | | | | | | | | | As devpath may not be set yet. When debug logging is enabled, log_device_*() calls sd_device_get_sysname(). So, we should not assume that devpath is always set. Fixes #11258.
* sd-device: ignore bind/unbind events for nowDmitry Torokhov2018-12-211-0/+9
| | | | | Until systemd/udev are ready for the new events and do not flush entire device state on each new event received, we should ignore them.
* Merge pull request #11144 from keszybz/dissect-image-fixLennart Poettering2018-12-174-235/+64
|\ | | | | Fix for dissect-image use in nspawn
| * sd-device: remove holes in struct sd_deviceZbigniew Jędrzejewski-Szmek2018-12-171-20/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Normally, we don't care too much about what pahole reports. But this structure could potentially be allocated for every device on the system, i.e. in a large number of copies. 5 vs 7 cache lines is nice. /* size: 400, cachelines: 7, members: 53 */ /* sum members: 330, holes: 12, sum holes: 70 */ /* last cacheline: 16 bytes */ /* size: 320, cachelines: 5, members: 53 */ /* bit holes: 1, sum bit holes: 6 bits */ /* bit_padding: 5 bits */
| * sd-device: pass timestamp internally as usec_t not char*Zbigniew Jędrzejewski-Szmek2018-12-163-27/+28
| |
| * sd-device: reduce the number of implementations of device_read_db() we keep ↵Zbigniew Jędrzejewski-Szmek2018-12-164-181/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | around We had two very similar functions: device_read_db_aux and device_read_db, and a number of wrappers for them: device_read_db_aux ← device_read_db (in sd-device.c) ← all functions in sd-device.c, including sd_device_is_initialized ← device_read_db_force ← event_execute_rules_on_remove (in udev-event.c) device_read_db (in device-private.c) ← functions in device_private.c (but not device_read_db_force): device_get_devnode_{mode,uid,gid} device_get_devlink_priority device_get_watch_handle device_clone_with_db ← called from udevadm, udev-{node,event,watch}.c Before 7141e4f62c3f220872df3114c42d9e4b9525e43e (sd-device: don't retry loading uevent/db files more than once), the two implementations were the same. In that commit, device_read_db_aux was changed. Those changes were reverted in the parent commit, so the two implementations are now again the same except for superficial differences. This commit removes device_read_db (in sd-device.c), and renames device_read_db_aux to device_read_db_internal and makes everyone use this one implementation. There should be no functional change.
| * sd-device: attempt to read db again if it wasn't foundZbigniew Jędrzejewski-Szmek2018-12-161-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This mostly reverts "sd-device: don't retry loading uevent/db files more than once", 7141e4f62c3f220872df3114c42d9e4b9525e43e. We will retry if we couldn't access the file, but not if parsing failed. Not re-reading the database at all just doesn't seem like a good idea. We have two implementations of device_read_db, and one does that, and the other retries to read the db. Re-reading seems more useful, since we can create the object and then access properties as some later time when we know that the device has been initialized and we can get useful results. Otherwise, we force the user to destroy this object and create a new one. This changes device_read_uevent_file() and device_read_db_aux(). See next commit for description of where those functions are used.
* | sd-device: do not change buffer size if the socket is already boundYu Watanabe2018-12-141-0/+6
| | | | | | | | | | | | | | | | From the results of CIs in #11076, changing buffer size may cause issue #10754. So, let's prohibit to change the size if it is already bound. This also reverts commit 986ab0d2dc161dfa026e8fc7a609f9efb8cb4397.
* | sd-device: do not modify socket option(s) if socket is passed by PID1Yu Watanabe2018-12-141-9/+9
| | | | | | | | | | | | If the socket fd is passed by PID1, then it is created by .socket unit and we have already set sufficient option(s) for the socket. So, let's not touch the passed socket.
* | Revert "sd-device: do not call device_monitor_enable_receiving() for passed ↵Yu Watanabe2018-12-141-5/+3
|/ | | | | | | | | | fd from pid1" This reverts commit 916707cca56ac73c81d10c41b6d7f0800663fc29. As the CI results on #11076, #10754 is not fixed by the commit, but by 986ab0d2dc161dfa026e8fc7a609f9efb8cb4397. So, let's revert the commit.
* util: drop missing.h from socket-util.hYu Watanabe2018-12-061-0/+1
|
* util-lib: split out all temporary file related calls into tmpfiles-util.cLennart Poettering2018-12-021-0/+1
| | | | | | | | This splits out a bunch of functions from fileio.c that have to do with temporary files. Simply to make the header files a bit shorter, and to group things more nicely. No code changes, just some rearranging of source files.
* Merge pull request #10996 from poettering/oci-prepZbigniew Jędrzejewski-Szmek2018-11-301-7/+8
|\ | | | | Preparation for the nspawn-OCI work
| * tree-wide: port various parts of the code to use parse_dev()Lennart Poettering2018-11-291-7/+8
| |