JobExec(): don't use Punt() in the child; it can't possibly DTRT, and will also

mess up the parents variables.

Instead, use execError() for all error paths in the child code.
This commit is contained in:
pk 2002-03-14 16:08:37 +00:00
parent 7c2860c21f
commit 0debc78bef
4 changed files with 37 additions and 26 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.40 2002/02/07 16:48:22 pk Exp $ */
/* $NetBSD: compat.c,v 1.41 2002/03/14 16:08:37 pk Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: compat.c,v 1.40 2002/02/07 16:48:22 pk Exp $";
static char rcsid[] = "$NetBSD: compat.c,v 1.41 2002/03/14 16:08:37 pk Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: compat.c,v 1.40 2002/02/07 16:48:22 pk Exp $");
__RCSID("$NetBSD: compat.c,v 1.41 2002/03/14 16:08:37 pk Exp $");
#endif
#endif /* not lint */
#endif
@ -289,7 +289,7 @@ CompatRunCommand (cmdp, gnp)
(void)execvp(av[0], av);
else
(void)execv(av[0], av);
execError(av[0]);
execError("exec", av[0]);
_exit(1);
}
if (bp) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.63 2002/03/14 08:07:55 pk Exp $ */
/* $NetBSD: job.c,v 1.64 2002/03/14 16:08:38 pk Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: job.c,v 1.63 2002/03/14 08:07:55 pk Exp $";
static char rcsid[] = "$NetBSD: job.c,v 1.64 2002/03/14 16:08:38 pk Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: job.c,v 1.63 2002/03/14 08:07:55 pk Exp $");
__RCSID("$NetBSD: job.c,v 1.64 2002/03/14 16:08:38 pk Exp $");
#endif
#endif /* not lint */
#endif
@ -1329,8 +1329,10 @@ JobExec(job, 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)
Punt("Cannot dup2: %s", strerror(errno));
if (dup2(FILENO(job->cmdFILE), 0) == -1) {
execError("dup2", "job->cmdFILE");
_exit(1);
}
(void) fcntl(0, F_SETFD, 0);
(void) lseek(0, (off_t)0, SEEK_SET);
@ -1347,16 +1349,20 @@ JobExec(job, argv)
* Set up the child's output to be routed through the pipe
* we've created for it.
*/
if (dup2(job->outPipe, 1) == -1)
Punt("Cannot dup2: %s", strerror(errno));
if (dup2(job->outPipe, 1) == -1) {
execError("dup2", "job->outPipe");
_exit(1);
}
} else {
/*
* We're capturing output in a file, so we duplicate the
* descriptor to the temporary file into the standard
* output.
*/
if (dup2(job->outFd, 1) == -1)
Punt("Cannot dup2: %s", strerror(errno));
if (dup2(job->outFd, 1) == -1) {
execError("dup2", "job->outFd");
_exit(1);
}
}
/*
* The output channels are marked close on exec. This bit was
@ -1365,8 +1371,10 @@ JobExec(job, argv)
* its standard output.
*/
(void) fcntl(1, F_SETFD, 0);
if (dup2(1, 2) == -1)
Punt("Cannot dup2: %s", strerror(errno));
if (dup2(1, 2) == -1) {
execError("dup2", "1, 2");
_exit(1);
}
#ifdef USE_PGRP
/*
@ -1388,7 +1396,7 @@ JobExec(job, argv)
#endif /* REMOTE */
{
(void) execv(shellPath, argv);
execError(shellPath);
execError("exec", shellPath);
}
_exit(1);
} else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.82 2002/01/27 01:50:54 reinoud Exp $ */
/* $NetBSD: main.c,v 1.83 2002/03/14 16:08:39 pk Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,7 +39,7 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: main.c,v 1.82 2002/01/27 01:50:54 reinoud Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.83 2002/03/14 16:08:39 pk Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.82 2002/01/27 01:50:54 reinoud Exp $");
__RCSID("$NetBSD: main.c,v 1.83 2002/03/14 16:08:39 pk Exp $");
#endif
#endif /* not lint */
#endif
@ -1576,12 +1576,13 @@ eunlink(file)
* Print why exec failed, avoiding stdio.
*/
void
execError(av)
execError(af, av)
const char *af;
const char *av;
{
#ifdef USE_IOVEC
int i = 0;
struct iovec iov[6];
struct iovec iov[8];
#define IOADD(s) \
(void)(iov[i].iov_base = (s), \
iov[i].iov_len = strlen(iov[i].iov_base), \
@ -1591,14 +1592,16 @@ execError(av)
#endif
IOADD(progname);
IOADD(": Exec of `");
IOADD(": ");
IOADD((char *)af);
IOADD("(");
IOADD((char *)av);
IOADD("' failed (");
IOADD(") failed (");
IOADD(strerror(errno));
IOADD(")\n");
#ifdef USE_IOVEC
(void)writev(2, iov, 6);
(void)writev(2, iov, 8);
#endif
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: nonints.h,v 1.25 2002/01/18 03:36:00 thorpej Exp $ */
/* $NetBSD: nonints.h,v 1.26 2002/03/14 16:08:39 pk Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@ -88,7 +88,7 @@ void *emalloc __P((size_t));
void *erealloc __P((void *, size_t));
void enomem __P((void));
int eunlink __P((const char *));
void execError __P((const char *));
void execError __P((const char *, const char *));
/* parse.c */
void Parse_Error __P((int, char *, ...))