From 7137f2f3a7e7e60a821a0d7c83f9b821045b567a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 26 Oct 2022 04:37:24 +0900 Subject: [PATCH] udev: drop ID_RENAMING from UdevEvent.dev_db_clone instead of UdevEvent.dev As the properties loaded from the database are stored to UdevEvent.dev_db_clone, instead of UdevEvent.dev. This also makes the removal done unconditionally, for safety. --- src/udev/udev-event.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index b3d92d51505..42b480ca6b1 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -906,7 +906,7 @@ static int rename_netif(UdevEvent *event) { return 0; } - /* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */ + /* Set ID_RENAMING boolean property here. It will be dropped when the corresponding move uevent is processed. */ r = device_add_property(dev, "ID_RENAMING", "1"); if (r < 0) return log_device_warning_errno(dev, r, "Failed to add 'ID_RENAMING' property: %m"); @@ -1008,17 +1008,6 @@ static int event_execute_rules_on_remove( return r; } -static int udev_event_on_move(sd_device *dev) { - int r; - - /* Drop previously added property */ - r = device_add_property(dev, "ID_RENAMING", NULL); - if (r < 0) - return log_device_debug_errno(dev, r, "Failed to remove 'ID_RENAMING' property: %m"); - - return 0; -} - static int copy_all_tags(sd_device *d, sd_device *s) { const char *tag; int r; @@ -1074,11 +1063,13 @@ int udev_event_execute_rules( if (r < 0) log_device_warning_errno(dev, r, "Failed to copy all tags from old database entry, ignoring: %m"); - if (action == SD_DEVICE_MOVE) { - r = udev_event_on_move(event->dev); - if (r < 0) - return r; - } + /* Drop previously added property for safety to make IMPORT{db}="ID_RENAMING" not work. This is + * mostly for 'move' uevent, but let's do unconditionally. Why? If a network interface is renamed in + * initrd, then udevd may lose the 'move' uevent during switching root. Usually, we do not set the + * persistent flag for network interfaces, but user may set it. Just for safety. */ + r = device_add_property(event->dev_db_clone, "ID_RENAMING", NULL); + if (r < 0) + return log_device_debug_errno(dev, r, "Failed to remove 'ID_RENAMING' property: %m"); DEVICE_TRACE_POINT(rules_start, dev);