Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Ubuntu Kernel Team (http://www.linux-archive.org/ubuntu-kernel-team/)
-   -   Introduces CHECK_ASPRINTF macro that checks asprintfs return value and terminates program in OOM scenarios. (http://www.linux-archive.org/ubuntu-kernel-team/280016-introduces-check_asprintf-macro-checks-asprintfs-return-value-terminates-program-oom-scenarios.html)

Ales Kozumplik 11-13-2009 03:22 PM

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.
---
loader/loader.h | 6 +++
loader/nfsinstall.c | 125 +++++++++++++--------------------------------------
2 files changed, 38 insertions(+), 93 deletions(-)

diff --git a/loader/loader.h b/loader/loader.h
index f942b7e..039c72a 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -185,4 +185,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/nfsinstall.c b/loader/nfsinstall.c
index e405df9..0eb3cbe 100644
--- a/loader/nfsinstall.c
+++ b/loader/nfsinstall.c
@@ -68,24 +68,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);
@@ -149,11 +141,7 @@ static void addDefaultKickstartFile(char **file, char *ip) {
*/
if ((*file) && (((*file)[strlen(*file) - 1] == '/') ||
((*file)[strlen(*file) - 1] == ''))) {
- 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);
}
}
@@ -184,12 +172,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);
@@ -219,18 +204,10 @@ char * mountNfsImage(struct installMethod * method,
*/
substr = strstr(directory, ".img");
if (!substr || (substr && *(substr+4) != '')) {
- 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);
@@ -247,13 +224,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)) {
@@ -264,11 +237,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);
@@ -276,14 +246,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 {
@@ -309,12 +273,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);
@@ -331,12 +293,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);

@@ -402,10 +361,7 @@ void setKickstartNfs(struct loaderData_s * loaderData, int argc,

substr = strstr(dir, ".img");
if (!substr || (substr && *(substr+4) != '')) {
- 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);
@@ -503,18 +459,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);
}

@@ -545,15 +493,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);
}
}

@@ -562,10 +504,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);
--
1.6.2.5

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

Ales Kozumplik 11-16-2009 08:14 AM

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.
---
loader/cdinstall.c | 45 +++++-------------
loader/copy.c | 32 +++---------
loader/driverdisk.c | 20 ++------
loader/driverselect.c | 22 +++------
loader/hardware.c | 5 +--
loader/hdinstall.c | 49 +++++--------------
loader/lang.c | 5 +--
loader/loader.c | 89 +++++++++--------------------------
loader/loader.h | 6 ++
loader/method.c | 5 +--
loader/net.c | 52 ++++++++-------------
loader/nfsinstall.c | 125 +++++++++++++------------------------------------
loader/urlinstall.c | 47 ++++--------------
loader/urls.c | 14 ++----
14 files changed, 145 insertions(+), 371 deletions(-)

