From 2cbc1e3b0a3062abfabc6a11cb7ae0616b4fdbdc Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Wed, 16 Feb 2011 16:11:59 +0100 Subject: 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. --- loader/net.c | 110 +++++++++++++++++++++++++++++++++-------------------------- loader/net.h | 2 ++ 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); -- cgit