aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndoni Zarate <aiz@arteche.es>2021-04-23 12:32:47 +0200
committerAnthony G. Basile <blueness@gentoo.org>2021-08-23 12:03:05 -0400
commit841cd0ce3f6b97fbf77e12a6018a2c4a633eba89 (patch)
tree23a31d00876158d2b2cb41e65038ec475cc0ba5d
parentMakefile: flag -n of ln is not POSIX (diff)
downloadeudev-841cd0ce3f6b97fbf77e12a6018a2c4a633eba89.tar.gz
eudev-841cd0ce3f6b97fbf77e12a6018a2c4a633eba89.tar.bz2
eudev-841cd0ce3f6b97fbf77e12a6018a2c4a633eba89.zip
On collision rename my name to a temporal one letting others got my name...
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r--src/udev/udev-event.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 4120c04f2..64cc69cbc 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -826,6 +826,7 @@ static int rename_netif_dev_fromname_toname(struct udev_device *dev,const char *
#ifdef ENABLE_RULE_GENERATOR
int loop;
+ struct ifreq ifr_tmp;
if (r == 0) {
log_info("renamed network interface %s to %s\n", ifr.ifr_name, ifr.ifr_newname);
@@ -835,6 +836,16 @@ static int rename_netif_dev_fromname_toname(struct udev_device *dev,const char *
log_debug("collision on rename of network interface %s to %s , retrying until timeout\n",
ifr.ifr_name, ifr.ifr_newname);
+ /* there has been a collision so rename my name to a temporal name, letting other one to rename to my name, freeying its name... */
+ memzero(&ifr_tmp, sizeof(struct ifreq));
+ strscpy(ifr_tmp.ifr_name, IFNAMSIZ, oldname);
+ snprintf(ifr_tmp.ifr_newname, IFNAMSIZ, "rename_%s", oldname);
+ r = ioctl(sk, SIOCSIFNAME, &ifr_tmp);
+ log_info("Temporarily renamed network interface %s to %s\n", ifr_tmp.ifr_name, ifr_tmp.ifr_newname);
+
+ /* we have changed our name so in subsequents tries i should rename my temporal name to the wanted one */
+ strscpy(ifr.ifr_name, IFNAMSIZ, ifr_tmp.ifr_newname);
+
r = -errno;
if (r != -EEXIST)
goto out;