Module Name:    src
Committed By:   rillig
Date:           Mon Sep 28 00:06:36 UTC 2020

Modified Files:
        src/usr.bin/make: job.c job.h

Log Message:
make(1): split Job.jobPipe into 2 separate fields

Just because these file descriptors have to be in an array when they are
created is not reason enough to keep this array and a few access macros
in the Job struct.  It's better to have separate fields, as they can be
documented independently.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/usr.bin/make/job.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/make/job.h

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.248 src/usr.bin/make/job.c:1.249
--- src/usr.bin/make/job.c:1.248	Sun Sep 27 23:56:25 2020
+++ src/usr.bin/make/job.c	Mon Sep 28 00:06:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.248 2020/09/27 23:56:25 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.249 2020/09/28 00:06:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.248 2020/09/27 23:56:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.249 2020/09/28 00:06:36 rillig Exp $");
 
 # define STATIC static
 
@@ -401,19 +401,23 @@ static void
 JobCreatePipe(Job *job, int minfd)
 {
     int i, fd, flags;
+    int pipe_fds[2];
 
-    if (pipe(job->jobPipe) == -1)
+    if (pipe(pipe_fds) == -1)
 	Punt("Cannot create pipe: %s", strerror(errno));
 
     for (i = 0; i < 2; i++) {
 	/* Avoid using low numbered fds */
-	fd = fcntl(job->jobPipe[i], F_DUPFD, minfd);
+	fd = fcntl(pipe_fds[i], F_DUPFD, minfd);
 	if (fd != -1) {
-	    close(job->jobPipe[i]);
-	    job->jobPipe[i] = fd;
+	    close(pipe_fds[i]);
+	    pipe_fds[i] = fd;
 	}
     }
 
+    job->inPipe = pipe_fds[0];
+    job->outPipe = pipe_fds[1];
+
     /* Set close-on-exec flag for both */
     if (fcntl(job->inPipe, F_SETFD, FD_CLOEXEC) == -1)
 	Punt("Cannot set close-on-exec: %s", strerror(errno));

Index: src/usr.bin/make/job.h
diff -u src/usr.bin/make/job.h:1.52 src/usr.bin/make/job.h:1.53
--- src/usr.bin/make/job.h:1.52	Sun Sep 27 23:12:12 2020
+++ src/usr.bin/make/job.h	Mon Sep 28 00:06:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.h,v 1.52 2020/09/27 23:12:12 rillig Exp $	*/
+/*	$NetBSD: job.h,v 1.53 2020/09/28 00:06:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -163,7 +163,8 @@ typedef struct Job {
 				 * commands */
 #define JOB_TRACED	0x400	/* we've sent 'set -x' */
 
-    int jobPipe[2];		/* Pipe for reading output from job */
+    int inPipe;			/* Pipe for reading output from job */
+    int outPipe;		/* Pipe for writing control commands */
     struct pollfd *inPollfd;	/* pollfd associated with inPipe */
 
 #define JOB_BUFSIZE	1024
@@ -176,9 +177,6 @@ typedef struct Job {
 #endif
 } Job;
 
-#define inPipe jobPipe[0]
-#define outPipe jobPipe[1]
-
 /*-
  * Shell Specifications:
  * Each shell type has associated with it the following information:

Reply via email to