Skip to content

Commit ba25a32

Browse files
committed
bin/xbps-fbulk: handle fopen/popen failures
1 parent e5e631f commit ba25a32

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

bin/xbps-fbulk/main.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ processCompletion(struct item *item)
232232
logpath = xbps_xasprintf("%s/deps/%s.txt",
233233
LogDir, xitem->pkgn);
234234
fp = fopen(logpath, "a");
235+
if (!fp) {
236+
xbps_error_printf(
237+
"failed to open file: %s: %s\n",
238+
logpath, strerror(errno));
239+
exit(EXIT_FAILURE);
240+
}
235241
fprintf(fp, "%s\n", item->pkgn);
236242
fclose(fp);
237243
free(logpath);
@@ -369,7 +375,13 @@ runBuilds(const char *bpath)
369375
*/
370376
item->xcode = -98;
371377
fp = fopen(logpath, "a");
372-
xbps_error_printf("xbps-fbulk: unable to fork/exec xbps-src\n");
378+
if (!fp) {
379+
xbps_error_printf(
380+
"failed to open file: %s: %s\n",
381+
logpath, strerror(errno));
382+
exit(EXIT_FAILURE);
383+
}
384+
fprintf(fp, "xbps-fbulk: unable to fork/exec xbps-src\n");
373385
fclose(fp);
374386
processCompletion(item);
375387
} else {
@@ -426,6 +438,12 @@ addDepn(struct item *item, struct item *xitem)
426438
logpath = xbps_xasprintf("%s/deps/%s.txt",
427439
LogDir, item->pkgn);
428440
fp = fopen(logpath, "a");
441+
if (!fp) {
442+
xbps_error_printf(
443+
"failed to open file: %s: %s\n", logpath,
444+
strerror(errno));
445+
exit(EXIT_FAILURE);
446+
}
429447
fprintf(fp, "%s\n", xitem->pkgn);
430448
fclose(fp);
431449
free(logpath);
@@ -461,6 +479,10 @@ ordered_depends(const char *bpath, const char *pkgn)
461479
snprintf(cmd, sizeof(cmd)-1,
462480
"%s/xbps-src show-build-deps %s 2>&1", bpath, pkgn);
463481
fp = popen(cmd, "r");
482+
if (!fp) {
483+
xbps_error_printf("faile to run xbps-src show-build-deps\n");
484+
exit(EXIT_FAILURE);
485+
}
464486
while (fgets(buf, sizeof(buf), fp) != NULL) {
465487
char dpath[PATH_MAX];
466488
size_t len;

0 commit comments

Comments
 (0)