Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make Do not ignore write failures.



details:   https://anonhg.NetBSD.org/src/rev/83d7d2e51555
branches:  trunk
changeset: 990041:83d7d2e51555
user:      sjg <sjg%NetBSD.org@localhost>
date:      Sun Oct 24 18:45:46 2021 +0000

description:
Do not ignore write failures.

We should not ignore failure to write to cmdFILE,
meta files and filemon.

Reviewed by: rillig

diffstat:

 usr.bin/make/job.c  |  16 ++++++++++------
 usr.bin/make/meta.c |  22 ++++++++++++++--------
 2 files changed, 24 insertions(+), 14 deletions(-)

diffs (126 lines):

diff -r df3a77cbbcfb -r 83d7d2e51555 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sun Oct 24 17:51:19 2021 +0000
+++ b/usr.bin/make/job.c        Sun Oct 24 18:45:46 2021 +0000
@@ -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 @@
        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 @@
 
                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 @@
        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;
        }
 
diff -r df3a77cbbcfb -r 83d7d2e51555 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Sun Oct 24 17:51:19 2021 +0000
+++ b/usr.bin/make/meta.c       Sun Oct 24 18:45:46 2021 +0000
@@ -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 @@
     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 @@
                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 @@
 #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 @@
     }
 
     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 @@
 
            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 @@
     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;



Home | Main Index | Thread Index | Old Index