[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH rhel6-branch 08/11] Reset only ifcfg file of device we failed to activate (#638131)



Not of all devices, e.g those brought up before activating
devices from kickstart.
---
 loader/net.c |  114 +++++++++++++++++++++++++++++++++-------------------------
 loader/net.h |    2 +
 2 files changed, 67 insertions(+), 49 deletions(-)

diff --git a/loader/net.c b/loader/net.c
index 42ff751..fa3d4dd 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -1158,10 +1158,7 @@ int manualNetConfig(char * device, iface_t * iface,
  * bring up the ones the user wants.
  */
 int writeDisabledNetInfo(void) {
-    int i = 0;
-    char *ofile = NULL;
-    char *nfile = NULL;
-    FILE *fp = NULL;
+    int i = 0, rc;
     struct device **devs = NULL;
 
     devs = getDevices(DEVICE_NETWORK);
@@ -1172,59 +1169,74 @@ int writeDisabledNetInfo(void) {
 
     for (i = 0; devs[i]; i++) {
         /* remove dhclient-DEVICE.conf if we have it */
-        if (asprintf(&ofile, "/etc/dhcp/dhclient-%s.conf", devs[i]->device) == -1) {
-            return 5;
+        if ((rc = removeDhclientConfFile(devs[i]->device)) != 0) {
+            return rc;
         }
-
-        if (!access(ofile, R_OK|W_OK)) {
-            if (unlink(ofile)) {
-                logMessage(ERROR, "error removing %s", ofile);
-            }
+        /* write disabled ifcfg-DEVICE file */
+        if ((rc = writeDisabledIfcfgFile(devs[i]->device)) != 0) {
+            return rc;
         }
+    }
 
-        if (ofile) {
-            free(ofile);
-            ofile = NULL;
-        }
+    return 0;
+}
 
-        /* write disabled ifcfg-DEVICE file */
-        
-        checked_asprintf(&ofile, "%s/.ifcfg-%s",
-                         NETWORK_SCRIPTS_PATH,
-                         devs[i]->device);
-        checked_asprintf(&nfile, "%s/ifcfg-%s",
-                         NETWORK_SCRIPTS_PATH,
-                         devs[i]->device);
+int removeDhclientConfFile(char *device) {
+    char *ofile = NULL;
+    if (asprintf(&ofile, "/etc/dhcp/dhclient-%s.conf", device) == -1) {
+	return 5;
+    }
 
-        if ((fp = fopen(ofile, "w")) == NULL) {
-            free(ofile);
-            return 2;
-        }
+    if (!access(ofile, R_OK|W_OK)) {
+	if (unlink(ofile)) {
+	    logMessage(ERROR, "error removing %s", ofile);
+	}
+    }
 
-        fprintf(fp, "DEVICE=%s\n", devs[i]->device);
-        fprintf(fp, "HWADDR=%s\n", iface_mac2str(devs[i]->device));
-        fprintf(fp, "ONBOOT=no\n");
-        fprintf(fp, "NM_CONTROLLED=no\n");
+    free(ofile);
+    return 0;
+}
 
-        if (fclose(fp) == EOF) {
-            return 3;
-        }
+int writeDisabledIfcfgFile(char *device) {
+    char *ofile = NULL;
+    char *nfile = NULL;
+    FILE *fp = NULL;
 
-        if (rename(ofile, nfile) == -1) {
-            free(ofile);
-            free(nfile);
-            return 4;
-        }
+    checked_asprintf(&ofile, "%s/.ifcfg-%s",
+		     NETWORK_SCRIPTS_PATH,
+		     device);
+    checked_asprintf(&nfile, "%s/ifcfg-%s",
+		     NETWORK_SCRIPTS_PATH,
+		     device);
 
-        if (ofile) {
-            free(ofile);
-            ofile = NULL;
-        }
+    if ((fp = fopen(ofile, "w")) == NULL) {
+	free(ofile);
+	return 2;
+    }
 
-        if (nfile) {
-            free(nfile);
-            nfile = NULL;
-        }
+    fprintf(fp, "DEVICE=%s\n", device);
+    fprintf(fp, "HWADDR=%s\n", iface_mac2str(device));
+    fprintf(fp, "ONBOOT=no\n");
+    fprintf(fp, "NM_CONTROLLED=no\n");
+
+    if (fclose(fp) == EOF) {
+	return 3;
+    }
+
+    if (rename(ofile, nfile) == -1) {
+	free(ofile);
+	free(nfile);
+	return 4;
+    }
+
+    if (ofile) {
+	free(ofile);
+	ofile = NULL;
+    }
+
+    if (nfile) {
+	free(nfile);
+	nfile = NULL;
     }
 
     return 0;
@@ -2066,8 +2078,12 @@ int activateDevice(struct loaderData_s * loaderData, iface_t * iface) {
              * we set before attempting to bring the incorrect interface up.
              */
             logMessage(ERROR, "unable to activate device %s", iface->device);
-            if ((rc = writeDisabledNetInfo()) != 0) {
-                logMessage(ERROR, "writeDisabledNetInfo failure (%s): %d",
+            if ((rc = removeDhclientConfFile(iface->device)) != 0) {
+                logMessage(ERROR, "removeDhclientConfFile failure (%s): %d",
+                           __func__, rc);
+            }
+            if ((rc = writeDisabledIfcfgFile(iface->device)) != 0) {
+                logMessage(ERROR, "writeDisabledIfcfgFile failure (%s): %d",
                            __func__, rc);
             }
 
diff --git a/loader/net.h b/loader/net.h
index b5769a5..567650a 100644
--- a/loader/net.h
+++ b/loader/net.h
@@ -65,6 +65,8 @@ int manualNetConfig(char * device, iface_t * iface,
                     struct intfconfig_s * ipcomps, struct netconfopts * opts);
 void debugNetworkInfo(iface_t * iface);
 int writeDisabledNetInfo(void);
+int writeDisabledIfcfgFile(char *device);
+int removeDhclientConfFile(char *device);
 int writeEnabledNetInfo(iface_t * iface);
 int chooseNetworkInterface(struct loaderData_s * loaderData);
 void setupIfaceStruct(iface_t * iface, struct loaderData_s * loaderData);
-- 
1.7.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]