Module Name: src
Committed By: sjg
Date: Sun Oct 24 18:45:46 UTC 2021
Modified Files:
src/usr.bin/make: job.c meta.c
Log Message:
Do not ignore write failures.
We should not ignore failure to write to cmdFILE,
meta files and filemon.
Reviewed by: rillig
To generate a diff of this commit:
cvs rdiff -u -r1.435 -r1.436 src/usr.bin/make/job.c
cvs rdiff -u -r1.183 -r1.184 src/usr.bin/make/meta.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.435 src/usr.bin/make/job.c:1.436
--- src/usr.bin/make/job.c:1.435 Wed Jun 16 09:47:51 2021
+++ src/usr.bin/make/job.c Sun Oct 24 18:45:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.435 2021/06/16 09:47:51 rillig Exp $ */
+/* $NetBSD: job.c,v 1.436 2021/10/24 18:45:46 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.435 2021/06/16 09:47:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.436 2021/10/24 18:45:46 sjg Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -765,8 +765,8 @@ ShellWriter_WriteFmt(ShellWriter *wr, co
DEBUG1(JOB, fmt, arg);
(void)fprintf(wr->f, fmt, arg);
- /* XXX: Is flushing needed in any case, or only if f == stdout? */
- (void)fflush(wr->f);
+ if (wr->f == stdout)
+ (void)fflush(wr->f);
}
static void
@@ -1163,7 +1163,9 @@ JobFinish(Job *job, int status)
JobClosePipes(job);
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
- (void)fclose(job->cmdFILE);
+ if (fclose(job->cmdFILE) != 0)
+ Punt("Cannot write shell script for '%s': %s",
+ job->node->name, strerror(errno));
job->cmdFILE = NULL;
}
done = true;
@@ -1526,7 +1528,9 @@ JobExec(Job *job, char **argv)
watchfd(job);
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
- (void)fclose(job->cmdFILE);
+ if (fclose(job->cmdFILE) != 0)
+ Punt("Cannot write shell script for '%s': %s",
+ job->node->name, strerror(errno));
job->cmdFILE = NULL;
}
Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.183 src/usr.bin/make/meta.c:1.184
--- src/usr.bin/make/meta.c:1.183 Thu Aug 19 15:50:30 2021
+++ src/usr.bin/make/meta.c Sun Oct 24 18:45:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.183 2021/08/19 15:50:30 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.184 2021/10/24 18:45:46 sjg Exp $ */
/*
* Implement 'meta' mode.
@@ -145,11 +145,11 @@ meta_open_filemon(BuildMon *pbm)
else
pbm->mon_fd = mkTempFile("filemon.XXXXXX", NULL, 0);
if ((dupfd = dup(pbm->mon_fd)) == -1) {
- err(1, "Could not dup filemon output!");
+ Punt("Could not dup filemon output: %s", strerror(errno));
}
(void)fcntl(dupfd, F_SETFD, FD_CLOEXEC);
if (filemon_setfd(pbm->filemon, dupfd) == -1) {
- err(1, "Could not set filemon file descriptor!");
+ Punt("Could not set filemon file descriptor: %s", strerror(errno));
}
/* we don't need these once we exec */
(void)fcntl(pbm->mon_fd, F_SETFD, FD_CLOEXEC);
@@ -187,7 +187,9 @@ filemon_read(FILE *mfp, int fd)
error = EIO;
}
}
- fflush(mfp);
+ if (fflush(mfp) != 0)
+ Punt("Cannot write filemon data to meta file: %s",
+ strerror(errno));
if (close(fd) < 0)
error = errno;
return error;
@@ -518,7 +520,7 @@ meta_create(BuildMon *pbm, GNode *gn)
#endif
if ((fp = fopen(fname, "w")) == NULL)
- err(1, "Could not open meta file '%s'", fname);
+ Punt("Could not open meta file '%s': %s", fname, strerror(errno));
fprintf(fp, "# Meta data file %s\n", fname);
@@ -536,7 +538,9 @@ meta_create(BuildMon *pbm, GNode *gn)
}
fprintf(fp, "-- command output --\n");
- fflush(fp);
+ if (fflush(fp) != 0)
+ Punt("Cannot write expanded command to meta file: %s",
+ strerror(errno));
Global_Append(".MAKE.META.FILES", fname);
Global_Append(".MAKE.META.CREATED", fname);
@@ -710,7 +714,7 @@ meta_job_child(Job *job)
pid = getpid();
if (filemon_setpid_child(pbm->filemon, pid) == -1) {
- err(1, "Could not set filemon pid!");
+ Punt("Could not set filemon pid: %s", strerror(errno));
}
}
}
@@ -850,8 +854,10 @@ meta_cmd_finish(void *pbmp)
if (pbm->filemon != NULL) {
while (filemon_process(pbm->filemon) > 0)
continue;
- if (filemon_close(pbm->filemon) == -1)
+ if (filemon_close(pbm->filemon) == -1) {
error = errno;
+ Punt("filemon failed: %s", strerror(errno));
+ }
x = filemon_read(pbm->mfp, pbm->mon_fd);
if (error == 0 && x != 0)
error = x;