]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: do not re-create database on remove event
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Oct 2024 15:55:43 +0000 (00:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Oct 2024 21:32:39 +0000 (06:32 +0900)
Fixes a bug introduced by f6bda694f908cc227b002570b893029aa4c9e173 (v256).

With the offending commit, on remove event, database file for a device is once
removed in event_execute_rules_on_remove(), but later re-created here.
This fixes the issue, and makes the database file not re-created on remove event.

src/udev/udev-worker.c

index 5577f5fab8d8733e582b8babde442575c7961455..7f22faccdc12ea11613d9c36b6d009ad7ee1322c 100644 (file)
@@ -200,26 +200,31 @@ static int worker_process_device(UdevWorker *worker, sd_device *dev) {
         if (r < 0)
                 return r;
 
+        /* Process RUN=. */
         udev_event_execute_run(udev_event);
 
         if (!worker->rtnl)
                 /* in case rtnl was initialized */
                 worker->rtnl = sd_netlink_ref(udev_event->rtnl);
 
+        /* Enable watch if requested. */
         if (udev_event->inotify_watch) {
                 r = udev_watch_begin(worker->inotify_fd, dev);
                 if (r < 0 && r != -ENOENT) /* The device may be already removed, ignore -ENOENT. */
                         log_device_warning_errno(dev, r, "Failed to add inotify watch, ignoring: %m");
         }
 
-        /* Finalize database. */
-        r = device_add_property(dev, "ID_PROCESSING", NULL);
-        if (r < 0)
-                return log_device_warning_errno(dev, r, "Failed to remove 'ID_PROCESSING' property: %m");
+        /* Finalize database. But do not re-create database on remove, which has been already removed in
+         * event_execute_rules_on_remove(). */
+        if (!device_for_action(dev, SD_DEVICE_REMOVE)) {
+                r = device_add_property(dev, "ID_PROCESSING", NULL);
+                if (r < 0)
+                        return log_device_warning_errno(dev, r, "Failed to remove 'ID_PROCESSING' property: %m");
 
-        r = device_update_db(dev);
-        if (r < 0)
-                return log_device_warning_errno(dev, r, "Failed to update database under /run/udev/data/: %m");
+                r = device_update_db(dev);
+                if (r < 0)
+                        return log_device_warning_errno(dev, r, "Failed to update database under /run/udev/data/: %m");
+        }
 
         log_device_uevent(dev, "Device processed");
         return 0;