Back out previous vfork changes.
This commit is contained in:
parent
dbc1cf06d2
commit
e6bccfe4be
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: eval.c,v 1.55 2000/05/17 07:37:12 elric Exp $ */
|
||||
/* $NetBSD: eval.c,v 1.56 2000/05/22 10:18:46 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
@ -41,24 +41,17 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: eval.c,v 1.55 2000/05/17 07:37:12 elric Exp $");
|
||||
__RCSID("$NetBSD: eval.c,v 1.56 2000/05/22 10:18:46 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
/*
|
||||
* Evaluate a command.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "shell.h"
|
||||
#include "nodes.h"
|
||||
#include "syntax.h"
|
||||
@ -595,7 +588,6 @@ out:
|
||||
}
|
||||
|
||||
|
||||
int vforked = 0;
|
||||
|
||||
/*
|
||||
* Execute a simple command.
|
||||
@ -635,7 +627,6 @@ evalcommand(cmd, flags, backcmd)
|
||||
(void) &flags;
|
||||
#endif
|
||||
|
||||
vforked = 0;
|
||||
/* First expand the arguments. */
|
||||
TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
|
||||
setstackmark(&smark);
|
||||
@ -745,72 +736,10 @@ evalcommand(cmd, flags, backcmd)
|
||||
if (pipe(pip) < 0)
|
||||
error("Pipe call failed");
|
||||
}
|
||||
#ifdef DO_SHAREDVFORK
|
||||
/* It is essential that if DO_SHAREDVFORK is defined that the
|
||||
* child's address space is actually shared with the parent as
|
||||
* we rely on this.
|
||||
*/
|
||||
if (cmdentry.cmdtype == CMDNORMAL) {
|
||||
pid_t pid;
|
||||
|
||||
INTOFF;
|
||||
savelocalvars = localvars;
|
||||
localvars = NULL;
|
||||
for (sp = varlist.list ; sp ; sp = sp->next)
|
||||
mklocal(sp->text, VEXPORT);
|
||||
vforked = 1;
|
||||
switch (pid = vfork()) {
|
||||
case -1:
|
||||
TRACE(("Vfork failed, errno=%d", errno));
|
||||
INTON;
|
||||
error("Cannot vfork");
|
||||
break;
|
||||
case 0:
|
||||
/* Make sure that exceptions only unwind to
|
||||
* after the vfork(2)
|
||||
*/
|
||||
if (setjmp(jmploc.loc)) {
|
||||
if (exception == EXSHELLPROC) {
|
||||
/* We can't progress with the vfork,
|
||||
* so, set vforked = 2 so the parent
|
||||
* knows, and _exit();
|
||||
*/
|
||||
vforked = 2;
|
||||
_exit(0);
|
||||
} else {
|
||||
_exit(exerrno);
|
||||
}
|
||||
}
|
||||
savehandler = handler;
|
||||
handler = &jmploc;
|
||||
forkchild(jp, cmd, mode, vforked);
|
||||
break;
|
||||
default:
|
||||
handler = savehandler; /* restore from vfork(2) */
|
||||
poplocalvars();
|
||||
localvars = savelocalvars;
|
||||
if (vforked == 2) {
|
||||
vforked = 0;
|
||||
waitpid(pid, NULL, 0);
|
||||
/* We need to progress in a normal fork fashion */
|
||||
goto normal_fork;
|
||||
}
|
||||
vforked = 0;
|
||||
forkparent(jp, cmd, mode, pid);
|
||||
goto parent;
|
||||
}
|
||||
} else {
|
||||
normal_fork:
|
||||
#endif
|
||||
if (forkshell(jp, cmd, mode) != 0)
|
||||
goto parent; /* at end of routine */
|
||||
#ifdef DO_SHAREDVFORK
|
||||
}
|
||||
#endif
|
||||
if (forkshell(jp, cmd, mode) != 0)
|
||||
goto parent; /* at end of routine */
|
||||
if (flags & EV_BACKCMD) {
|
||||
if (!vforked) {
|
||||
FORCEINTON;
|
||||
}
|
||||
FORCEINTON;
|
||||
close(pip[0]);
|
||||
if (pip[1] != 1) {
|
||||
close(1);
|
||||
@ -854,7 +783,7 @@ normal_fork:
|
||||
savehandler = handler;
|
||||
handler = &jmploc;
|
||||
for (sp = varlist.list ; sp ; sp = sp->next)
|
||||
mklocal(sp->text, 0);
|
||||
mklocal(sp->text);
|
||||
funcnest++;
|
||||
evaltree(cmdentry.u.func, flags & EV_TESTED);
|
||||
funcnest--;
|
||||
@ -933,13 +862,12 @@ cmddone:
|
||||
#ifdef DEBUG
|
||||
trputs("normal command: "); trargs(argv);
|
||||
#endif
|
||||
clearredir(vforked?REDIR_VFORK:0);
|
||||
redirect(cmd->ncmd.redirect, vforked?REDIR_VFORK:0);
|
||||
if (!vforked)
|
||||
for (sp = varlist.list ; sp ; sp = sp->next)
|
||||
setvareq(sp->text, VEXPORT|VSTACK);
|
||||
clearredir();
|
||||
redirect(cmd->ncmd.redirect, 0);
|
||||
for (sp = varlist.list ; sp ; sp = sp->next)
|
||||
setvareq(sp->text, VEXPORT|VSTACK);
|
||||
envp = environment();
|
||||
shellexec(argv, envp, pathval(), cmdentry.u.index, vforked);
|
||||
shellexec(argv, envp, pathval(), cmdentry.u.index);
|
||||
}
|
||||
goto out;
|
||||
|
||||
@ -964,6 +892,7 @@ out:
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Search for a command. This is called before we fork so that the
|
||||
* location of the command will be available in the parent as well as
|
||||
@ -1093,7 +1022,7 @@ execcmd(argc, argv)
|
||||
optschanged();
|
||||
for (sp = cmdenviron; sp ; sp = sp->next)
|
||||
setvareq(sp->text, VEXPORT|VSTACK);
|
||||
shellexec(argv + 1, environment(), pathval(), 0, 0);
|
||||
shellexec(argv + 1, environment(), pathval(), 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: exec.c,v 1.28 2000/05/13 20:50:14 elric Exp $ */
|
||||
/* $NetBSD: exec.c,v 1.29 2000/05/22 10:18:46 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,17 +41,15 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: exec.c,v 1.28 2000/05/13 20:50:14 elric Exp $");
|
||||
__RCSID("$NetBSD: exec.c,v 1.29 2000/05/22 10:18:46 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
@ -104,7 +102,7 @@ STATIC int builtinloc = -1; /* index in path of %builtin, or -1 */
|
||||
int exerrno = 0; /* Last exec error */
|
||||
|
||||
|
||||
STATIC void tryexec __P((char *, char **, char **, int));
|
||||
STATIC void tryexec __P((char *, char **, char **));
|
||||
STATIC void execinterp __P((char **, char **));
|
||||
STATIC void printentry __P((struct tblentry *, int));
|
||||
STATIC void clearcmdentry __P((int));
|
||||
@ -119,23 +117,22 @@ STATIC void delete_cmd_entry __P((void));
|
||||
*/
|
||||
|
||||
void
|
||||
shellexec(argv, envp, path, idx, vforked)
|
||||
shellexec(argv, envp, path, idx)
|
||||
char **argv, **envp;
|
||||
const char *path;
|
||||
int idx;
|
||||
int vforked;
|
||||
{
|
||||
char *cmdname;
|
||||
int e;
|
||||
|
||||
if (strchr(argv[0], '/') != NULL) {
|
||||
tryexec(argv[0], argv, envp, vforked);
|
||||
tryexec(argv[0], argv, envp);
|
||||
e = errno;
|
||||
} else {
|
||||
e = ENOENT;
|
||||
while ((cmdname = padvance(&path, argv[0])) != NULL) {
|
||||
if (--idx < 0 && pathopt == NULL) {
|
||||
tryexec(cmdname, argv, envp, vforked);
|
||||
tryexec(cmdname, argv, envp);
|
||||
if (errno != ENOENT && errno != ENOTDIR)
|
||||
e = errno;
|
||||
}
|
||||
@ -161,11 +158,10 @@ shellexec(argv, envp, path, idx, vforked)
|
||||
|
||||
|
||||
STATIC void
|
||||
tryexec(cmd, argv, envp, vforked)
|
||||
tryexec(cmd, argv, envp)
|
||||
char *cmd;
|
||||
char **argv;
|
||||
char **envp;
|
||||
int vforked;
|
||||
{
|
||||
int e;
|
||||
#ifndef BSD
|
||||
@ -181,13 +177,6 @@ tryexec(cmd, argv, envp, vforked)
|
||||
#endif
|
||||
e = errno;
|
||||
if (e == ENOEXEC) {
|
||||
if (vforked) {
|
||||
/* We are currently vfork(2)ed, so raise an
|
||||
* exception, and evalcommand will try again
|
||||
* with a normal fork(2).
|
||||
*/
|
||||
exraise(EXSHELLPROC);
|
||||
}
|
||||
initshellproc();
|
||||
setinputfile(cmd, 0);
|
||||
commandname = arg0 = savestr(argv[0]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: exec.h,v 1.16 2000/05/13 20:50:14 elric Exp $ */
|
||||
/* $NetBSD: exec.h,v 1.17 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -60,7 +60,7 @@ struct cmdentry {
|
||||
extern const char *pathopt; /* set by padvance */
|
||||
extern int exerrno; /* last exec error */
|
||||
|
||||
void shellexec __P((char **, char **, const char *, int, int))
|
||||
void shellexec __P((char **, char **, const char *, int))
|
||||
__attribute__((noreturn));
|
||||
char *padvance __P((const char **, const char *));
|
||||
int hashcmd __P((int, char **));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: input.c,v 1.33 2000/05/13 20:50:14 elric Exp $ */
|
||||
/* $NetBSD: input.c,v 1.34 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: input.c,v 1.33 2000/05/13 20:50:14 elric Exp $");
|
||||
__RCSID("$NetBSD: input.c,v 1.34 2000/05/22 10:18:47 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -506,22 +506,10 @@ popallfiles() {
|
||||
/*
|
||||
* Close the file(s) that the shell is reading commands from. Called
|
||||
* after a fork is done.
|
||||
*
|
||||
* Takes one arg, vfork, which tells it to not modify its global vars
|
||||
* as it is still running in the parent.
|
||||
*/
|
||||
|
||||
void
|
||||
closescript(int vforked) {
|
||||
if (vforked) {
|
||||
struct parsefile *pf;
|
||||
|
||||
for (pf=parsefile; pf != &basepf; pf=pf->prev)
|
||||
close(pf->fd);
|
||||
if (parsefile->fd > 0)
|
||||
close(parsefile->fd);
|
||||
return;
|
||||
}
|
||||
closescript() {
|
||||
popallfiles();
|
||||
if (parsefile->fd > 0) {
|
||||
close(parsefile->fd);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: input.h,v 1.11 2000/05/13 20:50:15 elric Exp $ */
|
||||
/* $NetBSD: input.h,v 1.12 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -61,6 +61,6 @@ void setinputfd __P((int, int));
|
||||
void setinputstring __P((char *, int));
|
||||
void popfile __P((void));
|
||||
void popallfiles __P((void));
|
||||
void closescript __P((int));
|
||||
void closescript __P((void));
|
||||
|
||||
#define pgetc_macro() (--parsenleft >= 0? *parsenextc++ : preadbuffer())
|
||||
|
178
bin/sh/jobs.c
178
bin/sh/jobs.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: jobs.c,v 1.35 2000/05/15 03:42:48 elric Exp $ */
|
||||
/* $NetBSD: jobs.c,v 1.36 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: jobs.c,v 1.35 2000/05/15 03:42:48 elric Exp $");
|
||||
__RCSID("$NetBSD: jobs.c,v 1.36 2000/05/22 10:18:47 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -149,9 +149,9 @@ setjobctl(on)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
setsignal(SIGTSTP, 0);
|
||||
setsignal(SIGTTOU, 0);
|
||||
setsignal(SIGTTIN, 0);
|
||||
setsignal(SIGTSTP);
|
||||
setsignal(SIGTTOU);
|
||||
setsignal(SIGTTIN);
|
||||
setpgid(0, rootpid);
|
||||
#ifdef OLD_TTY_DRIVER
|
||||
ioctl(2, TIOCSPGRP, (char *)&rootpid);
|
||||
@ -165,9 +165,9 @@ setjobctl(on)
|
||||
#else
|
||||
tcsetpgrp(2, initialpgrp);
|
||||
#endif
|
||||
setsignal(SIGTSTP, 0);
|
||||
setsignal(SIGTTOU, 0);
|
||||
setsignal(SIGTTIN, 0);
|
||||
setsignal(SIGTSTP);
|
||||
setsignal(SIGTTOU);
|
||||
setsignal(SIGTTIN);
|
||||
}
|
||||
jobctl = on;
|
||||
}
|
||||
@ -573,33 +573,82 @@ forkshell(jp, n, mode)
|
||||
int mode;
|
||||
{
|
||||
int pid;
|
||||
int pgrp;
|
||||
const char *devnull = _PATH_DEVNULL;
|
||||
const char *nullerr = "Can't open %s";
|
||||
|
||||
TRACE(("forkshell(%%%d, 0x%lx, %d) called\n", jp - jobtab, (long)n,
|
||||
mode));
|
||||
INTOFF;
|
||||
switch (pid = fork()) {
|
||||
case -1:
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
TRACE(("Fork failed, errno=%d\n", errno));
|
||||
INTON;
|
||||
error("Cannot fork");
|
||||
break;
|
||||
case 0:
|
||||
forkchild(jp, n, mode, 0);
|
||||
return 0;
|
||||
default:
|
||||
return forkparent(jp, n, mode, pid);
|
||||
}
|
||||
}
|
||||
if (pid == 0) {
|
||||
struct job *p;
|
||||
int wasroot;
|
||||
int i;
|
||||
|
||||
int
|
||||
forkparent(jp, n, mode, pid)
|
||||
union node *n;
|
||||
struct job *jp;
|
||||
int mode;
|
||||
pid_t pid;
|
||||
{
|
||||
int pgrp;
|
||||
|
||||
TRACE(("Child shell %d\n", getpid()));
|
||||
wasroot = rootshell;
|
||||
rootshell = 0;
|
||||
for (i = njobs, p = jobtab ; --i >= 0 ; p++)
|
||||
if (p->used)
|
||||
freejob(p);
|
||||
closescript();
|
||||
INTON;
|
||||
clear_traps();
|
||||
#if JOBS
|
||||
jobctl = 0; /* do job control only in root shell */
|
||||
if (wasroot && mode != FORK_NOJOB && mflag) {
|
||||
if (jp == NULL || jp->nprocs == 0)
|
||||
pgrp = getpid();
|
||||
else
|
||||
pgrp = jp->ps[0].pid;
|
||||
setpgid(0, pgrp);
|
||||
if (mode == FORK_FG) {
|
||||
/*** this causes superfluous TIOCSPGRPS ***/
|
||||
#ifdef OLD_TTY_DRIVER
|
||||
if (ioctl(2, TIOCSPGRP, (char *)&pgrp) < 0)
|
||||
error("TIOCSPGRP failed, errno=%d", errno);
|
||||
#else
|
||||
if (tcsetpgrp(2, pgrp) < 0)
|
||||
error("tcsetpgrp failed, errno=%d", errno);
|
||||
#endif
|
||||
}
|
||||
setsignal(SIGTSTP);
|
||||
setsignal(SIGTTOU);
|
||||
} else if (mode == FORK_BG) {
|
||||
ignoresig(SIGINT);
|
||||
ignoresig(SIGQUIT);
|
||||
if ((jp == NULL || jp->nprocs == 0) &&
|
||||
! fd0_redirected_p ()) {
|
||||
close(0);
|
||||
if (open(devnull, O_RDONLY) != 0)
|
||||
error(nullerr, devnull);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (mode == FORK_BG) {
|
||||
ignoresig(SIGINT);
|
||||
ignoresig(SIGQUIT);
|
||||
if ((jp == NULL || jp->nprocs == 0) &&
|
||||
! fd0_redirected_p ()) {
|
||||
close(0);
|
||||
if (open(devnull, O_RDONLY) != 0)
|
||||
error(nullerr, devnull);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (wasroot && iflag) {
|
||||
setsignal(SIGINT);
|
||||
setsignal(SIGQUIT);
|
||||
setsignal(SIGTERM);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
if (rootshell && mode != FORK_NOJOB && mflag) {
|
||||
if (jp == NULL || jp->nprocs == 0)
|
||||
pgrp = pid;
|
||||
@ -622,83 +671,6 @@ forkparent(jp, n, mode, pid)
|
||||
return pid;
|
||||
}
|
||||
|
||||
void
|
||||
forkchild(jp, n, mode, vforked)
|
||||
union node *n;
|
||||
struct job *jp;
|
||||
int mode;
|
||||
int vforked;
|
||||
{
|
||||
struct job *p;
|
||||
int wasroot;
|
||||
int i;
|
||||
int pgrp;
|
||||
const char *devnull = _PATH_DEVNULL;
|
||||
const char *nullerr = "Can't open %s";
|
||||
|
||||
TRACE(("Child shell %d\n", getpid()));
|
||||
wasroot = rootshell;
|
||||
if (!vforked) {
|
||||
rootshell = 0;
|
||||
for (i = njobs, p = jobtab ; --i >= 0 ; p++)
|
||||
if (p->used)
|
||||
freejob(p);
|
||||
}
|
||||
closescript(vforked);
|
||||
if (!vforked) {
|
||||
INTON;
|
||||
}
|
||||
clear_traps(vforked);
|
||||
#if JOBS
|
||||
if (!vforked)
|
||||
jobctl = 0; /* do job control only in root shell */
|
||||
if (wasroot && mode != FORK_NOJOB && mflag) {
|
||||
if (jp == NULL || jp->nprocs == 0)
|
||||
pgrp = getpid();
|
||||
else
|
||||
pgrp = jp->ps[0].pid;
|
||||
setpgid(0, pgrp);
|
||||
if (mode == FORK_FG) {
|
||||
/*** this causes superfluous TIOCSPGRPS ***/
|
||||
#ifdef OLD_TTY_DRIVER
|
||||
if (ioctl(2, TIOCSPGRP, (char *)&pgrp) < 0)
|
||||
error("TIOCSPGRP failed, errno=%d", errno);
|
||||
#else
|
||||
if (tcsetpgrp(2, pgrp) < 0)
|
||||
error("tcsetpgrp failed, errno=%d", errno);
|
||||
#endif
|
||||
}
|
||||
setsignal(SIGTSTP, vforked);
|
||||
setsignal(SIGTTOU, vforked);
|
||||
} else if (mode == FORK_BG) {
|
||||
ignoresig(SIGINT, vforked);
|
||||
ignoresig(SIGQUIT, vforked);
|
||||
if ((jp == NULL || jp->nprocs == 0) &&
|
||||
! fd0_redirected_p ()) {
|
||||
close(0);
|
||||
if (open(devnull, O_RDONLY) != 0)
|
||||
error(nullerr, devnull);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (mode == FORK_BG) {
|
||||
ignoresig(SIGINT, vforked);
|
||||
ignoresig(SIGQUIT, vforked);
|
||||
if ((jp == NULL || jp->nprocs == 0) &&
|
||||
! fd0_redirected_p ()) {
|
||||
close(0);
|
||||
if (open(devnull, O_RDONLY) != 0)
|
||||
error(nullerr, devnull);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (wasroot && iflag) {
|
||||
setsignal(SIGINT, vforked);
|
||||
setsignal(SIGQUIT, vforked);
|
||||
setsignal(SIGTERM, vforked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: jobs.h,v 1.11 2000/05/13 20:56:08 elric Exp $ */
|
||||
/* $NetBSD: jobs.h,v 1.12 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -88,8 +88,6 @@ int waitcmd __P((int, char **));
|
||||
int jobidcmd __P((int, char **));
|
||||
struct job *makejob __P((union node *, int));
|
||||
int forkshell __P((struct job *, union node *, int));
|
||||
void forkchild __P((struct job *jp, union node *n, int mode, int vforked));
|
||||
int forkparent __P((struct job *jp, union node *n, int mode, pid_t pid));
|
||||
int waitforjob __P((struct job *));
|
||||
int stoppedjobs __P((void));
|
||||
char *commandtext __P((union node *));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.37 2000/05/13 20:50:15 elric Exp $ */
|
||||
/* $NetBSD: main.c,v 1.38 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: main.c,v 1.37 2000/05/13 20:50:15 elric Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.38 2000/05/22 10:18:47 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -205,7 +205,7 @@ state3:
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SIGSSIZE; i++)
|
||||
setsignal(sigs[i], 0);
|
||||
setsignal(sigs[i]);
|
||||
}
|
||||
|
||||
if (minusc)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: redir.c,v 1.21 2000/05/13 20:50:15 elric Exp $ */
|
||||
/* $NetBSD: redir.c,v 1.22 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: redir.c,v 1.21 2000/05/13 20:50:15 elric Exp $");
|
||||
__RCSID("$NetBSD: redir.c,v 1.22 2000/05/22 10:18:47 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -120,9 +120,6 @@ redirect(redir, flags)
|
||||
memory[i] = 0;
|
||||
memory[1] = flags & REDIR_BACKQ;
|
||||
if (flags & REDIR_PUSH) {
|
||||
/* We don't have to worry about REDIR_VFORK here, as
|
||||
* flags & REDIR_PUSH is never true if REDIR_VFORK is set.
|
||||
*/
|
||||
sv = ckmalloc(sizeof (struct redirtab));
|
||||
for (i = 0 ; i < 10 ; i++)
|
||||
sv->renamed[i] = EMPTY;
|
||||
@ -338,7 +335,7 @@ RESET {
|
||||
}
|
||||
|
||||
SHELLPROC {
|
||||
clearredir(0);
|
||||
clearredir();
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -354,9 +351,7 @@ fd0_redirected_p () {
|
||||
*/
|
||||
|
||||
void
|
||||
clearredir(vforked)
|
||||
int vforked;
|
||||
{
|
||||
clearredir() {
|
||||
struct redirtab *rp;
|
||||
int i;
|
||||
|
||||
@ -365,8 +360,7 @@ clearredir(vforked)
|
||||
if (rp->renamed[i] >= 0) {
|
||||
close(rp->renamed[i]);
|
||||
}
|
||||
if (!vforked)
|
||||
rp->renamed[i] = EMPTY;
|
||||
rp->renamed[i] = EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: redir.h,v 1.11 2000/05/13 20:50:15 elric Exp $ */
|
||||
/* $NetBSD: redir.h,v 1.12 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,12 +41,11 @@
|
||||
/* flags passed to redirect */
|
||||
#define REDIR_PUSH 01 /* save previous values of file descriptors */
|
||||
#define REDIR_BACKQ 02 /* save the command output in memory */
|
||||
#define REDIR_VFORK 04 /* running under vfork(2), be careful */
|
||||
|
||||
union node;
|
||||
void redirect __P((union node *, int));
|
||||
void popredir __P((void));
|
||||
int fd0_redirected_p __P((void));
|
||||
void clearredir __P((int));
|
||||
void clearredir __P((void));
|
||||
int copyfd __P((int, int));
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: shell.h,v 1.12 2000/05/13 21:11:16 elric Exp $ */
|
||||
/* $NetBSD: shell.h,v 1.13 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -46,26 +46,17 @@
|
||||
* define SYSV if you are running under System V.
|
||||
* define DEBUG=1 to compile in debugging (set global "debug" to turn on)
|
||||
* define DEBUG=2 to compile in and turn on debugging.
|
||||
* define DO_SHAREDVFORK to indicate that vfork(2) shares its address
|
||||
* with its parent.
|
||||
*
|
||||
* When debugging is on, debugging info will be written to $HOME/trace and
|
||||
* a quit signal will generate a core dump.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#define JOBS 1
|
||||
#ifndef BSD
|
||||
#define BSD 1
|
||||
#endif
|
||||
|
||||
#ifndef DO_SHAREDVFORK
|
||||
#if __NetBSD_Version__ >= 104000000
|
||||
#define DO_SHAREDVFORK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef void *pointer;
|
||||
#ifndef NULL
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: trap.c,v 1.23 2000/05/13 20:50:15 elric Exp $ */
|
||||
/* $NetBSD: trap.c,v 1.24 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: trap.c,v 1.23 2000/05/13 20:50:15 elric Exp $");
|
||||
__RCSID("$NetBSD: trap.c,v 1.24 2000/05/22 10:18:47 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -121,7 +121,7 @@ trapcmd(argc, argv)
|
||||
ckfree(trap[signo]);
|
||||
trap[signo] = action;
|
||||
if (signo != 0)
|
||||
setsignal(signo, 0);
|
||||
setsignal(signo);
|
||||
INTON;
|
||||
ap++;
|
||||
}
|
||||
@ -131,26 +131,20 @@ trapcmd(argc, argv)
|
||||
|
||||
|
||||
/*
|
||||
* Clear traps on a fork or vfork.
|
||||
* Takes one arg vfork, to tell it to not be destructive of
|
||||
* the parents variables.
|
||||
* Clear traps on a fork.
|
||||
*/
|
||||
|
||||
void
|
||||
clear_traps(vforked)
|
||||
int vforked;
|
||||
{
|
||||
clear_traps() {
|
||||
char **tp;
|
||||
|
||||
for (tp = trap ; tp <= &trap[NSIG] ; tp++) {
|
||||
if (*tp && **tp) { /* trap not NULL or SIG_IGN */
|
||||
INTOFF;
|
||||
if (!vforked) {
|
||||
ckfree(*tp);
|
||||
*tp = NULL;
|
||||
}
|
||||
ckfree(*tp);
|
||||
*tp = NULL;
|
||||
if (tp != &trap[0])
|
||||
setsignal(tp - trap, vforked);
|
||||
setsignal(tp - trap);
|
||||
INTON;
|
||||
}
|
||||
}
|
||||
@ -164,13 +158,12 @@ clear_traps(vforked)
|
||||
*/
|
||||
|
||||
long
|
||||
setsignal(signo, vforked)
|
||||
setsignal(signo)
|
||||
int signo;
|
||||
int vforked;
|
||||
{
|
||||
int action;
|
||||
sig_t sigact = SIG_DFL;
|
||||
char *t, tsig;
|
||||
char *t;
|
||||
|
||||
if ((t = trap[signo]) == NULL)
|
||||
action = S_DFL;
|
||||
@ -178,7 +171,7 @@ setsignal(signo, vforked)
|
||||
action = S_CATCH;
|
||||
else
|
||||
action = S_IGN;
|
||||
if (rootshell && !vforked && action == S_DFL) {
|
||||
if (rootshell && action == S_DFL) {
|
||||
switch (signo) {
|
||||
case SIGINT:
|
||||
if (iflag || minusc || sflag == 0)
|
||||
@ -209,8 +202,7 @@ setsignal(signo, vforked)
|
||||
}
|
||||
|
||||
t = &sigmode[signo - 1];
|
||||
tsig = *t;
|
||||
if (tsig == 0) {
|
||||
if (*t == 0) {
|
||||
/*
|
||||
* current setting unknown
|
||||
*/
|
||||
@ -225,22 +217,21 @@ setsignal(signo, vforked)
|
||||
if (sigact == SIG_IGN) {
|
||||
if (mflag && (signo == SIGTSTP ||
|
||||
signo == SIGTTIN || signo == SIGTTOU)) {
|
||||
tsig = S_IGN; /* don't hard ignore these */
|
||||
*t = S_IGN; /* don't hard ignore these */
|
||||
} else
|
||||
tsig = S_HARD_IGN;
|
||||
*t = S_HARD_IGN;
|
||||
} else {
|
||||
tsig = S_RESET; /* force to be set */
|
||||
*t = S_RESET; /* force to be set */
|
||||
}
|
||||
}
|
||||
if (tsig == S_HARD_IGN || tsig == action)
|
||||
if (*t == S_HARD_IGN || *t == action)
|
||||
return 0;
|
||||
switch (action) {
|
||||
case S_DFL: sigact = SIG_DFL; break;
|
||||
case S_CATCH: sigact = onsig; break;
|
||||
case S_IGN: sigact = SIG_IGN; break;
|
||||
}
|
||||
if (!vforked)
|
||||
*t = action;
|
||||
*t = action;
|
||||
siginterrupt(signo, 1);
|
||||
return (long)signal(signo, sigact);
|
||||
}
|
||||
@ -266,15 +257,13 @@ getsigaction(signo, sigact)
|
||||
*/
|
||||
|
||||
void
|
||||
ignoresig(signo, vforked)
|
||||
ignoresig(signo)
|
||||
int signo;
|
||||
int vforked;
|
||||
{
|
||||
if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
|
||||
signal(signo, SIG_IGN);
|
||||
}
|
||||
if (!vforked)
|
||||
sigmode[signo - 1] = S_HARD_IGN;
|
||||
sigmode[signo - 1] = S_HARD_IGN;
|
||||
}
|
||||
|
||||
|
||||
@ -285,7 +274,7 @@ INCLUDE "trap.h"
|
||||
SHELLPROC {
|
||||
char *sm;
|
||||
|
||||
clear_traps(0);
|
||||
clear_traps();
|
||||
for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
|
||||
if (*sm == S_IGN)
|
||||
*sm = S_HARD_IGN;
|
||||
@ -355,9 +344,9 @@ setinteractive(on)
|
||||
|
||||
if (on == is_interactive)
|
||||
return;
|
||||
setsignal(SIGINT, 0);
|
||||
setsignal(SIGQUIT, 0);
|
||||
setsignal(SIGTERM, 0);
|
||||
setsignal(SIGINT);
|
||||
setsignal(SIGQUIT);
|
||||
setsignal(SIGTERM);
|
||||
is_interactive = on;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: trap.h,v 1.13 2000/05/13 20:50:15 elric Exp $ */
|
||||
/* $NetBSD: trap.h,v 1.14 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,9 +41,9 @@
|
||||
extern int pendingsigs;
|
||||
|
||||
int trapcmd __P((int, char **));
|
||||
void clear_traps __P((int));
|
||||
long setsignal __P((int, int));
|
||||
void ignoresig __P((int, int));
|
||||
void clear_traps __P((void));
|
||||
long setsignal __P((int));
|
||||
void ignoresig __P((int));
|
||||
void onsig __P((int));
|
||||
void dotrap __P((void));
|
||||
void setinteractive __P((int));
|
||||
|
14
bin/sh/var.c
14
bin/sh/var.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: var.c,v 1.24 2000/05/17 07:37:12 elric Exp $ */
|
||||
/* $NetBSD: var.c,v 1.25 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: var.c,v 1.24 2000/05/17 07:37:12 elric Exp $");
|
||||
__RCSID("$NetBSD: var.c,v 1.25 2000/05/22 10:18:47 elric Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -557,7 +557,7 @@ localcmd(argc, argv)
|
||||
if (! in_function())
|
||||
error("Not in a function");
|
||||
while ((name = *argptr++) != NULL) {
|
||||
mklocal(name, 0);
|
||||
mklocal(name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -571,7 +571,7 @@ localcmd(argc, argv)
|
||||
*/
|
||||
|
||||
void
|
||||
mklocal(name, flags)
|
||||
mklocal(name)
|
||||
char *name;
|
||||
{
|
||||
struct localvar *lvp;
|
||||
@ -590,9 +590,9 @@ mklocal(name, flags)
|
||||
for (vp = *vpp ; vp && ! varequal(vp->text, name) ; vp = vp->next);
|
||||
if (vp == NULL) {
|
||||
if (strchr(name, '='))
|
||||
setvareq(savestr(name), VSTRFIXED|flags);
|
||||
setvareq(savestr(name), VSTRFIXED);
|
||||
else
|
||||
setvar(name, NULL, VSTRFIXED|flags);
|
||||
setvar(name, NULL, VSTRFIXED);
|
||||
vp = *vpp; /* the new variable */
|
||||
lvp->text = NULL;
|
||||
lvp->flags = VUNSET;
|
||||
@ -601,7 +601,7 @@ mklocal(name, flags)
|
||||
lvp->flags = vp->flags;
|
||||
vp->flags |= VSTRFIXED|VTEXTFIXED;
|
||||
if (strchr(name, '='))
|
||||
setvareq(savestr(name), flags);
|
||||
setvareq(savestr(name), 0);
|
||||
}
|
||||
}
|
||||
lvp->vp = vp;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: var.h,v 1.17 2000/05/17 07:37:12 elric Exp $ */
|
||||
/* $NetBSD: var.h,v 1.18 2000/05/22 10:18:47 elric Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -123,7 +123,7 @@ void shprocvar __P((void));
|
||||
int showvarscmd __P((int, char **));
|
||||
int exportcmd __P((int, char **));
|
||||
int localcmd __P((int, char **));
|
||||
void mklocal __P((char *, int));
|
||||
void mklocal __P((char *));
|
||||
void poplocalvars __P((void));
|
||||
int setvarcmd __P((int, char **));
|
||||
int unsetcmd __P((int, char **));
|
||||
|
Loading…
Reference in New Issue
Block a user