diff --git a/loader/cdinstall.c b/loader/cdinstall.c
index d74396e..217528c 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/copy.c b/loader/copy.c
index 1c61233..35f2acf 100644
--- a/loader/copy.c
+++ b/loader/copy.c
@@ -48,14 +48,10 @@ int copyDirectory(char * from, char * to, void (*warnFn)(char *),

if (!(dir = opendir(from))) {
if (errorFn) {
- if (asprintf(&msg, N_("Failed to read directory %s: %m"), from) == -1) {
- fprintf(stderr, "%s: %d: %m
", __func__, __LINE__);
- fflush(stderr);
- abort();
- }
-
- errorFn(msg);
- free(msg);
+ CHECKED_ASPRINTF(&msg, N_("Failed to read directory %s: %m"), from);
+
+ errorFn(msg);
+ free(msg);
}

return 1;
@@ -81,12 +77,8 @@ int copyDirectory(char * from, char * to, void (*warnFn)(char *),
link[i] = '';
if (symlink(link, filespec2)) {
if (warnFn) {
- if (asprintf(&msg, "Failed to symlink %s to %s: %m",
- filespec2, link) == -1) {
- fprintf(stderr, "%s: %d: %m
", __func__, __LINE__);
- fflush(stderr);
- abort();
- }
+ CHECKED_ASPRINTF(&msg, "Failed to symlink %s to %s: %m",
+ filespec2, link);

warnFn(msg);
free(msg);
@@ -96,11 +88,7 @@ int copyDirectory(char * from, char * to, void (*warnFn)(char *),
fd = open(filespec, O_RDONLY);
if (fd == -1) {
if (errorFn) {
- if (asprintf(&msg, "Failed to open %s: %m", filespec) == -1) {
- fprintf(stderr, "%s: %d: %m
", __func__, __LINE__);
- fflush(stderr);
- abort();
- }
+ CHECKED_ASPRINTF(&msg, "Failed to open %s: %m", filespec);

errorFn(msg);
free(msg);
@@ -112,11 +100,7 @@ int copyDirectory(char * from, char * to, void (*warnFn)(char *),
outfd = open(filespec2, O_RDWR | O_TRUNC | O_CREAT, 0644);
if (outfd == -1) {
if (warnFn) {
- if (asprintf(&msg, "Failed to create %s: %m", filespec2) == -1) {
- fprintf(stderr, "%s: %d: %m
", __func__, __LINE__);
- fflush(stderr);
- abort();
- }
+ CHECKED_ASPRINTF(&msg, "Failed to create %s: %m", filespec2);

warnFn(msg);
free(msg);
diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index e5d8f90..3a6f497 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 28f5ffd..82e9fd4 100644
--- a/loader/driverselect.c
+++ b/loader/driverselect.c
@@ -63,14 +63,11 @@ static int getManualModuleArgs(struct moduleInfo * mod, char *** 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,
@@ -212,12 +209,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 e9be279..3ffcde0 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 a4396df..5b17c13 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,11 @@ 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."));

text = newtTextboxReflowed(-1, -1, buf, 62, 5, 5, 0);
free(buf);
@@ -327,10 +307,7 @@ char * mountHardDrive(struct installMethod * method,
*/
substr = strstr(dir, ".img");
if (!substr || (substr && *(substr+4) != '')) {
- 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 4b1103d..e72cadb 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 dea600f..26d8d2c 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -190,10 +190,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",
@@ -225,11 +222,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();
@@ -476,10 +469,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;
}

@@ -507,11 +497,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);
@@ -647,11 +634,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;
}
@@ -1140,19 +1124,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;
@@ -1179,11 +1157,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);
@@ -1250,11 +1225,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);
@@ -1594,12 +1566,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;
@@ -1665,19 +1634,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);
@@ -1780,10 +1743,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);
@@ -2115,10 +2075,7 @@ int main(int argc, char ** argv) {

c = path[n];
path[n] = '';
- 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 f942b7e..8345708 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -185,4 +185,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 ebfe557..029b7a0 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 9280dc7..ff00843 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -955,15 +955,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);

@@ -1157,19 +1154,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);
@@ -1885,16 +1876,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 e405df9..0eb3cbe 100644
--- a/loader/nfsinstall.c
+++ b/loader/nfsinstall.c
@@ -68,24 +68,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);
@@ -149,11 +141,7 @@ static void addDefaultKickstartFile(char **file, char *ip) {
*/
if ((*file) && (((*file)[strlen(*file) - 1] == '/') ||
((*file)[strlen(*file) - 1] == ''))) {
- 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);
}
}
@@ -184,12 +172,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);
@@ -219,18 +204,10 @@ char * mountNfsImage(struct installMethod * method,
*/
substr = strstr(directory, ".img");
if (!substr || (substr && *(substr+4) != '')) {
- 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);
@@ -247,13 +224,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)) {
@@ -264,11 +237,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);
@@ -276,14 +246,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 {
@@ -309,12 +273,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);
@@ -331,12 +293,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);

@@ -402,10 +361,7 @@ void setKickstartNfs(struct loaderData_s * loaderData, int argc,

substr = strstr(dir, ".img");
if (!substr || (substr && *(substr+4) != '')) {
- 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);
@@ -503,18 +459,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);
}

@@ -545,15 +493,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);
}
}

@@ -562,10 +504,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 b03efce..67108b5 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) != '')) {
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 efdbd82..8a05040 100644
--- a/loader/urls.c
+++ b/loader/urls.c
@@ -117,10 +117,7 @@ int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
*/
curl_easy_reset(loaderData->curl);

- if (asprintf(&version, "anaconda/%s", VERSION) == -1) {
- logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
- abort();
- }
+ CHECKED_ASPRINTF(&version, "anaconda/%s", VERSION);

curl_easy_setopt(loaderData->curl, CURLOPT_USERAGENT, version);
curl_easy_setopt(loaderData->curl, CURLOPT_URL, ui->url);
@@ -247,12 +244,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);
--
1.6.2.5

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


All times are GMT. The time now is 12:57 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.