Source-Changes-HG archive

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

[src/netbsd-1-4]: src/usr.bin/make Pull up revisions 1.26-1.31 (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/9bc35e5d1057
branches:  netbsd-1-4
changeset: 470193:9bc35e5d1057
user:      he <he%NetBSD.org@localhost>
date:      Sun Jan 23 13:35:44 2000 +0000

description:
Pull up revisions 1.26-1.31 (requested by christos):
  Several fixes:
   o SystemV portability
   o Avoid non-portable use of 'sh -q'
   o Job control fixes when USE_PGRP is in use
   o Fix stack overflow bugs, use snprintf (fixes PR#8259)
   o Don't bother freeing mem right before exit()
   o Be caseful when creating temporary files, to avoid
     security problem.

diffstat:

 usr.bin/make/job.c |  129 +++++++++++++++++++++++++++-------------------------
 1 files changed, 68 insertions(+), 61 deletions(-)

diffs (truncated from 383 to 300 lines):

diff -r 3c99dd114f4c -r 9bc35e5d1057 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sun Jan 23 12:57:12 2000 +0000
+++ b/usr.bin/make/job.c        Sun Jan 23 13:35:44 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.25.2.1 2000/01/23 12:02:26 he Exp $  */
+/*     $NetBSD: job.c,v 1.25.2.2 2000/01/23 13:35:44 he 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.25.2.1 2000/01/23 12:02:26 he Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.25.2.2 2000/01/23 13:35:44 he 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.25.2.1 2000/01/23 12:02:26 he Exp $");
+__RCSID("$NetBSD: job.c,v 1.25.2.2 2000/01/23 13:35:44 he Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -201,7 +201,12 @@
 #ifdef OLDBOURNESHELL
     FALSE, "echo \"%s\"\n", "sh -c '%s || exit 0'\n",
 #endif
-    "vq", "e",
+#ifdef __NetBSD__
+    "vq",
+#else
+    "v",
+#endif
+    "e",
 },
     /*
      * UNKNOWN.
@@ -267,7 +272,7 @@
 
 
 #if defined(USE_PGRP) && defined(SYSV)
-# define KILL(pid, sig)                killpg(-(pid), (sig))
+# define KILL(pid, sig)                kill(-(pid), (sig))
 #else
 # if defined(USE_PGRP)
 #  define KILL(pid, sig)       killpg((pid), (sig))
@@ -282,19 +287,12 @@
  * stuff much more. So, we devise our own macros... This is
  * really ugly, use dramamine sparingly. You have been warned.
  */
-#define W_SETMASKED(st, val, fun)                              \
-       {                                                       \
-               int sh = (int) ~0;                              \
-               int mask = fun(sh);                             \
-                                                               \
-               for (sh = 0; ((mask >> sh) & 1) == 0; sh++)     \
-                       continue;                               \
-               *(st) = (*(st) & ~mask) | ((val) << sh);        \
-       }
-
-#define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
-#define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
-
+#ifndef W_STOPCODE
+#define W_STOPCODE(sig) (((sig) << 8) | 0177)
+#endif
+#ifndef W_EXITCODE
+#define W_EXITCODE(ret, sig) ((ret << 8) | (sig))
+#endif 
 
 static int JobCondPassSig __P((ClientData, ClientData));
 static void JobPassSig __P((int));
@@ -383,6 +381,7 @@
 {
     sigset_t nmask, omask;
     struct sigaction act;
+    int sigcont;
 
     if (DEBUG(JOB)) {
        (void) fprintf(stdout, "JobPassSig(%d) called.\n", signo);
@@ -414,8 +413,7 @@
      * This ensures that all our jobs get continued when we wake up before
      * we take any other signal.
      */
-    sigemptyset(&nmask);
-    sigaddset(&nmask, signo);
+    sigfillset(&nmask);
     sigprocmask(SIG_SETMASK, &nmask, &omask);
     act.sa_handler = SIG_DFL;
     sigemptyset(&act.sa_mask);
@@ -428,17 +426,19 @@
                       ~0 & ~(1 << (signo-1)));
        (void) fflush(stdout);
     }
-    (void) signal(signo, SIG_DFL);
 
-    (void) KILL(getpid(), signo);
-
-    signo = SIGCONT;
-    Lst_ForEach(jobs, JobCondPassSig, (ClientData) &signo);
+    (void) kill(getpid(), signo);
+    if (signo != SIGTSTP) {
+       sigcont = SIGCONT;
+       Lst_ForEach(jobs, JobCondPassSig, (ClientData) &sigcont);
+    }
 
     (void) sigprocmask(SIG_SETMASK, &omask, NULL);
     sigprocmask(SIG_SETMASK, &omask, NULL);
-    act.sa_handler = JobPassSig;
-    sigaction(signo, &act, NULL);
+    if (signo != SIGCONT && signo != SIGTSTP) {
+       act.sa_handler = JobPassSig;
+       sigaction(sigcont, &act, NULL);
+    }
 }
 
 /*-
@@ -753,7 +753,7 @@
 
     if ((WIFEXITED(*status) &&
         (((WEXITSTATUS(*status) != 0) && !(job->flags & JOB_IGNERR)))) ||
-       (WIFSIGNALED(*status) && (WTERMSIG(*status) != SIGCONT)))
+       WIFSIGNALED(*status))
     {
        /*
         * If it exited non-zero and either we're doing things our
@@ -804,8 +804,7 @@
 
     if (done ||
        WIFSTOPPED(*status) ||
-       (WIFSIGNALED(*status) && (WTERMSIG(*status) == SIGCONT)) ||
-       DEBUG(JOB))
+       (WIFSIGNALED(*status) && (WTERMSIG(*status) == SIGCONT)))
     {
        FILE      *out;
 
@@ -844,7 +843,7 @@
                }
                (void) fprintf(out, "*** Completed successfully\n");
            }
-       } else if (WIFSTOPPED(*status)) {
+       } else if (WIFSTOPPED(*status) && WSTOPSIG(*status) != SIGCONT) {
            if (DEBUG(JOB)) {
                (void) fprintf(stdout, "Process %d stopped.\n", job->pid);
                (void) fflush(stdout);
@@ -854,8 +853,17 @@
                lastNode = job->node;
            }
            if (!(job->flags & JOB_REMIGRATE)) {
-               (void) fprintf(out, "*** Stopped -- signal %d\n",
-                   WSTOPSIG(*status));
+               switch (WSTOPSIG(*status)) {
+               case SIGTSTP:
+                   (void) fprintf(out, "*** Suspended\n");
+                   break;
+               case SIGSTOP:
+                   (void) fprintf(out, "*** Stopped\n");
+                   break;
+               default:
+                   (void) fprintf(out, "*** Stopped -- signal %d\n",
+                       WSTOPSIG(*status));
+               }
            }
            job->flags |= JOB_RESUME;
            (void)Lst_AtEnd(stoppedJobs, (ClientData)job);
@@ -865,7 +873,7 @@
 #endif
            (void) fflush(out);
            return;
-       } else if (WTERMSIG(*status) == SIGCONT) {
+       } else if (WIFSTOPPED(*status) &&  WSTOPSIG(*status) == SIGCONT) {
            /*
             * If the beastie has continued, shift the Job from the stopped
             * list to the running one (or re-stop it if concurrency is
@@ -940,7 +948,7 @@
            break;
        case JOB_ERROR:
            done = TRUE;
-           W_SETEXITSTATUS(status, 1);
+           *status = W_EXITCODE(1, 0);
            break;
        case JOB_FINISHED:
            /*
@@ -1000,7 +1008,6 @@
        /*
         * If we are aborting and the job table is now empty, we finish.
         */
-       (void) eunlink(tfile);
        Finish(errors);
     }
 }
