summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAles Kozumplik <akozumpl@redhat.com>2009-11-19 11:23:03 +0100
committerAles Kozumplik <akozumpl@redhat.com>2009-11-19 11:23:03 +0100
commitcf5fb9e8806f1d82a772b1f190f52bc1234baac9 (patch)
tree501679f2813de5af58390ca87b58638ae8c03df5
parent436da6753f80dfafcfc242a2b08fccb81bf83ab9 (diff)
downloadanaconda-cf5fb9e8806f1d82a772b1f190f52bc1234baac9.tar.gz
anaconda-cf5fb9e8806f1d82a772b1f190f52bc1234baac9.tar.xz
anaconda-cf5fb9e8806f1d82a772b1f190f52bc1234baac9.zip
Introduces check_asprintf macro that checks asprintfs return value and terminates program in OOM scenarios.
This is to avoid having to copy-paste the asprintf-log-abort if branch all the time. This commit also modifies existing asprintf() calls to use the new macro in places where the change wouldn't modify program's semantics.
-rw-r--r--loader/cdinstall.c45
-rw-r--r--loader/driverdisk.c20
-rw-r--r--loader/driverselect.c22
-rw-r--r--loader/hardware.c5
-rw-r--r--loader/hdinstall.c50
-rw-r--r--loader/lang.c5
-rw-r--r--loader/loader.c89
-rw-r--r--loader/loader.h6
-rw-r--r--loader/method.c5
-rw-r--r--loader/net.c52
-rw-r--r--loader/nfsinstall.c125
-rw-r--r--loader/urlinstall.c47
-rw-r--r--loader/urls.c14
13 files changed, 138 insertions, 347 deletions
diff --git a/loader/cdinstall.c b/loader/cdinstall.c
index cc3969172..3ccc332a8 100644
--- a/loader/cdinstall.c
+++ b/loader/cdinstall.c
@@ -265,11 +265,8 @@ static void queryCDMediaCheck(char *dev, char *location) {
continue;
}
- if (asprintf(&stage2loc, "%s/images/install.img",
- location) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&stage2loc, "%s/images/install.img",
+ location);
if (access(stage2loc, R_OK)) {
free(stage2loc);
@@ -308,10 +305,7 @@ static char *setupCdrom(char *location, struct loaderData_s *loaderData,
return NULL;
}
- if (asprintf(&stage2loc, "%s/images/install.img", location) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&stage2loc, "%s/images/install.img", location);
/* JKFIXME: ASSERT -- we have a cdrom device when we get here */
do {
@@ -323,10 +317,7 @@ static char *setupCdrom(char *location, struct loaderData_s *loaderData,
continue;
if (strncmp("/dev/", devices[i]->device, 5)) {
- if (asprintf(&tmp, "/dev/%s", devices[i]->device) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&tmp, "/dev/%s", devices[i]->device);
free(devices[i]->device);
devices[i]->device = tmp;
@@ -398,19 +389,13 @@ static char *setupCdrom(char *location, struct loaderData_s *loaderData,
continue;
}
- if (asprintf(&updpath, "%s/images/updates.img", location) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&updpath, "%s/images/updates.img", location);
logMessage(INFO, "Looking for updates in %s", updpath);
copyUpdatesImg(updpath);
free(updpath);
- if (asprintf(&updpath, "%s/images/product.img", location) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&updpath, "%s/images/product.img", location);
logMessage(INFO, "Looking for product in %s", updpath);
copyProductImg(updpath);
@@ -422,11 +407,8 @@ static char *setupCdrom(char *location, struct loaderData_s *loaderData,
umount(location);
}
- if (asprintf(&retbuf, "cdrom://%s:%s",
- devices[i]->device, location) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&retbuf, "cdrom://%s:%s",
+ devices[i]->device, location);
} else {
/* this wasnt the CD we were looking for, clean up and */
/* try the next CD drive */
@@ -439,13 +421,10 @@ static char *setupCdrom(char *location, struct loaderData_s *loaderData,
if (interactive) {
char * buf;
- if (asprintf(&buf, _("The %s disc was not found in any of your "
- "CDROM drives. Please insert the %s disc "
- "and press %s to retry."),
- getProductName(), getProductName(), _("OK")) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, _("The %s disc was not found in any of your "
+ "CDROM drives. Please insert the %s disc "
+ "and press %s to retry."),
+ getProductName(), getProductName(), _("OK"));
ejectCdrom(cddev);
rc = newtWinChoice(_("Disc Not Found"),
diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index 8c8cc93dc..5f8d43c53 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -146,15 +146,8 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
location->title = strdup(title);
location->version = version;
- if (asprintf(&location->path, "/tmp/DD-%d/modules.cgz", disknum) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
- if (asprintf(&fwdir, "/tmp/DD-%d/firmware", disknum) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&location->path, "/tmp/DD-%d/modules.cgz", disknum);
+ checked_asprintf(&fwdir, "/tmp/DD-%d/firmware", disknum);
if (!access(fwdir, R_OK|X_OK)) {
add_fw_search_dir(loaderData, fwdir);
@@ -349,12 +342,9 @@ int loadDriverFromMedia(int class, struct loaderData_s *loaderData,
case DEV_INSERT: {
char * buf;
- if (asprintf(&buf,
- _("Insert your driver disk into /dev/%s "
- "and press \"OK\" to continue."), device) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf,
+ _("Insert your driver disk into /dev/%s "
+ "and press \"OK\" to continue."), device);
rc = newtWinChoice(_("Insert Driver Disk"), _("OK"), _("Back"),
buf);
diff --git a/loader/driverselect.c b/loader/driverselect.c
index 3db9dc429..f9379f0a4 100644
--- a/loader/driverselect.c
+++ b/loader/driverselect.c
@@ -63,14 +63,11 @@ static int getManualModuleArgs(struct moduleInfo * mod, gchar *** moduleArgs) {
}
f = newtForm(NULL, NULL, 0);
- if (asprintf(&buf,
- _("Please enter any parameters which you wish to pass "
- "to the %s module separated by spaces. If you don't "
- "know what parameters to supply, skip this screen "
- "by pressing the \"OK\" button."), mod->moduleName) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf,
+ _("Please enter any parameters which you wish to pass "
+ "to the %s module separated by spaces. If you don't "
+ "know what parameters to supply, skip this screen "
+ "by pressing the \"OK\" button."), mod->moduleName);
text = newtTextboxReflowed(-1, -1, buf, 60, 0, 10, 0);
entry = newtEntry(-1, -1, argsEntry, 50, (const char **) &argsEntry,
@@ -188,12 +185,9 @@ int chooseManualDriver(int class, struct loaderData_s *loaderData) {
for (i = 0; i < numSorted; i++) {
char *buf = NULL;
- if (asprintf(&buf, "%s (%s)",
- modInfo->moduleList[sortedOrder[i].index].description,
- modInfo->moduleList[sortedOrder[i].index].moduleName) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, "%s (%s)",
+ modInfo->moduleList[sortedOrder[i].index].description,
+ modInfo->moduleList[sortedOrder[i].index].moduleName);
newtListboxAppendEntry(listbox, buf,
INT_TO_POINTER(sortedOrder[i].index));
diff --git a/loader/hardware.c b/loader/hardware.c
index 1f329055d..93fb0f8c0 100644
--- a/loader/hardware.c
+++ b/loader/hardware.c
@@ -84,10 +84,7 @@ static int detectHardware() {
close(fd);
if (timeout) {
- if (asprintf(&args[2], "--timeout=%d", timeout) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&args[2], "--timeout=%d", timeout);
}
rc = execv("/sbin/udevadm", args);
diff --git a/loader/hdinstall.c b/loader/hdinstall.c
index c523f1c5c..d5b6138a5 100644
--- a/loader/hdinstall.c
+++ b/loader/hdinstall.c
@@ -67,16 +67,9 @@ static char * setupIsoImages(char * device, char * dirName, char * location) {
if (doPwMount(device, "/mnt/isodir", "auto", "ro", NULL))
return NULL;
- if (asprintf(&dirspec, "/mnt/isodir%.*s",
- (int) (strrchr(dirName, '/') - dirName), dirName) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
- if (asprintf(&path, "/mnt/isodir%s", dirName) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&dirspec, "/mnt/isodir%.*s",
+ (int) (strrchr(dirName, '/') - dirName), dirName);
+ checked_asprintf(&path, "/mnt/isodir%s", dirName);
if (path) {
logMessage(INFO, "Path to stage2 image is %s", path);
@@ -92,19 +85,13 @@ static char * setupIsoImages(char * device, char * dirName, char * location) {
goto err;
}
- if (asprintf(&updpath, "%s/updates.img", dirspec) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&updpath, "%s/updates.img", dirspec);
logMessage(INFO, "Looking for updates for HD in %s", updpath);
copyUpdatesImg(updpath);
free(updpath);
- if (asprintf(&updpath, "%s/product.img", dirspec) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&updpath, "%s/product.img", dirspec);
logMessage(INFO, "Looking for product for HD in %s", updpath);
copyProductImg(updpath);
@@ -113,11 +100,8 @@ static char * setupIsoImages(char * device, char * dirName, char * location) {
free(dirspec);
umount("/mnt/isodir");
- if (asprintf(&url, "hd:%s:/%s", device,
- dirName ? dirName : ".") == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&url, "hd:%s:/%s", device,
+ dirName ? dirName : ".");
return url;
} else {
@@ -233,15 +217,12 @@ char * mountHardDrive(struct installMethod * method,
}
/* now find out which partition has the stage2 image */
- if (asprintf(&buf, _("What partition and directory on that "
- "partition holds the installation image "
- "for %s? If you don't see the disk drive "
- "you're using listed here, press F2 to "
- "configure additional devices."),
- getProductName()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, _("What partition and directory on that "
+ "partition holds the installation image "
+ "for %s? If you don't see the disk drive "
+ "you're using listed here, press F2 to "
+ "configure additional devices."),
+ getProductName());
text = newtTextboxReflowed(-1, -1, buf, 62, 5, 5, 0);
free(buf);
@@ -327,10 +308,7 @@ char * mountHardDrive(struct installMethod * method,
*/
substr = strstr(dir, ".img");
if (!substr || (substr && *(substr+4) != '\0')) {
- if (asprintf(&dir, "%s/images/install.img", dir) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&dir, "%s/images/install.img", dir);
}
loaderData->invalidRepoParam = 1;
diff --git a/loader/lang.c b/loader/lang.c
index 4b1103d65..390df2e60 100644
--- a/loader/lang.c
+++ b/loader/lang.c
@@ -262,10 +262,7 @@ static int setupLanguage(int choice, int forced) {
newtDrawRootText(0, 0, buf);
char *fmt = FL_RESCUE(flags) ? _(topLineWelcomeRescue) : _(topLineWelcome);
- if (asprintf(&buf, fmt, getProductName(), getProductArch()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, fmt, getProductName(), getProductArch());
newtDrawRootText(0, 0, buf);
free(buf);
diff --git a/loader/loader.c b/loader/loader.c
index e78419e07..cd3e17864 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -189,10 +189,7 @@ void doGdbserver(struct loaderData_s *loaderData) {
return;
}
- if (asprintf(&pid, "%d", loaderPid) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&pid, "%d", loaderPid);
if (!(child = fork())) {
logMessage(INFO, "starting gdbserver: %s %s %s %s",
@@ -224,11 +221,7 @@ void startNewt(void) {
char *buf;
char *arch = getProductArch();
- if (asprintf(&buf, _("Welcome to %s for %s"), getProductName(),
- arch) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, _("Welcome to %s for %s"), getProductName(), arch);
newtInit();
newtCls();
@@ -483,10 +476,7 @@ void loadUpdates(struct loaderData_s *loaderData) {
if (dir == -1) {
stage = UPD_DEVICE;
} else {
- if (asprintf(&part, "/dev/%s", device) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&part, "/dev/%s", device);
stage = UPD_PROMPT;
}
@@ -514,11 +504,8 @@ void loadUpdates(struct loaderData_s *loaderData) {
}
case UPD_PROMPT:
- if (asprintf(&buf, _("Insert your updates disk into %s and "
- "press \"OK\" to continue."), part) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, _("Insert your updates disk into %s and "
+ "press \"OK\" to continue."), part);
rc = newtWinChoice(_("Updates Disk"), _("OK"), _("Back"), buf);
free(buf);
@@ -654,11 +641,8 @@ static void readNetInfo(struct loaderData_s ** ld) {
while ((ent = readdir(dp)) != NULL) {
if (!strncmp(ent->d_name, "ifcfg-", 6)) {
- if (asprintf(&cfgfile, "/etc/sysconfig/network-scripts/%s",
- ent->d_name) == -1) {
- logMessage(DEBUGLVL, "%s (%d): %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&cfgfile, "/etc/sysconfig/network-scripts/%s",
+ ent->d_name);
break;
}
@@ -1150,19 +1134,13 @@ static void parseCmdLineFlags(struct loaderData_s * loaderData,
}
if (!strncasecmp(argv[i], "vesa", 4)) {
- if (asprintf(&extraArgs[numExtraArgs],
- "--xdriver=vesa") == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&extraArgs[numExtraArgs],
+ "--xdriver=vesa");
logMessage(WARNING, "\"vesa\" command line argument is deprecated. use \"xdriver=vesa\".");
} else {
- if (asprintf(&extraArgs[numExtraArgs],"--%s",
- argv[i]) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&extraArgs[numExtraArgs],"--%s",
+ argv[i]);
}
numExtraArgs += 1;
@@ -1189,11 +1167,8 @@ static void checkForRam(void) {
if (totalMemory() < MIN_RAM) {
char *buf;
- if (asprintf(&buf, _("You do not have enough RAM to install %s "
- "on this machine."), getProductName()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, _("You do not have enough RAM to install %s "
+ "on this machine."), getProductName());
startNewt();
newtWinMessage(_("Error"), _("OK"), buf);
@@ -1260,11 +1235,8 @@ static char *doLoaderMain(struct loaderData_s *loaderData,
*/
char *tmp;
- if (asprintf(&tmp, "%s/images/install.img",
- loaderData->instRepo) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&tmp, "%s/images/install.img",
+ loaderData->instRepo);
logMessage(INFO, "no stage2= given, assuming %s", tmp);
setStage2LocFromCmdline(tmp, loaderData);
@@ -1604,12 +1576,9 @@ static char *doLoaderMain(struct loaderData_s *loaderData,
/* Doesn't contain /images? Let's not even try. */
if (strstr(url, "/images") == NULL)
break;
-
- if (asprintf(&newInstRepo, "%.*s",
- (int) (strstr(url, "/images")-url), url) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+
+ checked_asprintf(&newInstRepo, "%.*s",
+ (int) (strstr(url, "/images")-url), url);
free(loaderData->instRepo);
loaderData->instRepo = newInstRepo;
@@ -1675,19 +1644,13 @@ static void migrate_runtime_directory(char * dirname) {
char * runtimedir;
int ret;
- if (asprintf(&runtimedir, "/mnt/runtime%s", dirname) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&runtimedir, "/mnt/runtime%s", dirname);
if (!access(runtimedir, X_OK)) {
if (unlink(dirname) == -1) {
char * olddir;
-
- if (asprintf(&olddir, "%s_old", dirname) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+
+ checked_asprintf(&olddir, "%s_old", dirname);
ret = rename(dirname, olddir);
free(olddir);
@@ -1790,10 +1753,7 @@ static void add_to_path_env(const char *env, const char *val)
oldenv = getenv(env);
if (oldenv) {
- if (asprintf(&newenv, "%s:%s", val, oldenv) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&newenv, "%s:%s", val, oldenv);
oldenv = strdupa(newenv);
free(newenv);
@@ -2134,10 +2094,7 @@ int main(int argc, char ** argv) {
c = path[n];
path[n] = '\0';
- if (asprintf(&binpath, "%s/anaconda", path) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&binpath, "%s/anaconda", path);
path[n] = c;
if (!access(binpath, X_OK)) {
diff --git a/loader/loader.h b/loader/loader.h
index 910afd606..ebf3766a8 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -182,4 +182,10 @@ struct loaderData_s {
#define LIBPATH "/lib:/usr/lib:/usr/X11R6/lib:/usr/kerberos/lib:/mnt/usr/lib:/mnt/sysimage/lib:/mnt/sysimage/usr/lib"
#endif
+#define checked_asprintf(...) \
+ if (asprintf( __VA_ARGS__ ) == -1) { \
+ logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); \
+ abort(); \
+ }
+
#endif
diff --git a/loader/method.c b/loader/method.c
index 90f06873a..3330c2412 100644
--- a/loader/method.c
+++ b/loader/method.c
@@ -88,10 +88,7 @@ int mountLoopback(char *fsystem, char *mntpoint, char *device) {
return LOADER_ERROR;
}
- if (asprintf(&opts, "ro,loop=%s", device) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&opts, "ro,loop=%s", device);
if (doPwMount(fsystem, mntpoint, "auto", opts, &err)) {
logMessage(ERROR, "failed to mount loopback device %s on %s as %s: %s",
diff --git a/loader/net.c b/loader/net.c
index 4f49d8f44..43de50f51 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -954,15 +954,12 @@ int manualNetConfig(char * device, iface_t * iface,
/* main window layout */
grid = newtCreateGrid(1, 3);
- if (asprintf(&buf,
- _("Enter the IPv4 and/or the IPv6 address and prefix "
- "(address / prefix). For IPv4, the dotted-quad "
- "netmask or the CIDR-style prefix are acceptable. "
- "The gateway and name server fields must be valid IPv4 "
- "or IPv6 addresses.")) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf,
+ _("Enter the IPv4 and/or the IPv6 address and prefix "
+ "(address / prefix). For IPv4, the dotted-quad "
+ "netmask or the CIDR-style prefix are acceptable. "
+ "The gateway and name server fields must be valid IPv4 "
+ "or IPv6 addresses."));
text = newtTextboxReflowed(-1, -1, buf, 52, 0, 10, 0);
@@ -1156,19 +1153,13 @@ int writeDisabledNetInfo(void) {
}
/* write disabled ifcfg-DEVICE file */
- if (asprintf(&ofile, "%s/.ifcfg-%s",
- NETWORK_SCRIPTS_PATH,
- devs[i]->device) == -1) {
- logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
- abort();
- }
-
- if (asprintf(&nfile, "%s/ifcfg-%s",
- NETWORK_SCRIPTS_PATH,
- devs[i]->device) == -1) {
- logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
- abort();
- }
+
+ 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);
@@ -1865,16 +1856,13 @@ int chooseNetworkInterface(struct loaderData_s * loaderData) {
continue;
}
- if (asprintf(&idstr, "%s %s %s",
- _("You can identify the physical port for"),
- devices[deviceNum],
- _("by flashing the LED lights for a number of "
- "seconds. Enter a number between 1 and 30 to "
- "set the duration to flash the LED port "
- "lights.")) == -1) {
- logMessage(ERROR, "asprintf() failure in %s: %m", __func__);
- abort();
- }
+ checked_asprintf(&idstr, "%s %s %s",
+ _("You can identify the physical port for"),
+ devices[deviceNum],
+ _("by flashing the LED lights for a number of "
+ "seconds. Enter a number between 1 and 30 to "
+ "set the duration to flash the LED port "
+ "lights."));
i = 1;
while (i) {
diff --git a/loader/nfsinstall.c b/loader/nfsinstall.c
index cabad46ba..ce9e8eabd 100644
--- a/loader/nfsinstall.c
+++ b/loader/nfsinstall.c
@@ -67,24 +67,16 @@ static int nfsGetSetup(char ** hostptr, char ** dirptr) {
entries[0].text = _("NFS server name:");
entries[0].value = &newServer;
entries[0].flags = NEWT_FLAG_SCROLL;
-
- if (asprintf(&entries[1].text, _("%s directory:"),
- getProductName()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+
+ checked_asprintf(&entries[1].text, _("%s directory:"), getProductName());
entries[1].value = &newDir;
entries[1].flags = NEWT_FLAG_SCROLL;
entries[2].text = NULL;
entries[2].value = NULL;
- if (asprintf(&buf, _("Please enter the server name and path to your %s "
- "installation image."), getProductName()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
+ checked_asprintf(&buf, _("Please enter the server name and path to your %s "
+ "installation image."), getProductName());
do {
rc = newtWinEntries(_("NFS Setup"), buf, 60, 5, 15,
24, entries, _("OK"), _("Back"), NULL);
@@ -148,11 +140,7 @@ static void addDefaultKickstartFile(char **file, char *ip) {
*/
if ((*file) && (((*file)[strlen(*file) - 1] == '/') ||
((*file)[strlen(*file) - 1] == '\0'))) {
- if (asprintf(file, "%s%s-kickstart", *file, ip) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
+ checked_asprintf(file, "%s%s-kickstart", *file, ip);
logMessage(DEBUGLVL, "addDefaultKickstartFile file: |%s|", *file);
}
}
@@ -183,12 +171,9 @@ char * mountNfsImage(struct installMethod * method,
loaderData->stage2Data)->mountOpts == NULL) {
mountOpts = strdup("ro");
} else {
- if (asprintf(&mountOpts, "ro,%s",
- ((struct nfsInstallData *)
- loaderData->stage2Data)->mountOpts) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&mountOpts, "ro,%s",
+ ((struct nfsInstallData *)
+ loaderData->stage2Data)->mountOpts);
}
logMessage(INFO, "host is %s, dir is %s, opts are '%s'", host, directory, mountOpts);
@@ -218,18 +203,10 @@ char * mountNfsImage(struct installMethod * method,
*/
substr = strstr(directory, ".img");
if (!substr || (substr && *(substr+4) != '\0')) {
- if (asprintf(&(loaderData->instRepo), "nfs:%s:%s",
- host, directory) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
- if (asprintf(&tmp, "nfs:%s:%s/images/install.img",
- host, directory) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
+ checked_asprintf(&(loaderData->instRepo), "nfs:%s:%s",
+ host, directory);
+ checked_asprintf(&tmp, "nfs:%s:%s/images/install.img",
+ host, directory);
setStage2LocFromCmdline(tmp, loaderData);
free(host);
free(directory);
@@ -246,13 +223,9 @@ char * mountNfsImage(struct installMethod * method,
case NFS_STAGE_MOUNT: {
char *buf;
- if (asprintf(&fullPath, "%s:%.*s", host,
- (int) (strrchr(directory, '/')-directory),
- directory) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
+ checked_asprintf(&fullPath, "%s:%.*s", host,
+ (int) (strrchr(directory, '/')-directory),
+ directory);
logMessage(INFO, "mounting nfs path %s", fullPath);
if (FL_TESTING(flags)) {
@@ -263,11 +236,8 @@ char * mountNfsImage(struct installMethod * method,
stage = NFS_STAGE_NFS;
if (!doPwMount(fullPath, "/mnt/stage2", "nfs", mountOpts, NULL)) {
- if (asprintf(&buf, "/mnt/stage2/%s",
- strrchr(directory, '/')) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, "/mnt/stage2/%s",
+ strrchr(directory, '/'));
if (!access(buf, R_OK)) {
logMessage(INFO, "can access %s", buf);
@@ -275,14 +245,8 @@ char * mountNfsImage(struct installMethod * method,
if (rc == 0) {
stage = NFS_STAGE_UPDATES;
-
- if (asprintf(&url, "nfs:%s:%s", host,
- directory) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__,
- __LINE__);
- abort();
- }
-
+ checked_asprintf(&url, "nfs:%s:%s", host,
+ directory);
free(buf);
break;
} else {
@@ -308,12 +272,10 @@ char * mountNfsImage(struct installMethod * method,
break;
}
- if (asprintf(&buf, _("That directory does not seem to "
- "contain a %s installation image."),
- getProductName()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf,
+ _("That directory does not seem to "
+ "contain a %s installation image."),
+ getProductName());
newtWinMessage(_("Error"), _("OK"), buf);
free(buf);
@@ -330,12 +292,9 @@ char * mountNfsImage(struct installMethod * method,
case NFS_STAGE_UPDATES: {
char *buf;
- if (asprintf(&buf, "%.*s/RHupdates",
- (int) (strrchr(fullPath, '/')-fullPath),
- fullPath) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, "%.*s/RHupdates",
+ (int) (strrchr(fullPath, '/')-fullPath),
+ fullPath);
logMessage(INFO, "mounting nfs path %s for updates", buf);
@@ -406,10 +365,7 @@ void setKickstartNfs(struct loaderData_s * loaderData, int argc,
substr = strstr(dir, ".img");
if (!substr || (substr && *(substr+4) != '\0')) {
- if (asprintf(&(loaderData->instRepo), "nfs:%s:%s", host, dir) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&(loaderData->instRepo), "nfs:%s:%s", host, dir);
logMessage(INFO, "results of nfs, host is %s, dir is %s, opts are '%s'",
host, dir, mountOpts);
@@ -507,18 +463,10 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
filename = nm_dhcp4_config_get_one_option(dhcp, "filename");
if (filename == NULL) {
- if (asprintf(&url, "%s:/kickstart/", nextserver) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
+ checked_asprintf(&url, "%s:/kickstart/", nextserver);
logMessage(ERROR, "bootp: no bootfile received");
} else {
- if (asprintf(&url, "%s:%s", nextserver, filename) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
-
+ checked_asprintf(&url, "%s:%s", nextserver, filename);
logMessage(INFO, "bootp: bootfile is %s", filename);
}
@@ -549,15 +497,9 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
chk = host + strlen(host)-1;
if (*chk == '/' || *path == '/') {
- if (asprintf(&host, "%s:%s", host, path) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&host, "%s:%s", host, path);
} else {
- if (asprintf(&host, "%s:/%s", host, path) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&host, "%s:/%s", host, path);
}
}
@@ -566,10 +508,7 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
if (!doPwMount(host, "/tmp/mnt", "nfs", opts, NULL)) {
char * buf;
- if (asprintf(&buf, "/tmp/mnt/%s", file) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf, "/tmp/mnt/%s", file);
if (copyFile(buf, dest)) {
logMessage(ERROR, "failed to copy file to %s", dest);
diff --git a/loader/urlinstall.c b/loader/urlinstall.c
index 8279ec9f6..519d08c3f 100644
--- a/loader/urlinstall.c
+++ b/loader/urlinstall.c
@@ -66,15 +66,9 @@ static char **headers() {
logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
abort();
}
-
- if (asprintf(&extraHeaders[0], "X-Anaconda-Architecture: %s", getProductArch()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
- if (asprintf(&extraHeaders[1], "X-Anaconda-System-Release: %s", getProductName()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+
+ checked_asprintf(&extraHeaders[0], "X-Anaconda-Architecture: %s", getProductArch());
+ checked_asprintf(&extraHeaders[1], "X-Anaconda-System-Release: %s", getProductName());
if (FL_KICKSTART_SEND_MAC(flags)) {
/* find all ethernet devices and make a header entry for each one */
@@ -89,11 +83,8 @@ static char **headers() {
if (mac) {
extraHeaders = realloc(extraHeaders, (len+1)*sizeof(char *));
- if (asprintf(&extraHeaders[len], "X-RHN-Provisioning-MAC-%d: %s %s",
- i, dev, mac) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&extraHeaders[len], "X-RHN-Provisioning-MAC-%d: %s %s",
+ i, dev, mac);
len++;
free(mac);
@@ -122,10 +113,7 @@ static char **headers() {
extraHeaders = realloc(extraHeaders, (len+1)*sizeof(char *));
- if (asprintf(&extraHeaders[len], "X-System-Serial-Number: %s", sn) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&extraHeaders[len], "X-System-Serial-Number: %s", sn);
len++;
}
@@ -190,10 +178,7 @@ static int loadUrlImages(struct loaderData_s *loaderData, struct iurlinfo *ui) {
/* grab the updates.img before install.img so that we minimize our
* ramdisk usage */
- if (asprintf(&ui->url, "%s/%s", path, "updates.img") == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&ui->url, "%s/%s", path, "updates.img");
if (!loadSingleUrlImage(loaderData, ui, "/tmp/updates-disk.img", "/tmp/update-disk",
"/dev/loop7", 1)) {
@@ -211,10 +196,7 @@ static int loadUrlImages(struct loaderData_s *loaderData, struct iurlinfo *ui) {
/* grab the product.img before install.img so that we minimize our
* ramdisk usage */
- if (asprintf(&ui->url, "%s/%s", path, "product.img") == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&ui->url, "%s/%s", path, "product.img");
if (!loadSingleUrlImage(loaderData, ui, "/tmp/product-disk.img", "/tmp/product-disk",
"/dev/loop7", 1)) {
@@ -228,10 +210,7 @@ static int loadUrlImages(struct loaderData_s *loaderData, struct iurlinfo *ui) {
free(ui->url);
ui->url = strdup(oldUrl);
- if (asprintf(&dest, "/tmp/install.img") == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&dest, "/tmp/install.img");
rc = loadSingleUrlImage(loaderData, ui, dest, "/mnt/runtime", "/dev/loop0", 0);
free(dest);
@@ -299,12 +278,8 @@ char *mountUrlImage(struct installMethod *method, char *location,
if (!substr || (substr && *(substr+4) != '\0')) {
loaderData->instRepo = strdup(ui.url);
- if (asprintf(&ui.url, "%s/images/install.img",
- ui.url) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__,
- __LINE__);
- abort();
- }
+ checked_asprintf(&ui.url, "%s/images/install.img",
+ ui.url);
}
loaderData->invalidRepoParam = 1;
diff --git a/loader/urls.c b/loader/urls.c
index ecf4a1b0c..f7d3e341e 100644
--- a/loader/urls.c
+++ b/loader/urls.c
@@ -118,10 +118,7 @@ int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
curl_global_init(CURL_GLOBAL_SSL);
curl = curl_easy_init();
- if (asprintf(&version, "anaconda/%s", VERSION) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&version, "anaconda/%s", VERSION);
curl_easy_setopt(curl, CURLOPT_USERAGENT, version);
curl_easy_setopt(curl, CURLOPT_URL, ui->url);
@@ -251,12 +248,9 @@ int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui) {
buttons = newtButtonBar(_("OK"), &okay, _("Back"), &cancel, NULL);
- if (asprintf(&buf,
- _("Please enter the URL containing the %s installation image on your server."),
- getProductName()) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ checked_asprintf(&buf,
+ _("Please enter the URL containing the %s installation image on your server."),
+ getProductName());
reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height);
free(buf);