From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthias Schwarzott Date: Tue, 23 Jan 2007 16:12:55 +0000 Subject: [PATCH] Sanitizing netif-rename code Message-Id: <200701231712.56015.zzam@gentoo.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="Boundary-00=_IQjtFI5jgkPfxb9" List-Id: To: linux-hotplug@vger.kernel.org --Boundary-00=_IQjtFI5jgkPfxb9 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi there! The attached patch comes origins from this Bugreport: http://bugs.gentoo.org/show_bug.cgi?id=158531 The original code from udev_device.c / function rename_netif looks like this: while (loop--) { retval = ioctl(sk, SIOCSIFNAME, &ifr); if (retval != 0) { if (errno != EEXIST) { err("error changing net interface name %s to %s: %s", ifr.ifr_name, ifr.ifr_newname, strerror(errno)); break; } dbg("wait for netif '%s' to become free, loop=%i", udev->name, (30 * 20) - loop); usleep(1000 * 1000 / 20); } } In some loop the rename-syscall will succeed, and retval is 0. In this case the loop is not left, but just retried the loop and executing the rename code over and over again. Attached patch adds something similar to that (inside the loop): if (retval == 0) break; Greetings Matthias -- Matthias Schwarzott (zzam) --Boundary-00=_IQjtFI5jgkPfxb9 Content-Type: text/x-diff; charset="utf-8"; name="udev-103-busywait.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="udev-103-busywait.patch" diff -Nur udev-103old/udev_device.c udev-103/udev_device.c --- udev-103old/udev_device.c 2006-10-20 14:43:35.000000000 +0200 +++ udev-103/udev_device.c 2006-12-20 12:04:52.000000000 +0100 @@ -122,16 +122,18 @@ strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ); loop = 30 * 20; while (loop--) { - retval = ioctl(sk, SIOCSIFNAME, &ifr); - if (retval != 0) { + retval = ioctl(sk, SIOCSIFNAME, &ifr); + if (retval == 0) { + break; + } else { if (errno != EEXIST) { err("error changing net interface name %s to %s: %s", ifr.ifr_name, ifr.ifr_newname, strerror(errno)); break; } - dbg("wait for netif '%s' to become free, loop=%i", udev->name, (30 * 20) - loop); - usleep(1000 * 1000 / 20); } + dbg("wait for netif '%s' to become free, loop=%i", udev->name, (30 * 20) - loop); + usleep(1000 * 1000 / 20); } } --Boundary-00=_IQjtFI5jgkPfxb9 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV --Boundary-00=_IQjtFI5jgkPfxb9 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel --Boundary-00=_IQjtFI5jgkPfxb9--