[PATCH 8/9] Reset only ifcfg file of device we failed to activate (#638131)

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

 



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

diff --git a/loader/net.c b/loader/net.c
index 64b493d..8349b9d 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -1158,10 +1158,8 @@ int manualNetConfig(char * device, iface_t * iface,
  * bring up the ones the user wants.
  */
 int writeDisabledNetInfo(void) {
-    int i = 0;
+    int i = 0, rc;
     char *ofile = NULL;
-    char *nfile = NULL;
-    FILE *fp = NULL;
     struct device **devs = NULL;
 
     devs = getDevices(DEVICE_NETWORK);
@@ -1188,46 +1186,58 @@ int writeDisabledNetInfo(void) {
         }
 
         /* 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);
-
-        if ((fp = fopen(ofile, "w")) == NULL) {
-            free(ofile);
-            return 2;
+        if ((rc = writeDisabledIfcfgFile(devs[i]->device)) != 0) {
+            return rc;
         }
+    }
 
-        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");
+    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;
+
 }
 
 /*
@@ -2057,8 +2067,8 @@ 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 = writeDisabledIfcfgFile(iface->device)) != 0) {
+                logMessage(ERROR, "writeDisabledIfcfgFile failure (%s): %d",
                            __func__, rc);
             }
 
diff --git a/loader/net.h b/loader/net.h
index ca9c0a9..bed4c67 100644
--- a/loader/net.h
+++ b/loader/net.h
@@ -65,6 +65,7 @@ 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 writeEnabledNetInfo(iface_t * iface);
 int chooseNetworkInterface(struct loaderData_s * loaderData);
 void setupIfaceStruct(iface_t * iface, struct loaderData_s * loaderData);
-- 
1.7.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux