Module Name: src Committed By: rillig Date: Sun Oct 18 08:01:23 UTC 2020
Modified Files: src/usr.bin/make: config.h main.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/config.h cvs rdiff -u -r1.372 -r1.373 src/usr.bin/make/main.c 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/config.h diff -u src/usr.bin/make/config.h:1.23 src/usr.bin/make/config.h:1.24 --- src/usr.bin/make/config.h:1.23 Sun Sep 27 17:17:01 2020 +++ src/usr.bin/make/config.h Sun Oct 18 08:01:23 2020 @@ -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" Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.372 src/usr.bin/make/main.c:1.373 --- src/usr.bin/make/main.c:1.372 Sun Oct 18 07:46:04 2020 +++ src/usr.bin/make/main.c Sun Oct 18 08:01:23 2020 @@ -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 @@ eunlink(const char *file) 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 @@ eunlink(const char *file) 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); }