make(1): replace execError with execDie

All calls to this function were followed by _exit(1).
This commit is contained in:
rillig 2020-10-18 07:46:04 +00:00
parent 1f7ebca62c
commit 2309709fed
5 changed files with 34 additions and 53 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.165 2020/10/05 19:27:47 rillig Exp $ */
/* $NetBSD: compat.c,v 1.166 2020/10/18 07:46:04 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -96,7 +96,7 @@
#include "pathnames.h"
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: compat.c,v 1.165 2020/10/05 19:27:47 rillig Exp $");
MAKE_RCSID("$NetBSD: compat.c,v 1.166 2020/10/18 07:46:04 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
@ -348,8 +348,7 @@ Compat_RunCommand(const char *cmdp, struct GNode *gn)
}
#endif
(void)execvp(av[0], (char *const *)UNCONST(av));
execError("exec", av[0]);
_exit(1);
execDie("exec", av[0]);
}
free(mav);

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.263 2020/10/17 21:32:30 rillig Exp $ */
/* $NetBSD: job.c,v 1.264 2020/10/18 07:46:04 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.263 2020/10/17 21:32:30 rillig Exp $");
MAKE_RCSID("$NetBSD: job.c,v 1.264 2020/10/18 07:46:04 rillig Exp $");
# define STATIC static
@ -1203,55 +1203,40 @@ JobExec(Job *job, char **argv)
* 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) {
execError("dup2", "job->cmdFILE");
_exit(1);
}
if (fcntl(0, F_SETFD, 0) == -1) {
execError("fcntl clear close-on-exec", "stdin");
_exit(1);
}
if (lseek(0, (off_t)0, SEEK_SET) == -1) {
execError("lseek to 0", "stdin");
_exit(1);
}
if (dup2(fileno(job->cmdFILE), 0) == -1)
execDie("dup2", "job->cmdFILE");
if (fcntl(0, F_SETFD, 0) == -1)
execDie("fcntl clear close-on-exec", "stdin");
if (lseek(0, (off_t)0, SEEK_SET) == -1)
execDie("lseek to 0", "stdin");
if (job->node->type & (OP_MAKE | OP_SUBMAKE)) {
/*
* Pass job token pipe to submakes.
*/
if (fcntl(tokenWaitJob.inPipe, F_SETFD, 0) == -1) {
execError("clear close-on-exec", "tokenWaitJob.inPipe");
_exit(1);
}
if (fcntl(tokenWaitJob.outPipe, F_SETFD, 0) == -1) {
execError("clear close-on-exec", "tokenWaitJob.outPipe");
_exit(1);
}
if (fcntl(tokenWaitJob.inPipe, F_SETFD, 0) == -1)
execDie("clear close-on-exec", "tokenWaitJob.inPipe");
if (fcntl(tokenWaitJob.outPipe, F_SETFD, 0) == -1)
execDie("clear close-on-exec", "tokenWaitJob.outPipe");
}
/*
* Set up the child's output to be routed through the pipe
* we've created for it.
*/
if (dup2(job->outPipe, 1) == -1) {
execError("dup2", "job->outPipe");
_exit(1);
}
if (dup2(job->outPipe, 1) == -1)
execDie("dup2", "job->outPipe");
/*
* The output channels are marked close on exec. This bit was
* duplicated by the dup2(on some systems), so we have to clear
* it before routing the shell's error output to the same place as
* its standard output.
*/
if (fcntl(1, F_SETFD, 0) == -1) {
execError("clear close-on-exec", "stdout");
_exit(1);
}
if (dup2(1, 2) == -1) {
execError("dup2", "1, 2");
_exit(1);
}
if (fcntl(1, F_SETFD, 0) == -1)
execDie("clear close-on-exec", "stdout");
if (dup2(1, 2) == -1)
execDie("dup2", "1, 2");
/*
* We want to switch the child into a different process family so
@ -1270,8 +1255,7 @@ JobExec(Job *job, char **argv)
Var_ExportVars();
(void)execv(shellPath, argv);
execError("exec", shellPath);
_exit(1);
execDie("exec", shellPath);
}
/* Parent, continuing after the child exec */

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.371 2020/10/05 22:45:47 rillig Exp $ */
/* $NetBSD: main.c,v 1.372 2020/10/18 07:46:04 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -122,7 +122,7 @@
#endif
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: main.c,v 1.371 2020/10/05 22:45:47 rillig Exp $");
MAKE_RCSID("$NetBSD: main.c,v 1.372 2020/10/18 07:46:04 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@ -1877,11 +1877,11 @@ eunlink(const char *file)
}
/*
* execError --
* execDie --
* Print why exec failed, avoiding stdio.
*/
void
execError(const char *af, const char *av)
void MAKE_ATTR_DEAD
execDie(const char *af, const char *av)
{
#ifdef USE_IOVEC
int i = 0;
@ -1907,6 +1907,7 @@ execError(const char *af, const char *av)
while (writev(2, iov, 8) == -1 && errno == EAGAIN)
continue;
#endif
_exit(1);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: meta.c,v 1.122 2020/09/28 22:23:35 rillig Exp $ */
/* $NetBSD: meta.c,v 1.123 2020/10/18 07:46:04 rillig Exp $ */
/*
* Implement 'meta' mode.
@ -1647,11 +1647,8 @@ void
meta_compat_child(void)
{
meta_job_child(NULL);
if (dup2(childPipe[1], 1) < 0 ||
dup2(1, 2) < 0) {
execError("dup2", "pipe");
_exit(1);
}
if (dup2(childPipe[1], 1) < 0 || dup2(1, 2) < 0)
execDie("dup2", "pipe");
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: nonints.h,v 1.141 2020/10/17 21:32:30 rillig Exp $ */
/* $NetBSD: nonints.h,v 1.142 2020/10/18 07:46:04 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@ -114,7 +114,7 @@ void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
void DieHorribly(void) MAKE_ATTR_DEAD;
void Finish(int) MAKE_ATTR_DEAD;
int eunlink(const char *);
void execError(const char *, const char *);
void execDie(const char *, const char *);
char *getTmpdir(void);
Boolean s2Boolean(const char *, Boolean);
Boolean getBoolean(const char *, Boolean);