Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make 1. the tfile patch was incorrect. If we are doi...



details:   https://anonhg.NetBSD.org/src/rev/a07feb99dc91
branches:  trunk
changeset: 499969:a07feb99dc91
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Dec 03 01:27:03 2000 +0000

description:
1. the tfile patch was incorrect. If we are doing multiple jobs, we
   try to open tfile many times, passing bad strings to mkstemp
2. remove extra semicolon after the MESSAGE macro
3. more error checking
4. be more careful about setting things to NULL after freeing.
5. fix a comment that does not apply anymore

diffstat:

 usr.bin/make/job.c |  39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)

diffs (133 lines):

diff -r 3440a6c13a28 -r a07feb99dc91 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sun Dec 03 01:18:15 2000 +0000
+++ b/usr.bin/make/job.c        Sun Dec 03 01:27:03 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.33 2000/04/20 11:23:25 sjg Exp $     */
+/*     $NetBSD: job.c,v 1.34 2000/12/03 01:27:03 christos Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -39,14 +39,14 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: job.c,v 1.33 2000/04/20 11:23:25 sjg Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.34 2000/12/03 01:27:03 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c      8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.33 2000/04/20 11:23:25 sjg Exp $");
+__RCSID("$NetBSD: job.c,v 1.34 2000/12/03 01:27:03 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -166,13 +166,6 @@
 #define JOB_FINISHED   2       /* The job is already finished */
 #define JOB_STOPPED    3       /* The job is stopped */
 
-/*
- * tfile is the name of a file into which all shell commands are put. It is
- * used over by removing it before the child shell is executed. The XXXXX in
- * the string are replaced by the pid of the make process in a 5-character
- * field with leading zeroes.
- */
-static char     tfile[] = TMPPAT;
 
 
 /*
@@ -253,11 +246,11 @@
 #ifdef REMOTE
 # define TARG_FMT  "--- %s at %s ---\n" /* Default format */
 # define MESSAGE(fp, gn) \
-       (void) fprintf(fp, targFmt, gn->name, gn->rem.hname);
+       (void) fprintf(fp, targFmt, gn->name, gn->rem.hname)
 #else
 # define TARG_FMT  "--- %s ---\n" /* Default format */
 # define MESSAGE(fp, gn) \
-       (void) fprintf(fp, targFmt, gn->name);
+       (void) fprintf(fp, targFmt, gn->name)
 #endif
 
 /*
@@ -773,6 +766,7 @@
        JobClose(job);
        if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
           (void) fclose(job->cmdFILE);
+          job->cmdFILE = NULL;
        }
        done = TRUE;
 #ifdef REMOTE
@@ -819,6 +813,8 @@
             * output file as well.
             */
            out = fdopen(job->outFd, "w");
+           if (out == NULL)
+               Punt("Cannot fdopen");
        } else {
            out = stdout;
        }
@@ -1232,7 +1228,7 @@
 #endif /* RMT_NO_EXEC */
 
     if ((cpid = vfork()) == -1) {
-       Punt("Cannot fork");
+       Punt("Cannot vfork");
     } else if (cpid == 0) {
 
        /*
@@ -1732,6 +1728,13 @@
      */
     if ((gn->type & OP_MAKE) || (!noExecute && !touchFlag)) {
        /*
+        * tfile is the name of a file into which all shell commands are
+        * put. It is used over by removing it before the child shell is
+        * executed. The XXXXXX in the string are replaced by the pid of
+        * the make process in a 6-character field with leading zeroes.
+        */
+       char     tfile[sizeof(TMPPAT)];
+       /*
         * We're serious here, but if the commands were bogus, we're
         * also dead...
         */
@@ -1739,6 +1742,7 @@
            DieHorribly();
        }
 
+       (void)strcpy(tfile, TMPPAT);
        if ((tfd = mkstemp(tfile)) == -1)
            Punt("Could not create temporary file %s", strerror(errno));
        (void) eunlink(tfile);
@@ -1851,8 +1855,10 @@
         * Unlink and close the command file if we opened one
         */
        if (job->cmdFILE != stdout) {
-           if (job->cmdFILE != NULL)
+           if (job->cmdFILE != NULL) {
                (void) fclose(job->cmdFILE);
+               job->cmdFILE = NULL;
+           }
        } else {
             (void) fflush(stdout);
        }
@@ -2212,6 +2218,8 @@
            }
            (void) fclose(oFILE);
            (void) eunlink(job->outFile);
+       } else {
+           Punt("Cannot open `%s'", job->outFile);
        }
     }
 }
@@ -2943,8 +2951,7 @@
  *     Number of errors reported.
  *
  * Side Effects:
- *     The process' temporary file (tfile) is removed if it still
- *     existed.
+ *     None.
  *-----------------------------------------------------------------------
  */
 int



Home | Main Index | Thread Index | Old Index