diff options
author | Kay Sievers <kay@vrfy.org> | 2012-07-05 17:40:50 +0200 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2012-07-05 17:40:50 +0200 |
commit | 97595710b77aa162ca5e20da57d0a1ed7355eaad (patch) | |
tree | 1d7412c52d0591b14bef72b7c7db91d49f00f2e2 /src/udev | |
parent | 47ef94ac5f39db6c5c18be10afe32397a0a8d5cc (diff) |
udev: network device renaming - immediately give up if the target name isn't available
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/udev-event.c | 69 |
1 files changed, 9 insertions, 60 deletions
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index aff14878a7..46e579dce2 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -745,32 +745,11 @@ out: return err; } -static void rename_netif_kernel_log(struct ifreq ifr) -{ - int klog; - FILE *f; - - klog = open("/dev/kmsg", O_WRONLY|O_CLOEXEC); - if (klog < 0) - return; - - f = fdopen(klog, "w"); - if (f == NULL) { - close(klog); - return; - } - - fprintf(f, "<30>udevd[%u]: renamed network interface %s to %s\n", - getpid(), ifr.ifr_name, ifr.ifr_newname); - fclose(f); -} - static int rename_netif(struct udev_event *event) { struct udev_device *dev = event->dev; int sk; struct ifreq ifr; - int loop; int err; log_debug("changing net interface name from '%s' to '%s'\n", @@ -787,49 +766,19 @@ static int rename_netif(struct udev_event *event) util_strscpy(ifr.ifr_name, IFNAMSIZ, udev_device_get_sysname(dev)); util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name); err = ioctl(sk, SIOCSIFNAME, &ifr); - if (err == 0) { - rename_netif_kernel_log(ifr); - goto out; - } - - /* keep trying if the destination interface name already exists */ - err = -errno; - if (err != -EEXIST) - goto out; - - /* free our own name, another process may wait for us */ - snprintf(ifr.ifr_newname, IFNAMSIZ, "rename%u", udev_device_get_ifindex(dev)); - err = ioctl(sk, SIOCSIFNAME, &ifr); - if (err < 0) { - err = -errno; - goto out; - } - - /* log temporary name */ - rename_netif_kernel_log(ifr); - - /* wait a maximum of 90 seconds for our target to become available */ - util_strscpy(ifr.ifr_name, IFNAMSIZ, ifr.ifr_newname); - util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name); - loop = 90 * 20; - while (loop--) { - const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 }; - - nanosleep(&duration, NULL); + if (err >= 0) { + FILE *f; - err = ioctl(sk, SIOCSIFNAME, &ifr); - if (err == 0) { - rename_netif_kernel_log(ifr); - break; + f = fopen("/dev/kmsg", "we"); + if (f != NULL) { + fprintf(f, "<30>systemd-udevd[%u]: renamed network interface %s to %s\n", + getpid(), ifr.ifr_name, ifr.ifr_newname); + fclose(f); } + } else { err = -errno; - if (err != -EEXIST) - break; - } - -out: - if (err < 0) log_error("error changing net interface name %s to %s: %m\n", ifr.ifr_name, ifr.ifr_newname); + } close(sk); return err; } |