@@ -1285,7 +1292,10 @@
        _exit(1);
     } else {
 #ifdef REMOTE
-       long omask = sigblock(sigmask(SIGCHLD));
+       sigset_t nmask, omask;
+       sigemptyset(&nmask);
+       sigaddset(&nmask, SIGCHLD);
+       sigprocmask(SIG_BLOCK, &nmask, &omask);
 #endif
        job->pid = cpid;
 
@@ -1321,7 +1331,7 @@
            }
        }
 #ifdef REMOTE
-       (void) sigsetmask(omask);
+       sigprocmask(SIG_SETMASK, &omask, NULL);
 #endif
     }
 
@@ -1370,7 +1380,7 @@
         * Bourne shell thinks its second argument is a file to source.
         * Grrrr. Note the ten-character limitation on the combined arguments.
         */
-       (void)sprintf(args, "-%s%s",
+       (void)snprintf(args, sizeof(args), "-%s%s",
                      ((job->flags & JOB_IGNERR) ? "" :
                       (commandShell->exit ? commandShell->exit : "")),
                      ((job->flags & JOB_SILENT) ? "" :
@@ -1506,7 +1516,7 @@
         * 'echo' flag of the commandShell is used to get it to start echoing
         * as soon as it starts processing commands.
         */
-       char      *argv[4];
+       char      *argv[10];
 
        JobMakeArgv(job, argv);
 
@@ -1608,7 +1618,7 @@
                 * actually put the thing in the job table.
                 */
                job->flags |= JOB_CONTINUING;
-               W_SETTERMSIG(&status, SIGCONT);
+               status = W_STOPCODE(SIGCONT);
                JobFinish(job, &status);
 
                job->flags &= ~(JOB_RESUME|JOB_CONTINUING);
@@ -1619,8 +1629,7 @@
            } else {
                Error("couldn't resume %s: %s",
                    job->node->name, strerror(errno));
-               status = 0;
-               W_SETEXITSTATUS(&status, 1);
+               status = W_EXITCODE(1, 0);
                JobFinish(job, &status);
            }
        } else {
@@ -1667,11 +1676,11 @@
                               * if any. */
 {
     register Job  *job;       /* new job descriptor */
-    char         *argv[4];   /* Argument vector to shell */
-    static int    jobno = 0;  /* job number of catching output in a file */
+    char         *argv[10];  /* Argument vector to shell */
     Boolean      cmdsOK;     /* true if the nodes commands were all right */
     Boolean      local;      /* Set true if the job was run locally */
     Boolean      noExec;     /* Set true if we decide not to run the job */
+    int                  tfd;        /* File descriptor to the temp file */
 
     if (previous != NULL) {
        previous->flags &= ~(JOB_FIRST|JOB_IGNERR|JOB_SILENT|JOB_REMOTE);
@@ -1726,9 +1735,13 @@
            DieHorribly();
        }
 
-       job->cmdFILE = fopen(tfile, "w+");
+       if ((tfd = mkstemp(tfile)) == -1)
+           Punt("Could not create temporary file %s", strerror(errno));
+       (void) eunlink(tfile);
+
+       job->cmdFILE = fdopen(tfd, "w+");
        if (job->cmdFILE == NULL) {
-           Punt("Could not open %s", tfile);
+           Punt("Could not fdopen %s", tfile);
        }
        (void) fcntl(FILENO(job->cmdFILE), F_SETFD, 1);
        /*
@@ -1834,7 +1847,6 @@
         * Unlink and close the command file if we opened one
         */
        if (job->cmdFILE != stdout) {
-           (void) eunlink(tfile);
            if (job->cmdFILE != NULL)
                (void) fclose(job->cmdFILE);
        } else {
@@ -1862,7 +1874,6 @@
        }
     } else {
        (void) fflush(job->cmdFILE);
-       (void) eunlink(tfile);
     }
 
     /*
@@ -1874,8 +1885,7 @@
     /*



Home | Main Index | Thread Index | Old Index