forked from pool/systemd
64 lines
2.6 KiB
Diff
64 lines
2.6 KiB
Diff
|
From: Robert Milasan <rmilasan@suse.com>
|
||
|
Cc: Werner Fink <werner@suse.de>
|
||
|
Subject: udev always rename network
|
||
|
|
||
|
Date: Thu, 28 Mar 2013 09:24:43 +0000
|
||
|
udev: ensure that the network interfaces are renamed even if they exist (bnc#809843).
|
||
|
|
||
|
Date: Tue, 4 Mar 2014 10:29:21 +0000
|
||
|
Port the patch of Robert to systemd v210 and test it out.
|
||
|
|
||
|
---
|
||
|
udev-event.c | 40 ++++++++++++++++++++++++++++++++++++----
|
||
|
1 file changed, 36 insertions(+), 4 deletions(-)
|
||
|
|
||
|
--- systemd-210/src/udev/udev-event.c
|
||
|
+++ systemd-210/src/udev/udev-event.c 2014-03-04 11:19:50.583710411 +0100
|
||
|
@@ -765,10 +765,42 @@ static int rename_netif(struct udev_even
|
||
|
return r;
|
||
|
|
||
|
r = rtnl_set_link_name(rtnl, udev_device_get_ifindex(dev), name);
|
||
|
- if (r < 0)
|
||
|
- log_error("error changing net interface name %s to %s: %s",
|
||
|
- oldname, name, strerror(-r));
|
||
|
- else
|
||
|
+ if (r < 0) {
|
||
|
+ char interim[IFNAMSIZ], *ptr = &interim[0];
|
||
|
+ int loop = 90;
|
||
|
+
|
||
|
+ /* keep trying if the destination interface name already exists */
|
||
|
+ if (r != -EEXIST) {
|
||
|
+ log_error("error changing net interface name %s to %s: %s",
|
||
|
+ oldname, name, strerror(-r));
|
||
|
+ return r;
|
||
|
+ }
|
||
|
+
|
||
|
+ /* free our own name, another process may wait for us */
|
||
|
+ strpcpyf(&ptr, IFNAMSIZ, "rename%u", udev_device_get_ifindex(dev));
|
||
|
+
|
||
|
+ r = rtnl_set_link_name(rtnl, udev_device_get_ifindex(dev), interim);
|
||
|
+ if (r < 0) {
|
||
|
+ log_error("error changing net interface name %s to %s: %s",
|
||
|
+ oldname, name, strerror(-r));
|
||
|
+ return r;
|
||
|
+ }
|
||
|
+
|
||
|
+ /* log temporary name */
|
||
|
+ print_kmsg("renamed network interface %s to %s", oldname, interim);
|
||
|
+ do {
|
||
|
+ r = rtnl_set_link_name(rtnl, udev_device_get_ifindex(dev), name);
|
||
|
+ if (r == 0) {
|
||
|
+ print_kmsg("renamed network interface %s to %s", oldname, name);
|
||
|
+ return r;
|
||
|
+ }
|
||
|
+ if (r != -EEXIST) {
|
||
|
+ log_error("error changing net interface name %s to %s: %s",
|
||
|
+ oldname, name, strerror(-r));
|
||
|
+ return r;
|
||
|
+ }
|
||
|
+ } while (loop-- > 0);
|
||
|
+ } else
|
||
|
print_kmsg("renamed network interface %s to %s", oldname, name);
|
||
|
|
||
|
return r;
|