From 6f233736fa8dfaabc83e4f77724453038e3dd7d0 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Tue, 28 Nov 2006 23:11:04 +0000 Subject: add a step to rename any temporarily renamed devices (#208740, #204803, #214817) --- src/rename_device.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/rename_device.c b/src/rename_device.c index cb960fc5..0ec08b46 100644 --- a/src/rename_device.c +++ b/src/rename_device.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -50,8 +51,15 @@ struct netdev { struct netdev *next; }; +struct tmp { + char *src; + char *target; + struct tmp *next; +}; + struct netdev *configs = NULL; struct netdev *devs = NULL; +struct tmp *tmplist = NULL; #if defined(__s390__) || defined(__s390x__) static int is_cdev(const struct dirent *dent) { @@ -294,6 +302,7 @@ void rename_device(char *src, char *target, struct netdev *current) { char *curdev; char *dev = NULL; struct netdev *i, *tmpdev; + char *fallback = NULL; hw = get_hwaddr(target); if (!hw) { @@ -309,14 +318,25 @@ void rename_device(char *src, char *target, struct netdev *current) { if (nconfig) { dev = nconfig; for (i = current; i; i = i->next) { - if (!strcmp(i->dev,dev)) + if (!strcmp(i->dev,dev)) { + fallback = dev; dev = NULL; + } } } if (!dev) asprintf(&dev,"__tmp%d",rand()); if (!dev) return; + if (fallback) { + struct tmp *ntmp = calloc(1, sizeof(struct tmp)); + + ntmp->src = strdup(dev); + ntmp->target = strdup(fallback); + if (tmplist) + ntmp->next = tmplist; + tmplist = ntmp; + } tmpdev = calloc(1,sizeof(struct netdev)); tmpdev->dev = curdev; if (current) @@ -364,7 +384,11 @@ void take_lock() { int main(int argc, char **argv) { char *src, *target, *hw; - + struct tmp *tmpdev; + struct timeval tv; + + gettimeofday(&tv, NULL); + srand(tv.tv_usec); take_lock(); signal(SIGSEGV,sighandler); @@ -388,6 +412,9 @@ int main(int argc, char **argv) { goto out_unlock; rename_device(src, target, NULL); + for (tmpdev = tmplist; tmpdev ; tmpdev = tmpdev->next) { + rename_device(tmpdev->src, tmpdev->target, NULL); + } printf("INTERFACE=%s\n",target); printf("DEVPATH=/class/net/%s\n", target); out_unlock: -- cgit v1.2.1