Improve bookkeeping of in_waitcmd and style fixes.

Submitted by:	Bruce Evans
This commit is contained in:
cracauer 1998-08-25 09:33:34 +00:00
parent 3fc10b7719
commit 2ca0a9a7fb
7 changed files with 41 additions and 27 deletions

View File

@ -88,12 +88,16 @@ expr: ARITH_LPAREN expr ARITH_RPAREN = { $$ = $2; }
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: arith.y,v 1.7 1998/05/18 06:43:27 charnier Exp $
* $Id: arith.y,v 1.8 1998/08/24 10:20:36 cracauer Exp $
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)arith.y 8.3 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include "shell.h"
#include "error.h"
@ -103,8 +107,8 @@ static char sccsid[] = "@(#)arith.y 8.3 (Berkeley) 5/4/95";
char *arith_buf, *arith_startbuf;
extern void arith_lex_reset();
int yyparse(void);
int yylex(void);
int yylex __P((void));
int yyparse __P((void));
int
arith(s)

View File

@ -34,12 +34,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: arith_lex.l,v 1.10 1998/05/18 06:43:28 charnier Exp $
* $Id: arith_lex.l,v 1.11 1998/08/24 10:20:36 cracauer Exp $
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)arith_lex.l 8.3 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <unistd.h>
#include "y.tab.h"

View File

@ -39,7 +39,7 @@
static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id: error.c,v 1.11 1998/08/24 10:20:36 cracauer Exp $";
"$Id: error.c,v 1.12 1998/08/24 19:15:48 cracauer Exp $";
#endif /* not lint */
/*
@ -91,7 +91,7 @@ exraise(e)
/*
* Called from trap.c when a SIGINT is received. (If the user specifies
* that SIGINT is to be trapped or ignored using the trap builtin, then
* this routine is not called.) Supressint is nonzero when interrupts
* this routine is not called.) Suppressint is nonzero when interrupts
* are held using the INTOFF macro. If SIGINTs are not suppressed and
* the shell is not a root shell, then we want to be terminated if we
* get here, as if we were terminated directly by a SIGINT. Arrange for
@ -102,8 +102,9 @@ void
onint() {
sigset_t sigset;
/* The !in_dotrap is save. The only way we can arrive here with
* in_dotrap set is that a trap handler set SIGINT to default
/*
* The !in_dotrap here is safe. The only way we can arrive here
* with in_dotrap set is that a trap handler set SIGINT to SIG_DFL
* and killed itself.
*/
@ -115,9 +116,9 @@ onint() {
sigemptyset(&sigset);
sigprocmask(SIG_SETMASK, &sigset, NULL);
/* This doesn't seem to be needed. Note that main emit a newline
* as well.
*/
/*
* This doesn't seem to be needed, since main() emits a newline.
*/
#if 0
if (tcgetpgrp(0) == getpid())
write(STDERR_FILENO, "\n", 1);

View File

@ -39,7 +39,7 @@
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id: jobs.c,v 1.20 1998/05/18 06:43:47 charnier Exp $";
"$Id: jobs.c,v 1.21 1998/08/24 10:20:36 cracauer Exp $";
#endif /* not lint */
#include <fcntl.h>
@ -87,8 +87,8 @@ MKINIT pid_t backgndpid = -1; /* pid of last background process */
int initialpgrp; /* pgrp of shell on invocation */
int curjob; /* current job */
#endif
int in_waitcmd = 0; /* Are we in waitcmd? */
volatile sig_atomic_t breakwaitcmd = 0; /* Should wait be terminated? */
int in_waitcmd = 0; /* are we in waitcmd()? */
volatile sig_atomic_t breakwaitcmd = 0; /* should wait be terminated? */
#if JOBS
STATIC void restartjob __P((struct job *));
@ -97,7 +97,7 @@ STATIC void freejob __P((struct job *));
STATIC struct job *getjob __P((char *));
STATIC int dowait __P((int, struct job *));
#if SYSV
STATIC volatile int onsigchild __P((void));
STATIC int onsigchild __P((void));
#endif
STATIC int waitproc __P((int, int *));
STATIC void cmdtxt __P((union node *));
@ -387,10 +387,14 @@ waitcmd(argc, argv)
} else {
job = NULL;
}
/*
* Loop until a process is terminated or stopped, or a SIGINT is
* received.
*/
in_waitcmd++;
do { /* loop until process terminated or stopped or SIGINT is
* received
*/
do {
if (job != NULL) {
if (job->state) {
status = job->ps[job->nprocs - 1].status;
@ -404,11 +408,13 @@ waitcmd(argc, argv)
retval = WTERMSIG(status) + 128;
if (! iflag)
freejob(job);
in_waitcmd--;
return retval;
}
} else {
for (jp = jobtab ; ; jp++) {
if (jp >= jobtab + njobs) { /* no running procs */
in_waitcmd--;
return 0;
}
if (jp->used && jp->state == 0)
@ -418,7 +424,6 @@ waitcmd(argc, argv)
} while (dowait(1, (struct job *)NULL) != -1);
in_waitcmd--;
/* Not reachable */
return 0;
}

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)jobs.h 8.2 (Berkeley) 5/4/95
* $Id: jobs.h,v 1.6 1997/08/18 02:53:20 steve Exp $
* $Id: jobs.h,v 1.7 1998/08/24 10:20:36 cracauer Exp $
*/
/* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */
@ -42,7 +42,7 @@
#define FORK_BG 1
#define FORK_NOJOB 2
#include <signal.h> /* For sig_atomic_t */
#include <signal.h> /* for sig_atomic_t */
/*
* A job structure contains information about a job. A job is either a
@ -78,8 +78,8 @@ struct job {
extern pid_t backgndpid; /* pid of last background process */
extern int job_warning; /* user was warned about stopped jobs */
extern int in_waitcmd; /* Are we in wait? */
extern volatile sig_atomic_t breakwaitcmd; /* Should wait be terminated? */
extern int in_waitcmd; /* are we in waitcmd()? */
extern volatile sig_atomic_t breakwaitcmd; /* should wait be terminated? */
void setjobctl __P((int));
int fgcmd __P((int, char **));

View File

@ -39,14 +39,13 @@
static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id: miscbltin.c,v 1.15 1998/05/18 06:43:58 charnier Exp $";
"$Id: miscbltin.c,v 1.16 1998/08/24 10:20:36 cracauer Exp $";
#endif /* not lint */
/*
* Miscelaneous builtins.
*/
#include <stdlib.h> /* strtol() */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
@ -55,6 +54,7 @@ static const char rcsid[] =
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include "shell.h"

View File

@ -39,7 +39,7 @@
static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95";
#endif
static const char rcsid[] =
"$Id: trap.c,v 1.12 1998/08/24 10:20:36 cracauer Exp $";
"$Id: trap.c,v 1.13 1998/08/25 08:49:47 cracauer Exp $";
#endif /* not lint */
#include <signal.h>
@ -76,7 +76,7 @@ static const char rcsid[] =
MKINIT char sigmode[NSIG]; /* current value of signal */
int pendingsigs; /* indicates some signal received */
int in_dotrap = 0; /* Do we execute in a trap handler? */
int in_dotrap; /* do we execute in a trap handler? */
static char *trap[NSIG]; /* trap handler commands */
static volatile sig_atomic_t gotsig[NSIG];
/* indicates specified signal received */