aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2006-07-19 14:55:04 +0000
committerBill Nottingham <notting@redhat.com>2006-07-19 14:55:04 +0000
commit338d390986d219a996e8c7e854e58a9344ee9346 (patch)
treed82e8cf94b5bd3c7ed74b22becea3af0f47870fd /src
parentb9d47ad29e0af2b71725d5da3dc853495c58328e (diff)
downloadinitscripts-338d390986d219a996e8c7e854e58a9344ee9346.tar
initscripts-338d390986d219a996e8c7e854e58a9344ee9346.tar.gz
initscripts-338d390986d219a996e8c7e854e58a9344ee9346.tar.bz2
initscripts-338d390986d219a996e8c7e854e58a9344ee9346.tar.xz
initscripts-338d390986d219a996e8c7e854e58a9344ee9346.zip
don't loop if there are multiple devices with the same hwaddr (#199242, <markmc@redhat.com>)
Diffstat (limited to 'src')
-rw-r--r--src/rename_device.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/rename_device.c b/src/rename_device.c
index 00b14475..295e4461 100644
--- a/src/rename_device.c
+++ b/src/rename_device.c
@@ -177,15 +177,21 @@ char *get_hwaddr(char *device) {
return NULL;
}
-char *get_config_by_hwaddr(char *hwaddr) {
+char *get_config_by_hwaddr(char *hwaddr, char *current) {
struct netdev *config;
+ char *first = NULL;
if (!hwaddr) return NULL;
- for (config = configs; config; config = config->next)
- if (!strcasecmp(config->hwaddr, hwaddr))
+ for (config = configs; config; config = config->next) {
+ if (strcasecmp(config->hwaddr, hwaddr) != 0)
+ continue;
+ if (!current || !strcasecmp(config->dev, current))
return config->dev;
- return NULL;
+ if (!first)
+ first = config->dev;
+ }
+ return first;
}
char *get_device_by_hwaddr(char *hwaddr) {
@@ -212,6 +218,7 @@ int do_rename(char *src, char *target) {
g_strlcpy(ifr.ifr_name, src, IFNAMSIZ);
g_strlcpy(ifr.ifr_newname, target, IFNAMSIZ);
ret = ioctl(sock, SIOCSIFNAME, &ifr);
+ close(sock);
return ret;
}
@@ -240,7 +247,7 @@ void rename_device(char *src, char *target, struct netdev *current) {
return;
}
- nconfig = get_config_by_hwaddr(hw);
+ nconfig = get_config_by_hwaddr(hw, NULL);
curdev = get_device_by_hwaddr(hw);
if (nconfig) {
@@ -320,7 +327,7 @@ int main(int argc, char **argv) {
hw = get_hwaddr(src);
if (!hw)
goto out_unlock;
- target = get_config_by_hwaddr(hw);
+ target = get_config_by_hwaddr(hw, src);
if (!target || !strcmp(src,target))
goto out_unlock;