+ /*
+ * Take a "read lock" on the device node; this establishes
+ * a concept of device "ownership" to serialize device
+ * access. External processes holding a "write lock" will
+ * cause udev to skip the event handling; in the case udev
+ * acquired the lock, the external process will block until
+ * udev has finished its event handling.
+ */
+ if (streq_ptr("block", udev_device_get_subsystem(dev))) {
+ struct udev_device *d = dev;
+
+ if (streq_ptr("partition", udev_device_get_devtype(d)))
+ d = udev_device_get_parent(d);
+
+ if (d) {
+ fd_lock = open(udev_device_get_devnode(d), O_RDONLY|O_CLOEXEC|O_NOFOLLOW|O_NONBLOCK);
+ if (fd_lock >= 0 && flock(fd_lock, LOCK_SH|LOCK_NB) < 0) {
+ log_debug("Unable to flock(%s), skipping event handling: %m", udev_device_get_devnode(d));
+ err = -EWOULDBLOCK;
+ goto skip;
+ }
+ }
+ }
+