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 USE_IOVEC



details:   https://anonhg.NetBSD.org/src/rev/48643ffda01d
branches:  trunk
changeset: 955960:48643ffda01d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 18 08:01:23 2020 +0000

description:
make(1): remove USE_IOVEC

When a system call in a child process failed, there was no guarantee
that the error message would be written completely.  Using writev
correctly is harder than building the string in a buffer and then
writing it in the traditional way.

According to POSIX 2004, using memory allocation or even calling
write(2) from the child process invokes undefined behavior.  The
remaining code from make has done all this for several years now,
successfully, therefore adding one more of that won't hurt.

Make still tries to write the error message atomically by passing the
whole buffer at once to write(2), just as in the previous writev(2)
implementation.

diffstat:

 usr.bin/make/config.h |   8 +------
 usr.bin/make/main.c   |  59 ++++++++++++++++++++++++++------------------------
 2 files changed, 32 insertions(+), 35 deletions(-)

diffs (112 lines):

diff -r 5b5952855f0d -r 48643ffda01d usr.bin/make/config.h
--- a/usr.bin/make/config.h     Sun Oct 18 07:46:04 2020 +0000
+++ b/usr.bin/make/config.h     Sun Oct 18 08:01:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.h,v 1.23 2020/09/27 17:17:01 rillig Exp $       */
+/*     $NetBSD: config.h,v 1.24 2020/10/18 08:01:23 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -154,12 +154,6 @@
  */
 #define SUNSHCMD
 
-/*
- * USE_IOVEC
- *     We have writev(2)
- */
-#define USE_IOVEC
-
 #if defined(MAKE_NATIVE) && !defined(__ELF__)
 # ifndef RANLIBMAG
 #  define RANLIBMAG "__.SYMDEF"
diff -r 5b5952855f0d -r 48643ffda01d usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sun Oct 18 07:46:04 2020 +0000
+++ b/usr.bin/make/main.c       Sun Oct 18 08:01:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.372 2020/10/18 07:46:04 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.373 2020/10/18 08:01:23 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,12 +117,8 @@
 #include "pathnames.h"
 #include "trace.h"
 
-#ifdef USE_IOVEC
-#include <sys/uio.h>
-#endif
-
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.372 2020/10/18 07:46:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.373 2020/10/18 08:01:23 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -1876,6 +1872,22 @@
        return unlink(file);
 }
 
+static void
+write_all(int fd, const void *data, size_t n)
+{
+       const char *mem = data;
+
+       while (n > 0) {
+               ssize_t written = write(fd, mem, n);
+               if (written == -1 && errno == EAGAIN)
+                       continue;
+               if (written == -1)
+                       break;
+               mem += written;
+               n -= written;
+       }
+}
+
 /*
  * execDie --
  *     Print why exec failed, avoiding stdio.
@@ -1883,30 +1895,21 @@
 void MAKE_ATTR_DEAD
 execDie(const char *af, const char *av)
 {
-#ifdef USE_IOVEC
-       int i = 0;
-       struct iovec iov[8];
-#define IOADD(s) \
-       (void)(iov[i].iov_base = UNCONST(s), \
-           iov[i].iov_len = strlen(iov[i].iov_base), \
-           i++)
-#else
-#define        IOADD(void)write(2, s, strlen(s))
-#endif
+       Buffer buf;
 
-       IOADD(progname);
-       IOADD(": ");
-       IOADD(af);
-       IOADD("(");
-       IOADD(av);
-       IOADD(") failed (");
-       IOADD(strerror(errno));
-       IOADD(")\n");
+       Buf_Init(&buf, 0);
+       Buf_AddStr(&buf, progname);
+       Buf_AddStr(&buf, ": ");
+       Buf_AddStr(&buf, af);
+       Buf_AddStr(&buf, "(");
+       Buf_AddStr(&buf, av);
+       Buf_AddStr(&buf, ") failed (");
+       Buf_AddStr(&buf, strerror(errno));
+       Buf_AddStr(&buf, ")\n");
 
-#ifdef USE_IOVEC
-       while (writev(2, iov, 8) == -1 && errno == EAGAIN)
-           continue;
-#endif
+       write_all(STDERR_FILENO, Buf_GetAll(&buf, NULL), Buf_Len(&buf));
+
+       Buf_Destroy(&buf, TRUE);
        _exit(1);
 }
 



Home | Main Index | Thread Index | Old Index