Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): remove macro FILENO
details: https://anonhg.NetBSD.org/src/rev/3e00431c9118
branches: trunk
changeset: 955661:3e00431c9118
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Oct 06 16:39:23 2020 +0000
description:
make(1): remove macro FILENO
This macro was obviously wrong since it would have converted file
numbers above 127 to very large numbers, close to 2^32.
The fact that it didn't blow up at all is that this macro was only ever
given the file descriptor 4 as an argument, which can well be
represented as a char, be it signed or unsigned. And this is how the
story goes:
In Job_Init, two jobs are started. The server job allocates file
descriptors 15 and above. The childExitJob is created next, and the
pipe that it creates is [3, 4]. Using F_DUPFD, fd 3 is mapped to fd 5,
and fd 3 is closed. After that, fd 4 is mapped to fd 3 (which had just
been closed), and fd 4 is closed.
After this initialization, file descriptors 0, 1, 2, 3 and 5 are taken.
This leaves a gap at file descriptor 4, and this gap is filled whenever
cmdFILE is created.
Because of this particular order of events, the macro is not necessary.
If it should ever become necessary on platforms like the old SunOS, the
parameter minfd for JobCreatePipe should be increased to 5, which would
leave the file descriptors 3 and 4 to be used by stdio streams.
On 1995-11-03, when the macro was added, SunOS must have been in its
very early development. In Solaris 8 (released in January 2000),
FILE._file is already an unsigned char, therefore the seeming need for
this macro must have been due to an older version, probably from the 2.x
series of SunOS.
diffstat:
usr.bin/make/job.c | 18 ++++--------------
1 files changed, 4 insertions(+), 14 deletions(-)
diffs (53 lines):
diff -r 819ad610f8cb -r 3e00431c9118 usr.bin/make/job.c
--- a/usr.bin/make/job.c Tue Oct 06 15:05:54 2020 +0000
+++ b/usr.bin/make/job.c Tue Oct 06 16:39:23 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.261 2020/10/05 21:37:07 rillig Exp $ */
+/* $NetBSD: job.c,v 1.262 2020/10/06 16:39:23 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.261 2020/10/05 21:37:07 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.262 2020/10/06 16:39:23 rillig Exp $");
# define STATIC static
@@ -162,16 +162,6 @@
*/
int jobTokensRunning = 0;
-/*
- * XXX: Avoid SunOS bug... FILENO() is fp->_file, and file
- * is a char! So when we go above 127 we turn negative!
- *
- * XXX: This cannot have ever worked. Converting a signed char directly to
- * unsigned creates very large numbers. It should have been converted to
- * unsigned char first, in the same way as for the <ctype.h> functions.
- */
-#define FILENO(a) ((unsigned) fileno(a))
-
/* The number of commands actually printed for a target.
* XXX: Why printed? Shouldn't that be run/printed instead, depending on the
* command line options?
@@ -1213,7 +1203,7 @@
* reset it to the beginning (again). Since the stream was marked
* close-on-exec, we must clear that bit in the new input.
*/
- if (dup2(FILENO(job->cmdFILE), 0) == -1) {
+ if (dup2(fileno(job->cmdFILE), 0) == -1) {
execError("dup2", "job->cmdFILE");
_exit(1);
}
@@ -1466,7 +1456,7 @@
if (job->cmdFILE == NULL) {
Punt("Could not fdopen %s", tfile);
}
- (void)fcntl(FILENO(job->cmdFILE), F_SETFD, FD_CLOEXEC);
+ (void)fcntl(fileno(job->cmdFILE), F_SETFD, FD_CLOEXEC);
/*
* Send the commands to the command file, flush all its buffers then
* rewind and remove the thing.
Home |
Main Index |
Thread Index |
Old Index