diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 49c692944e..fd79c5fea7 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -226,6 +226,15 @@ revert: } (void) device_add_property(dev, "ID_RENAMING", NULL); + /* When rename_netif() returns an error, the caller bails out of event_execute_rules() before + * device_update_db(dev) is called. Without persisting 'dev' here we would leave the on-disk + * database holding only the (stale) cloned state, dropping every property that udev rules added + * to the device during this event (e.g. ENV{}= assignments alongside the failing NAME=). + * In the -EBUSY case (r == 0) the caller continues normally and will write the DB itself, so + * only persist here when we're actually about to bail out. */ + if (r < 0) + (void) device_update_db(dev); + return r; } diff --git a/test/units/TEST-17-UDEV.rename-netif.sh b/test/units/TEST-17-UDEV.rename-netif.sh index 0abfe24bcd..393719efed 100755 --- a/test/units/TEST-17-UDEV.rename-netif.sh +++ b/test/units/TEST-17-UDEV.rename-netif.sh @@ -100,7 +100,7 @@ timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /s # cleanup ip link del hoge -# shellcheck disable=SC2317 +# shellcheck disable=SC2317,SC2329 teardown_netif_renaming_conflict() { set +ex @@ -181,4 +181,58 @@ EOF test_netif_renaming_conflict +# shellcheck disable=SC2317,SC2329 +teardown_netif_renaming_keeps_properties() { + set +ex + + rm -f /run/udev/rules.d/50-testsuite.rules + udevadm control --reload --timeout=30 + + ip link del rename-src 2>/dev/null || : + ip link del rename-dst 2>/dev/null || : +} + +test_netif_renaming_keeps_properties() { + trap teardown_netif_renaming_keeps_properties RETURN + + cat >/run/udev/rules.d/50-testsuite.rules <