]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: do not try to lock whole block device on remove event
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Oct 2024 21:22:24 +0000 (06:22 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Oct 2024 01:51:19 +0000 (10:51 +0900)
As another device may be created with the same device node while udevd
is processing the remove event of the previous owner of the device node.

This also adds comment why we skip watching device node on remove.

src/udev/udev-watch.c
src/udev/udev-worker.c

index c28c43b2af47ba385db228c35ff8ade7db3299ae..1b8e2b8dbd4ee4ea5a5b0be724a771d7574a7ac0 100644 (file)
@@ -181,6 +181,9 @@ int udev_watch_begin(int inotify_fd, sd_device *dev) {
         assert(inotify_fd >= 0);
         assert(dev);
 
+        /* Ignore the request of watching the device node on remove event, as the device node specified by
+         * DEVNAME= has already been removed, and may already be assigned to another device. Consider the
+         * case e.g. a USB stick memory was unplugged and then another one is plugged. */
         if (device_for_action(dev, SD_DEVICE_REMOVE))
                 return 0;
 
index 7f22faccdc12ea11613d9c36b6d009ad7ee1322c..59f56f653cdafe081ffd7a68b9fe0c6b4a1f44c4 100644 (file)
@@ -97,6 +97,12 @@ static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) {
          * event handling; in the case udev acquired the lock, the external process can block until udev has
          * finished its event handling. */
 
+        /* Do not try to lock device on remove event, as the device node specified by DEVNAME= has already
+         * been removed, and may already be assigned to another device. Consider the case e.g. a USB stick
+         * memory was unplugged and then another one is plugged. */
+        if (device_for_action(dev, SD_DEVICE_REMOVE))
+                goto nolock;
+
         r = udev_get_whole_disk(dev, &dev_whole_disk, &val);
         if (r < 0)
                 return r;