Deleted Added
full compact
job.c (146572) job.c (146574)
1/*-
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1988, 1989 by Adam de Boor
5 * Copyright (c) 1989 by Berkeley Softworks
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by

--- 26 unchanged lines hidden (view full) ---

35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)job.c 8.2 (Berkeley) 3/19/94
40 */
41
42#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1988, 1989 by Adam de Boor
5 * Copyright (c) 1989 by Berkeley Softworks
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by

--- 26 unchanged lines hidden (view full) ---

35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)job.c 8.2 (Berkeley) 3/19/94
40 */
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/usr.bin/make/job.c 146572 2005-05-24 15:30:03Z harti $");
43__FBSDID("$FreeBSD: head/usr.bin/make/job.c 146574 2005-05-24 15:41:34Z harti $");
44
45#ifndef OLD_JOKE
46#define OLD_JOKE 0
47#endif /* OLD_JOKE */
48
49/*-
50 * job.c --
51 * handle the creation etc. of our child processes.

--- 76 unchanged lines hidden (view full) ---

128#include "buf.h"
129#include "config.h"
130#include "dir.h"
131#include "globals.h"
132#include "GNode.h"
133#include "job.h"
134#include "make.h"
135#include "parse.h"
44
45#ifndef OLD_JOKE
46#define OLD_JOKE 0
47#endif /* OLD_JOKE */
48
49/*-
50 * job.c --
51 * handle the creation etc. of our child processes.

--- 76 unchanged lines hidden (view full) ---

128#include "buf.h"
129#include "config.h"
130#include "dir.h"
131#include "globals.h"
132#include "GNode.h"
133#include "job.h"
134#include "make.h"
135#include "parse.h"
136#include "pathnames.h"
136#include "proc.h"
137#include "shell.h"
138#include "str.h"
139#include "suff.h"
140#include "targ.h"
141#include "util.h"
142#include "var.h"
143
144#define TMPPAT "/tmp/makeXXXXXXXXXX"

--- 228 unchanged lines hidden (view full) ---

373 for (sh = 0; ((mask >> sh) & 1) == 0; sh++) \
374 continue; \
375 *(st) = (*(st) & ~mask) | ((val) << sh); \
376 }
377
378#define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
379#define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
380
137#include "shell.h"
138#include "str.h"
139#include "suff.h"
140#include "targ.h"
141#include "util.h"
142#include "var.h"
143
144#define TMPPAT "/tmp/makeXXXXXXXXXX"

--- 228 unchanged lines hidden (view full) ---

373 for (sh = 0; ((mask >> sh) & 1) == 0; sh++) \
374 continue; \
375 *(st) = (*(st) & ~mask) | ((val) << sh); \
376 }
377
378#define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
379#define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
380
381/**
382 * Information used to create a new process.
383 */
384typedef struct ProcStuff {
385 int in; /* stdin for new process */
386 int out; /* stdout for new process */
387 int err; /* stderr for new process */
388
389 int merge_errors; /* true if stderr is redirected to stdin */
390 int pgroup; /* true if new process a process leader */
391 int searchpath; /* true if binary should be found via $PATH */
392
393 char **argv;
394 int argv_free; /* release argv after use */
395 int errCheck;
396
397 pid_t child_pid;
398} ProcStuff;
399
400static void JobRestart(Job *);
401static int JobStart(GNode *, int, Job *);
402static void JobDoOutput(Job *, Boolean);
403static void JobInterrupt(int, int);
404static void JobRestartJobs(void);
381static void JobRestart(Job *);
382static int JobStart(GNode *, int, Job *);
383static void JobDoOutput(Job *, Boolean);
384static void JobInterrupt(int, int);
385static void JobRestartJobs(void);
405static void ProcExec(const ProcStuff *) __dead2;
406static int Compat_RunCommand(char *, struct GNode *);
407
408static GNode *curTarg = NULL;
409static GNode *ENDNode;
410
411/**
412 * Create a fifo file with a uniq filename, and returns a file
413 * descriptor to that fifo.

--- 103 unchanged lines hidden (view full) ---

517
518 sigemptyset(&sa.sa_mask);
519 sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
520 sa.sa_handler = catch_child;
521 sigaction(SIGCHLD, &sa, NULL);
522}
523
524/**
386static int Compat_RunCommand(char *, struct GNode *);
387
388static GNode *curTarg = NULL;
389static GNode *ENDNode;
390
391/**
392 * Create a fifo file with a uniq filename, and returns a file
393 * descriptor to that fifo.

--- 103 unchanged lines hidden (view full) ---

497
498 sigemptyset(&sa.sa_mask);
499 sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
500 sa.sa_handler = catch_child;
501 sigaction(SIGCHLD, &sa, NULL);
502}
503
504/**
525 * Replace the current process.
526 */
527static void
528ProcExec(const ProcStuff *ps)
529{
530
531 if (ps->in != STDIN_FILENO) {
532 /*
533 * Redirect the child's stdin to the input fd
534 * and reset it to the beginning (again).
535 */
536 if (dup2(ps->in, STDIN_FILENO) == -1)
537 Punt("Cannot dup2: %s", strerror(errno));
538 lseek(STDIN_FILENO, (off_t)0, SEEK_SET);
539 }
540
541 if (ps->out != STDOUT_FILENO) {
542 /*
543 * Redirect the child's stdout to the output fd.
544 */
545 if (dup2(ps->out, STDOUT_FILENO) == -1)
546 Punt("Cannot dup2: %s", strerror(errno));
547 close(ps->out);
548 }
549
550 if (ps->err != STDERR_FILENO) {
551 /*
552 * Redirect the child's stderr to the err fd.
553 */
554 if (dup2(ps->err, STDERR_FILENO) == -1)
555 Punt("Cannot dup2: %s", strerror(errno));
556 close(ps->err);
557 }
558
559 if (ps->merge_errors) {
560 /*
561 * Send stderr to parent process too.
562 */
563 if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1)
564 Punt("Cannot dup2: %s", strerror(errno));
565 }
566
567 if (commandShell->unsetenv) {
568 /* for the benfit of ksh */
569 unsetenv("ENV");
570 }
571
572 /*
573 * The file descriptors for stdin, stdout, or stderr might
574 * have been marked close-on-exec. Clear the flag on all
575 * of them.
576 */
577 fcntl(STDIN_FILENO, F_SETFD,
578 fcntl(STDIN_FILENO, F_GETFD) & (~FD_CLOEXEC));
579 fcntl(STDOUT_FILENO, F_SETFD,
580 fcntl(STDOUT_FILENO, F_GETFD) & (~FD_CLOEXEC));
581 fcntl(STDERR_FILENO, F_SETFD,
582 fcntl(STDERR_FILENO, F_GETFD) & (~FD_CLOEXEC));
583
584 if (ps->pgroup) {
585#ifdef USE_PGRP
586 /*
587 * Become a process group leader, so we can kill it and all
588 * its descendants in one fell swoop, by killing its process
589 * family, but not commit suicide.
590 */
591#if defined(SYSV)
592 setsid();
593#else
594 setpgid(0, getpid());
595#endif
596#endif /* USE_PGRP */
597 }
598
599 if (ps->searchpath) {
600 execvp(ps->argv[0], ps->argv);
601
602 write(STDERR_FILENO, ps->argv[0], strlen(ps->argv[0]));
603 write(STDERR_FILENO, ":", 1);
604 write(STDERR_FILENO, strerror(errno), strlen(strerror(errno)));
605 write(STDERR_FILENO, "\n", 1);
606 } else {
607 execv(commandShell->path, ps->argv);
608
609 write(STDERR_FILENO,
610 "Could not execute shell\n",
611 sizeof("Could not execute shell"));
612 }
613
614 /*
615 * Since we are the child process, exit without flushing buffers.
616 */
617 _exit(1);
618 /* NOTREACHED */
619}
620
621/**
622 * Wait for child process to terminate.
623 */
624static int
625ProcWait(ProcStuff *ps)
626{
627 pid_t pid;
628 int status;
629

--- 845 unchanged lines hidden (view full) ---

1475
1476 } else if (ps.child_pid == 0) {
1477 /*
1478 * Child
1479 */
1480 if (fifoFd >= 0)
1481 close(fifoFd);
1482
505 * Wait for child process to terminate.
506 */
507static int
508ProcWait(ProcStuff *ps)
509{
510 pid_t pid;
511 int status;
512

--- 845 unchanged lines hidden (view full) ---

1358
1359 } else if (ps.child_pid == 0) {
1360 /*
1361 * Child
1362 */
1363 if (fifoFd >= 0)
1364 close(fifoFd);
1365
1483 ProcExec(&ps);
1366 Proc_Exec(&ps);
1484 /* NOTREACHED */
1485 }
1486
1487 /*
1488 * Parent
1489 */
1490 job->pid = ps.child_pid;
1491

--- 1327 unchanged lines hidden (view full) ---

2819 if ((ps.child_pid = vfork()) == -1) {
2820 *error = "Couldn't exec \"%s\"";
2821 return (buf);
2822
2823 } else if (ps.child_pid == 0) {
2824 /*
2825 * Child
2826 */
1367 /* NOTREACHED */
1368 }
1369
1370 /*
1371 * Parent
1372 */
1373 job->pid = ps.child_pid;
1374

--- 1327 unchanged lines hidden (view full) ---

2702 if ((ps.child_pid = vfork()) == -1) {
2703 *error = "Couldn't exec \"%s\"";
2704 return (buf);
2705
2706 } else if (ps.child_pid == 0) {
2707 /*
2708 * Child
2709 */
2827 ProcExec(&ps);
2710 Proc_Exec(&ps);
2828 /* NOTREACHED */
2829 }
2830
2831 free(ps.argv[2]);
2832 free(ps.argv[1]);
2833 free(ps.argv[0]);
2834 free(ps.argv);
2835

--- 273 unchanged lines hidden (view full) ---

3109 */
3110 if ((ps.child_pid = vfork()) == -1) {
3111 Fatal("Could not fork");
3112
3113 } else if (ps.child_pid == 0) {
3114 /*
3115 * Child
3116 */
2711 /* NOTREACHED */
2712 }
2713
2714 free(ps.argv[2]);
2715 free(ps.argv[1]);
2716 free(ps.argv[0]);
2717 free(ps.argv);
2718

--- 273 unchanged lines hidden (view full) ---

2992 */
2993 if ((ps.child_pid = vfork()) == -1) {
2994 Fatal("Could not fork");
2995
2996 } else if (ps.child_pid == 0) {
2997 /*
2998 * Child
2999 */
3117 ProcExec(&ps);
3000 Proc_Exec(&ps);
3118 /* NOTREACHED */
3119
3120 } else {
3121 if (ps.argv_free) {
3122 free(ps.argv[2]);
3123 free(ps.argv[1]);
3124 free(ps.argv[0]);
3125 free(ps.argv);

--- 379 unchanged lines hidden ---
3001 /* NOTREACHED */
3002
3003 } else {
3004 if (ps.argv_free) {
3005 free(ps.argv[2]);
3006 free(ps.argv[1]);
3007 free(ps.argv[0]);
3008 free(ps.argv);

--- 379 unchanged lines hidden ---