summaryrefslogtreecommitdiff
path: root/src/udev/udevd.c
Commit message (Collapse)AuthorAgeFilesLines
* udev: single binary replacing udevd and udevadmNorbert Lange2020-06-011-3/+2
| | | | | | | | | | | | | | | Since the separate binaries contain mostly the same code, this almost halves the size of the installation. before: 398K /bin/udevadm 391K /lib/systemd/systemd-udevd after: 431K /bin/udevadm 0 /lib/systemd/systemd-udevd -> ../../bin/udevadm Fixes: #14200
* udevd: update snippet stringZbigniew Jędrzejewski-Szmek2020-05-301-1/+1
| | | | | Repeating the unit name in the description is not useful, and "manages devices" is too cryptic.
* udev: when the BSD lock on a block device is taken, don't complainLennart Poettering2020-05-271-6/+11
| | | | | | | | | if someone implements https://systemd.io/BLOCK_DEVICE_LOCKING/ then we shouldn't loudly complain about that. This reverts back to the original behaviour from 3ebdb81ef088afd3b4c72b516beb5610f8c93a0d: when the lock is taken we silently skip processing the device and sending out the messages for it.
* tree-wide: make sure our control buffers are properly alignedLennart Poettering2020-05-071-4/+1
| | | | | | | | | | | | | We always need to make them unions with a "struct cmsghdr" in them, so that things properly aligned. Otherwise we might end up at an unaligned address and the counting goes all wrong, possibly making the kernel refuse our buffers. Also, let's make sure we initialize the control buffers to zero when sending, but leave them uninitialized when reading. Both the alignment and the initialization thing is mentioned in the cmsg(3) man page.
* socket-util: introduce type-safe, dereferencing wrapper CMSG_FIND_DATA ↵Lennart Poettering2020-04-231-8/+2
| | | | | | | around cmsg_find() let's take this once step further, and add type-safety to cmsg_find(), and imply the CMSG_DATA() macro for finding the cmsg payload.
* tree-wide: use recvmsg_safe() at various placesLennart Poettering2020-04-231-9/+11
| | | | | | | | | | | | | | | | | Let's be extra careful whenever we return from recvmsg() and see MSG_CTRUNC set. This generally means we ran into a programming error, as we didn't size the control buffer large enough. It's an error condition we should at least log about, or propagate up. Hence do that. This is particularly important when receiving fds, since for those the control data can be of any size. In particular on stream sockets that's nasty, because if we miss an fd because of control data truncation we cannot recover, we might not even realize that we are one off. (Also, when failing early, if there's any chance the socket might be AF_UNIX let's close all received fds, all the time. We got this right most of the time, but there were a few cases missing. God, UNIX is hard to use)
* udev: add debug logs for delaying and delegation of eventsUwe Kleine-König2020-03-111-0/+11
| | | | | | | | | | | | | Up to now each uevent logs the following things at debug level: - Device is queued - Processing device - Device processed However when the device is queued it might still have to wait for earlier devices to be processed before being able to start being processed itself. When analysing logs this dependency information is quite cruicial, so add respective debug log calls.
* udev: assume that the recv buffer size of the netlink socket is already ↵Franck Bui2020-01-281-1/+5
| | | | | | configured when the socket is passed in This makes ReceiveBuffer= option in systemd-udevd-kernel.socket unit useful.
* udevd: don't use monitor after manager_exit()Martin Wilck2019-11-261-4/+6
| | | | | | | | | | If udevd receives an exit signal, it releases its reference on the udev monitor in manager_exit(). If at this time a worker is hanging, and if the event timeout for this worker expires before udevd exits, udevd crashes in on_sigchld()->udev_monitor_send_device(), because the monitor has already been freed. Fix this by testing the validity of manager->monitor in on_sigchld().
* Revert "udevd: fix crash when workers time out after exit is signal caught"Martin Wilck2019-11-261-2/+2
| | | | | This reverts commit 5db454b8031c58a743cc4ee3d5d1dd01dcff17e8. See https://github.com/systemd/systemd/issues/14128
* udevd: fix crash when workers time out after exit is signal caughtMartin Wilck2019-11-121-2/+2
| | | | | | | | | | | If udevd receives an exit signal, it releases its reference on the udev monitor in manager_exit(). If at this time a worker is hanging, and if the event timeout for this worker expires before udevd exits, udevd crashes in on_sigchld()->udev_monitor_send_device(), because the monitor has already been freed. Fix this by releasing the main process's monitor ref later, in manager_free().
* udevd: wait for workers to finish when exitingMartin Wilck2019-11-121-21/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On some systems with lots of devices, device probing for certain drivers can take a very long time. If systemd-udevd detects a timeout and kills the worker running modprobe using SIGKILL, some devices will not be probed, or end up in unusable state. The --event-timeout option can be used to modify the maximum time spent in an uevent handler. But if systemd-udevd exits, it uses a different timeout, hard-coded to 30s, and exits when this timeout expires, causing all workers to be KILLed by systemd afterwards. In practice, this may lead to workers being killed after significantly less time than specified with the event-timeout. This is particularly significant during initrd processing: systemd-udevd will be stopped by systemd when initrd-switch-root.target is about to be isolated, which usually happens quickly after finding and mounting the root FS. If systemd-udevd is started by PID 1 (i.e. basically always), systemd will kill both udevd and the workers after expiry of TimeoutStopSec. This is actually better than the built-in udevd timeout, because it's more transparent and configurable for users. This way users can avoid the mentioned boot problem by simply increasing StopTimeoutSec= in systemd-udevd.service. If udevd is not started by systemd (standalone), this is still an improvement. udevd will kill hanging workers when the event timeout is reached, which is configurable via the udev.event_timeout= kernel command line parameter. Before this patch, udevd would simply exit with workers still running, which would then become zombie processes. With the timeout removed, the sd_event_now() assertion in manager_exit() can be dropped.
* tree-wide: drop signal.h when signal-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop socket.h when socket-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* udevd: add helper with error handling to synthesize "change" eventsZbigniew Jędrzejewski-Szmek2019-07-121-13/+16
| | | | | Coverity was unhappy that we ignore the return value from write_string_file(). We should at least warn. CID#1302373.
* udevd: open log output earlyZbigniew Jędrzejewski-Szmek2019-07-041-1/+2
| | | | | We'd log to the "console", losing structured logs during configuration file parsing. Let's be nice to journalctl users, and log to the journal immediately.
* udevd: fix a reversed conditional on global property setLubomir Rintel2019-06-251-1/+1
| | | | | | | | | | | | | | | | | # udevadm control --property=HELLO=WORLD Received udev control message (ENV), unsetting 'HELLO' # udevadm control --property=HELLO= Received udev control message (ENV), setting 'HELLO=' Oh no, it's busted. Let's try removing this one little negation real quick to see if it helps... # udevadm control --property=HELLO=WORLD Received udev control message (ENV), setting 'HELLO=WORLD' # udevadm control --property=HELLO= Received udev control message (ENV), unsetting 'HELLO' Feels much better now.
* udev: propagate errors in udev_event_execute_rules()Yu Watanabe2019-06-051-1/+4
| | | | And do not set initialized flag to the device.
* udev: modernize udev-rules.cYu Watanabe2019-06-021-1/+1
| | | | | | | | | | | This does the following: - rename enum udev_builtin_cmd -> UdevBuiltinCmd - rename struct udev_builtin -> UdevBuiltin - move type definitions to udev-rules.h - move prototypes of functions defined in udev-rules.c to udev-rules.h - drop to use strbuf - propagate critical errors in applying rules, - drop limitation for number of tokens per line.
* udevd: change the default value of udev.children-max (again)Franck Bui2019-05-161-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow-up for faae64fa3dc22738b3af669579a33055b9d71432, which increased the default number of udev workers per cpu regardless of how big the system is. It's not really clear from the commit message if the new number of workers improved the overall time for the boot process or only reduced the number of times the max number of children limit was reached (and in this case 5406c36844b3 commit might have been more appropriate in the first place). But systems with ~1000 CPUs are not rare these days and the worker numbers get quite large with CPU factor of 8. Spawning more than 2000 workers can't be healthy on any system, no matter how big. Indeed the main mistake is the belief that udev is CPU-intensive, and thus the number of allowed workers has to increase with the number of CPUs. It is not, at probably has never been. It's I/O bound, and sometimes, bound by resources such as locks. This is an argument to: - scale only weakly with the number of CPUs, and the rationale to switch back to a scale factor C=2 but with a higher offset number which should affect systems with a small number of CPUs only. With this patch applied the offset is increased from O=8 to O=16. - put an absolute maximum limit to make sure no more than 2048 workers are spawned no matter how big the system is. This still provides more workers for the laptop cases (where the number of CPUs is limited), while avoiding sky-rocketing numbers for big systems. Note that on most desktop systems, the memory limit will kick in. The following table collects numbers about children-max. For each scenario, the first column is the "cpu_limit" limit, and the second number is the minimum amount of memory for the "cpu_limit" limit to become relevant (with less RAM, memory will limit the number of children thus "mem_limit" will become the active limit). | > v240 | < v240 | this patch | CPUs | C = 8, O = 8 | C = 2, O = 8 | C = 2, O = 16 | ------------------------------------------------------- 1 | 16 2 | 10 1.3 | 18 2 | 2 | 24 3 | 12 1.5 | 20 2 | 4 | 40 5 | 16 2 | 24 3 | 8 | 72 9 | 24 3 | 32 4 | 16 | 136 17 | 40 5 | 48 5 | 64 | 520 65 | 136 17 | 144 18 | 1024 | 8200 1025 | 2056 263 | 2048 256 | 2048 |16392 2049 | 4104 513 | 2048 256 | This patch is mainly based on Martin Wilck's analyze and comments.
* udevd: notify when max number value of children is reached only once per ↵Franck Bui2019-04-261-1/+10
| | | | | | | | | | | | | | | | | | batch of events When booting with "udev.log-priority=debug" for example, the output might be spammed with messages like this: systemd-udevd[23545]: maximum number (248) of children reached systemd-udevd[23545]: maximum number (248) of children reached systemd-udevd[23545]: maximum number (248) of children reached systemd-udevd[23545]: maximum number (248) of children reached systemd-udevd[23545]: maximum number (248) of children reached systemd-udevd[23545]: maximum number (248) of children reached systemd-udevd[23545]: maximum number (248) of children reached While the message itself is useful, printing it per batch of events should be enough.
* udev: move udev_ctrl_cleanup() into manager_free()Yu Watanabe2019-04-011-7/+6
|
* util: split out some stuff into a new file limits-util.[ch]Lennart Poettering2019-03-131-0/+1
|
* udevd: use device_get_action() and device_get_seqnum()Yu Watanabe2019-03-121-21/+14
|
* udev-ctrl: use sd_event and introduce udev_ctrl_start()Yu Watanabe2019-02-201-59/+42
| | | | | Now the new callback function get enum udev_ctrl_msg_type. So, this commit also drops udev_ctrl_connection and udev_ctrl_msg.
* udev: drop unused Manager::uevent_eventYu Watanabe2019-02-201-3/+0
|
* udev-ctrl: make udev_ctrl_new() return negative errno on failureYu Watanabe2019-02-201-3/+3
|
* Merge pull request #11589 from yuwata/udevd-is-device-busyLennart Poettering2019-02-151-21/+14
|\ | | | | udevd: refactoring is_device_busy()
| * udevd: save the result of devnum or ifindex blockerYu Watanabe2019-01-291-2/+2
| |
| * udevd: always block follwoing events with same devpathYu Watanabe2019-01-291-5/+1
| | | | | | | | | | | | | | | | Originally commented as "devices names might have changed/swapped in the meantime", but may not. For safety, let's block the following events with same devpath. This may fix #6514.
| * udevd: trivial refactoring of is_device_busy()Yu Watanabe2019-01-291-14/+11
| |
* | udev: check whether systemd is running, and do not use cg_kill() if notYu Watanabe2019-02-131-4/+4
|/ | | | Fixes #11645.
* udevd: rename control command SYNC -> PING in log messageYu Watanabe2019-01-181-1/+1
|
* udev: also update log level for LOG_REALM_SYSTEMDYu Watanabe2019-01-131-1/+2
| | | | | | Now, not a few udevd debug logs come from sd-device or sd-hwdb. Only setting LOG_REALM_UDEV may not sufficient to debug. We have already similar code in main() and udevadm.
* udevd: refuse devices which do not have ACTION propertyYu Watanabe2019-01-121-7/+7
|
* udevd: drop unnecessary bracketsYu Watanabe2019-01-121-5/+4
|
* udevd: make worker also log ACTION propertyYu Watanabe2019-01-121-3/+7
|
* udevd: reject devices which do not have SEQNUMYu Watanabe2019-01-121-1/+1
|
* udevd: provide worker_hash_ops and drop manager_workers_free()Yu Watanabe2019-01-121-14/+3
|
* udevd: use structured initializer at one more placeYu Watanabe2019-01-121-6/+9
|
* udevd: use worker_free() on failure in worker_new()Yu Watanabe2019-01-121-1/+3
| | | | Otherwise, worker_monitor may not unrefed correctly.
* udev: open control and netlink sockets before daemonizationZbigniew Jędrzejewski-Szmek2019-01-101-33/+34
| | | | | | | | | | | | | | | | c4b69e990f962128cc6975e36e91e9ad838fa2c4 effectively moved the initalization of socket. Before that commit: run → listen_fds → udev_ctrl_new → udev_ctrl_new_from_fd → socket() After: run → main_loop → manager_new → udev_ctrl_new_from_fd → socket() The problem is that main_loop was called after daemonization. Move manager_new out of main_loop and before daemonization. Fixes #11314 (hopefully ;)). v2: Yu Watanabe sd_event is initialized in main_loop().
* udevd: drop redundant call to sd_event_get_exit_codeZbigniew Jędrzejewski-Szmek2019-01-101-12/+3
| | | | sd_event_loop returns the same thing anyway.
* Merge pull request #11244 from yuwata/revert-udev-changesZbigniew Jędrzejewski-Szmek2019-01-031-1/+1
|\ | | | | udev: revert bind/unbind patch and one more
| * Revert "udevd: configure a child process name for worker processes"Yu Watanabe2019-01-021-1/+1
| | | | | | | | This reverts commit 49f3ee7e74c714f55aab395c080b1099fc17f7fd.
* | meson: generate version tag from gitZbigniew Jędrzejewski-Szmek2018-12-211-2/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | $ build/systemctl --version systemd 239-3555-g6178cbb5b5 +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid $ git tag v240 -m 'v240' $ ninja -C build ninja: Entering directory `build' [76/76] Linking target fuzz-unit-file. $ build/systemctl --version systemd 240 +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid This is very useful during development, because a precise version string is embedded in the build product and displayed during boot, so we don't have to guess answers for questions like "did I just boot the latest version or the one from before?". This change creates an overhead for "noop" builds. On my laptop, 'ninja -C build' that does nothing goes from 0.1 to 0.5 s. It would be nice to avoid this, but I think that <1 s is still acceptable. Fixes #7183. PACKAGE_VERSION is renamed to GIT_VERSION, to make it obvious that this is the more dynamically changing version string. Why save to a file? It would be easy to generate the version tag using run_command(), but we want to go through a file so that stuff gets rebuilt when this file changes. If we just defined an variable in meson, ninja wouldn't know it needs to rebuild things.
* Merge pull request #11159 from keszybz/udev-typedefLennart Poettering2018-12-171-6/+8
|\ | | | | Udev typedef and normal error reporting
| * udev: use typedef for struct udev_eventZbigniew Jędrzejewski-Szmek2018-12-171-1/+1
| |
| * udev: use typedef for struct udev_rulesZbigniew Jędrzejewski-Szmek2018-12-171-1/+1
| |