summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadek Vykydal <rvykydal@redhat.com>2011-02-16 16:11:59 +0100
committerRadek Vykydal <rvykydal@redhat.com>2011-03-02 13:21:43 +0100
commit2cbc1e3b0a3062abfabc6a11cb7ae0616b4fdbdc (patch)
tree853adf274d5a12fa0227227566061213a271997a
parent365a39857d455a73c001af9ce3171a7ed346974d (diff)
downloadanaconda-2cbc1e3b0a3062abfabc6a11cb7ae0616b4fdbdc.tar.gz
anaconda-2cbc1e3b0a3062abfabc6a11cb7ae0616b4fdbdc.tar.xz
anaconda-2cbc1e3b0a3062abfabc6a11cb7ae0616b4fdbdc.zip
Reset only ifcfg file of device we failed to activate
Port from rhel6-branch. Resolves: rhbz#638131 Not of all devices, e.g those brought up before activating devices from kickstart.
-rw-r--r--loader/net.c110
-rw-r--r--loader/net.h2
2 files changed, 64 insertions, 48 deletions
diff --git a/loader/net.c b/loader/net.c
index 8fe6ca3ad..c571e99ea 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -1180,10 +1180,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);
@@ -1194,59 +1191,72 @@ 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;
}
+ }
+ return 0;
+}
- if (ofile) {
- free(ofile);
- ofile = NULL;
+int removeDhclientConfFile(char *device) {
+ char *ofile = NULL;
+ if (asprintf(&ofile, "/etc/dhcp/dhclient-%s.conf", device) == -1) {
+ return 5;
+ }
+
+ if (!access(ofile, R_OK|W_OK)) {
+ if (unlink(ofile)) {
+ logMessage(ERROR, "error removing %s", ofile);
}
+ }
- /* 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);
+ free(ofile);
+ return 0;
+}
- if ((fp = fopen(ofile, "w")) == NULL) {
- free(ofile);
- return 2;
- }
+int writeDisabledIfcfgFile(char *device) {
+ char *ofile = NULL;
+ char *nfile = NULL;
+ FILE *fp = NULL;
- 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");
+ checked_asprintf(&ofile, "%s/.ifcfg-%s",
+ NETWORK_SCRIPTS_PATH,
+ device);
+ checked_asprintf(&nfile, "%s/ifcfg-%s",
+ NETWORK_SCRIPTS_PATH,
+ device);
- if (fclose(fp) == EOF) {
- return 3;
- }
+ if ((fp = fopen(ofile, "w")) == NULL) {
+ free(ofile);
+ return 2;
+ }
+ 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 (rename(ofile, nfile) == -1) {
- free(ofile);
- free(nfile);
- return 4;
- }
+ if (fclose(fp) == EOF) {
+ return 3;
+ }
- if (ofile) {
- free(ofile);
- ofile = NULL;
- }
+ if (rename(ofile, nfile) == -1) {
+ free(ofile);
+ free(nfile);
+ return 4;
+ }
- if (nfile) {
- free(nfile);
- nfile = NULL;
- }
+ if (ofile) {
+ free(ofile);
+ ofile = NULL;
+ }
+
+ if (nfile) {
+ free(nfile);
+ nfile = NULL;
}
return 0;
@@ -1953,8 +1963,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 7e3ed1648..2a354f987 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);