summaryrefslogtreecommitdiff
path: root/src/shared/udev-util.c
Commit message (Collapse)AuthorAgeFilesLines
* udev-rules: fix matching of token types that support alternative patternsDmitry V. Levin2023-03-191-5/+14
| | | | | | | | | | | | | | | For those token types that support matching of alternative patterns, their token values are interpreted as nulstr, so make sure the parser does the right thing and makes these token values terminated by two subsequent NULs so they could be safely interpreted as nulstr. Before this fix, the following rules would result to "echo foo" invocation: ENV{foo}=", RUN" ENV{foo}=="bar", RUN+="echo foo" because the value of `ENV{foo}` is treated as nulstr, and it used to match against alternative patterns, in this case `bar`, `, RUN`, and `="echo foo`. Fixes: 25de7aa7b90c ("udev: modernize udev-rules.c")
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-1/+1
| | | | | | | | | | | | | | | | -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.
* ac-power: check battery existence and statusYu Watanabe2022-11-131-14/+44
| | | | | | | | If a battery is not present or its status is not discharging, then the battery should not be used as a power source. Let's count batteries currently discharging. Fixes #25316.
* tree-wide: set description for device managerYu Watanabe2022-10-191-0/+9
|
* tree-wide: use ASSERT_PTR moreDavid Tardon2022-09-131-2/+1
|
* udev-util: make device_wait_for_initialization() take relative timeoutYu Watanabe2022-08-311-12/+10
| | | | Also make the timer event source floating.
* udev-util: replace device_new_from_dev_path() with sd_device_new_from_devname()Yu Watanabe2022-08-311-29/+6
|
* udev-util: minor cleanups for on_ac_power()Yu Watanabe2022-08-281-7/+7
| | | | Follow-ups for #24420.
* on-ac-power: ignore devices with scope==DeviceZbigniew Jędrzejewski-Szmek2022-08-231-0/+8
| | | | | | | | | | | | | | | | | | | | | | | My mouse is reported as: P: /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.4/1-4.4:1.2/0003:046D:C52B.001E/0003:046D:4051.001F/power_supply/hidpp_battery_4 M: hidpp_battery_4 R: 4 U: power_supply E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.4/1-4.4:1.2/0003:046D:C52B.001E/0003:046D:4051.001F/power_supply/hidpp_battery_4 E: SUBSYSTEM=power_supply E: POWER_SUPPLY_NAME=hidpp_battery_4 E: POWER_SUPPLY_TYPE=Battery E: POWER_SUPPLY_ONLINE=1 E: POWER_SUPPLY_STATUS=Discharging E: POWER_SUPPLY_SCOPE=Device E: POWER_SUPPLY_MODEL_NAME=Wireless Mouse M510 E: POWER_SUPPLY_MANUFACTURER=Logitech E: POWER_SUPPLY_SERIAL_NUMBER=4051-bc-cd-d2-5b E: POWER_SUPPLY_CAPACITY_LEVEL=Normal See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=25a0bc2dfc2ea732f40af2dae52426ead66ae76e Effectively, "System" and "Unkown" are passed through, "Device" is rejected.
* on-ac-power: rework logicZbigniew Jędrzejewski-Szmek2022-08-231-35/+25
| | | | | | | | | | | | | | | | | | | | | | | | History of the function: 96788d2aa4f4b0b49874b4a240ce47d9e8485d1b assume system is running on AC power when no battery found 795e86b4f1e8a1fd440f8c817621779c6aedbdb5 ignore USB-C ports in power source mode when detecting system is running on AC power c19a51bec40ae5e5073464e72411e7920d05d683 invert ac_power() source type check 6d89003462484c8656b698e07b9cf0a337e3818e assume ac when /sys/class/power_supply is missing 240dbaa44f8e5ad51775c776fc3ce9cd2f19f037 add ConditionACPower= Interestingly, the return condition 'on_ac_power == found_online || !found_offline' was there from the very beginning, and even Yu's latest change doesn't change this, but only extends it to 'on_ac_power == found_online || !found_offline || !found_battery'. This means that any system with no AC power supply will be unconditionally classified as on_ac_power. Let's change the logic: if we have an online AC supply, answer is "yes". If no supplies, but we have a battery, answer is "no". Otherwise, assume "yes", based on the assumption that presense of a battery would at least be always reported, even if an AC power supply might not be. Fixes #24407. It also shouldn't impact previous fixes: assume ac when /sys/class/power_supply is missing, ignore USB-C ports in power source mode, assume system is running on AC power when no battery found.
* shared/udev-util: say "ignoring device", not "ignoring"Zbigniew Jędrzejewski-Szmek2022-08-231-6/+6
| | | | The short form sounds like we're ignoring the error.
* udev-util: assume system is running on AC power when no battery foundYu Watanabe2022-08-061-2/+5
| | | | Fixes #24214.
* udev-util: align string tableYu Watanabe2022-08-061-1/+1
|
* tree-wide: link to docs.kernel.org for kernel documentationnl67202022-07-041-2/+2
| | | | | | | https://www.kernel.org/ links to https://docs.kernel.org/ for the documentation. See https://git.kernel.org/pub/scm/docs/kernel/website.git/commit/?id=ebc1c372850f249dd143c6d942e66c88ec610520 These URLs are shorter and nicer looking.
* udev: make newer event also blocked by DEVPATH_OLDYu Watanabe2022-05-041-0/+13
| | | | | | | | | | | | | | | | | | Previously, a device has DEVPATH_OLD is blocked by a previous event whose devpath is equivalent to the DEVPATH_OLD. This extends the condtion. 1. an event has DEVPATH_OLD is blocked by a previous event whose devpath is a parent of, child of, or equivalent to the DEVPATH_OLD. 2. an event is blocked by a previous event whose DEVPATH_OLD is a parent of, child of, or equivalent to the devpath of the new event. I am not sure such check is really necessary. But, the cost of the check is expected to be extremely small, as device renaming does not occur so frequently. Hence, it should not introduce any significant performance regression.
* udev-util: add parentheses to make coverity silentYu Watanabe2022-02-181-1/+1
| | | | Fixes CID#1474365.
* udev-util: introduce udev_available() helper functionYu Watanabe2022-02-171-0/+15
|
* sd128: export sd_id128_to_uuid_string()Lennart Poettering2022-02-141-1/+1
| | | | | | | | | We expose various other forms of UUID helpers already, i.e. SD_ID128_UUID_FORMAT_STR and SD_ID128_MAKE_UUID_STR(), and we parse UUIDs, hence add a high-level helper for formatting UUIDs too. This doesn't add any new code, it just moves some helpers id128-util.[ch] → sd-id128.[ch], to make them public.
* udev-util: add event UUID to debugging logsYu Watanabe2022-01-191-2/+7
|
* udev-util: ignore USB-C ports in power source mode when detecting system is ↵Yu Watanabe2022-01-061-0/+72
| | | | | | running on AC power Fixes #21988.
* udev-util: re-implement on_ac_power() with sd-deviceYu Watanabe2022-01-061-34/+39
|
* util: move on_ac_power() from util.c -> udev-util.cYu Watanabe2022-01-061-0/+62
|
* tree-wide: make cunescape*() functions return ssize_tZbigniew Jędrzejewski-Szmek2021-07-091-6/+7
| | | | | Strictly speaking, we are returning the size of a memory chunk of arbitrary size, so ssize_t is more appropriate than int.
* udev-util: introduce udev_replace_ifname()Yu Watanabe2021-06-231-0/+17
|
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-051-1/+1
|
* tree-wide: use sd_device_new_from_stat_rdev() whereever appropriateLennart Poettering2021-02-221-1/+1
|
* sd-device: ignore error in device_cache_sysattr_value() and propagate ↵Yu Watanabe2021-02-211-4/+5
| | | | | | | | | | | | | | original error code There are three calls of device_cache_sysattr_value(). Two of them are just caching the value. Hence, let's ignore its failure, and propagate original error code. One exception is the last call in sd_device_get_sysattr_value(). Unfortunately, it returns `const char *` instead of `char *`. So, sd_device object must have the reference of the returned value. Hence, error in updating the cache by device_cache_sysattr_value() is critical, and we need to propagate the error in that case.
* sd-device: add sd_device_get_action() + sd_device_get_seqnum() + ↵Lennart Poettering2021-02-181-8/+12
| | | | | | | | | | | | | | | | sd_device_new_from_stat_rdev() To make sd-device properly usable for all programs we need to provide an API for the "action" field of an event, it's one of the most relevant ones, and it was so far missing. This also adds sd_device_get_seqnum(), which isn't that interesting, except for generating pretty debug output, which we use it ourselves for. This also makes device_new_from_stat_rdev() public, as it is truly useful, as we can see in our own uses of it, and I think is fairly generic to show up in the public APIs.
* udev: stop to use LOG_REALM_UDEVYu Watanabe2021-01-251-1/+1
| | | | | | | | Before this commit, udevd is built with LOG_REALM=LOG_REALM_UDEV. However, log level specified by e.g. environment variable or kernel command line option are also passed to LOG_REALM_SYSTEMD. So, the maximum log level for the two realms are always equivalent, and it is not necessary to specify the build option. Hence drop it.
* udev: introduce udev_queue_is_empty() and udev_queue_init()Yu Watanabe2020-12-161-0/+20
|
* udev: move util_resolve_subsys_kernel() to udev-util.cYu Watanabe2020-12-161-0/+65
|
* udev: move util_replace_chars() to udev-util.cYu Watanabe2020-12-161-0/+45
|
* udev: move util_replace_whitespace() to udev-util.cYu Watanabe2020-12-161-0/+43
|
* udev: introduce log_device_uevent() helper functionYu Watanabe2020-12-101-0/+14
| | | | And this drops duplicated check for seqnum and device action.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Merge pull request #17399 from afq984/udev-escaped-stringYu Watanabe2020-10-301-0/+49
|\ | | | | Allow escaped string in udev rules
| * udev: escaped string syntax e"..." in rule filesYu, Li-Yu2020-10-291-0/+49
| | | | | | | | | | | | | | * Existing valid rule files written with KEY="value" are not affected * Now, KEY=e"value\n" becomes valid. Where `\n` is a newline character * Escape sequences supported by src/basic/escape.h:cunescape() is supported
* | udev-util: use absolute rather than relative timeout when waiting for devicesLennart Poettering2020-10-221-8/+9
|/ | | | This makes it easier to accurately wait for a overall deadline.
* udev-util: ignore remove events, we care about initialization after allLennart Poettering2020-10-091-0/+16
|
* udev-util: make use of sd-event's NULL callback supportLennart Poettering2020-10-071-5/+1
|
* Merge pull request #17154 from keszybz/crypttab-commasLennart Poettering2020-10-011-4/+5
|\ | | | | Allow escaping commas in crypttab
| * tree-wide: drop assignments to r when we only need errnoZbigniew Jędrzejewski-Szmek2020-09-241-4/+5
| | | | | | | | | | | | | | If the whole call is simple and we don't need to look at the return value apart from the conditional, let's use a form without assignment of the return value. When the function call is more complicated, it still makes sense to use a temporary variable.
* | udev-util: simplify device_is_renaming() error handlingLennart Poettering2020-09-281-2/+4
|/
* shared/udev-util: fix sd_device leak in device_wait_for_initializationLuca Boccassi2020-08-141-1/+7
| | | | | If the caller doesn't pass a return pointer, or if sd_event_loop fails after the device was found and referenced, it never gets dereferenced.
* udev-util: add device_wait_for_devlinkLuca Boccassi2020-08-141-14/+83
| | | | | Allows to wait for an event by matching on the devlink that gets created.
* tree-wide: make use of new relative time events in sd-event.hLennart Poettering2020-07-281-3/+4
|
* udev: make signal that we use to kill workers on timeout configurableMichal Sekletár2020-06-051-7/+19
|
* udev: warn when we fail to parse udev.confZbigniew Jędrzejewski-Szmek2019-07-041-5/+10
| | | | | This should be like any other parse error and a warning should be emitted. Let's use log_syntax() so we get the CONFIG_FILE= set.
* util: make device_wait_for_initialization() optionally takes timeout valueYu Watanabe2019-06-041-2/+15
|
* util: make argument "subsystem" in device_wait_for_initialization() optionalYu Watanabe2019-06-041-4/+12
|