From: Yu Watanabe Date: Sun, 13 Oct 2024 15:55:43 +0000 (+0900) Subject: udev: do not re-create database on remove event X-Git-Tag: v257-rc1~224^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b2dce150d5eadcd33d620e095c9c1e2de51dd24;p=thirdparty%2Fsystemd.git udev: do not re-create database on remove event 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. --- diff --git a/src/udev/udev-worker.c b/src/udev/udev-worker.c index 5577f5fab8d..7f22faccdc1 100644 --- a/src/udev/udev-worker.c +++ b/src/udev/udev-worker.c @@ -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;