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.
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;
* 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;