NetBSD Problem Report #236
From gnats Wed Apr 27 20:08:37 1994
Received: from cis-ts3-slip4.cis.brown.edu (root@cis-ts3-slip4.cis.brown.edu [128.148.19.58]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id UAA00972 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Wed, 27 Apr 1994 20:08:28 -0700
Message-Id: <199404280309.XAA00345@cis-ts3-slip4.cis.brown.edu>
Date: Wed, 27 Apr 1994 23:09:50 -0400
From: Mark Weaver <mhw@cs.brown.edu>
Reply-To: mhw@cs.brown.edu
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: ash(1) parser is broken w.r.t. backgnd commands
X-Send-Pr-Version: 3.2
>Number: 236
>Category: bin
>Synopsis: ash(1) parser is broken w.r.t. backgnd commands
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: gnats-admin
>State: closed
>Class: sw-bug
>Submitter-Id: mhw
>Arrival-Date: Wed Apr 27 20:20:02 +0000 1994
>Closed-Date: Wed May 11 11:17:49 +0000 1994
>Last-Modified:
>Originator: Mark Weaver
>Release: current-940427
>Organization:
--------------------------------------------------------------------
Email: Mark_Weaver@brown.edu | Brown University
PGP Key: finger mhw@cs.brown.edu | Dept of Computer Science
>Environment:
System: NetBSD cis-ts3-slip4.cis.brown.edu 0.9a EXCELSIOR#2 i386
>Description:
Typing "sleep 1; sleep 10 &" executes the equivalent (roughly)
of "{ sleep 1; sleep 10; } &". This is because the parser is
broken w.r.t. lists. When a "&" is encountered in a list, all
the prior commands are grouped together and backgrounded, instead
of only the previous and-or construct being backgrounded.
This bug was reported earlier as well, claiming that the problem
occured within if statements only. Actually, it happens in any
list. However, in the outer body of the shell script, a list is
terminated at each newline (as a memory optimization), so the
problem went unnoticed.
[ Note that this bug is _not_ fixed by the 4.4 shell. But
I was able to apply this patch by hand. So this bug will
be fixed when it is integrated into NetBSD.
--jtc ]
>How-To-Repeat:
$ sleep 1; sleep 10 &
$ jobs
[1] 321 sleep 1; sleep 10
$
(first command above returns immediately)
mhw ~ % cat t
#!/bin/sh
(
sleep 2
echo 1
echo 2 &
echo 3
wait
)
mhw ~ % sh t
3
1
2
(with a 2 second pause after the 3 is printed)
>Fix:
*** parser.c.mhw1 Fri Dec 17 00:48:39 1993
--- parser.c Wed Apr 27 22:50:51 1994
***************
*** 144,174 ****
STATIC union node *
list(nlflag) {
union node *n1, *n2, *n3;
checkkwd = 2;
if (nlflag == 0 && tokendlist[peektoken()])
return NULL;
! n1 = andor();
for (;;) {
! switch (readtoken()) {
! case TBACKGND:
! if (n1->type == NCMD || n1->type == NPIPE) {
! n1->ncmd.backgnd = 1;
! } else if (n1->type == NREDIR) {
! n1->type = NBACKGND;
} else {
n3 = (union node *)stalloc(sizeof (struct nredir));
n3->type = NBACKGND;
! n3->nredir.n = n1;
n3->nredir.redirect = NULL;
! n1 = n3;
}
! goto tsemi;
! case TNL:
! tokpushback++;
/* fall through */
! tsemi: case TSEMI:
! if (readtoken() == TNL) {
parseheredoc();
if (nlflag)
return n1;
--- 144,188 ----
STATIC union node *
list(nlflag) {
union node *n1, *n2, *n3;
+ int tok;
checkkwd = 2;
if (nlflag == 0 && tokendlist[peektoken()])
return NULL;
! n1 = NULL;
for (;;) {
! n2 = andor();
! tok = readtoken();
! if (tok == TBACKGND) {
! if (n2->type == NCMD || n2->type == NPIPE) {
! n2->ncmd.backgnd = 1;
! } else if (n2->type == NREDIR) {
! n2->type = NBACKGND;
} else {
n3 = (union node *)stalloc(sizeof (struct nredir));
n3->type = NBACKGND;
! n3->nredir.n = n2;
n3->nredir.redirect = NULL;
! n2 = n3;
}
! }
! if (n1 == NULL) {
! n1 = n2;
! }
! else {
! n3 = (union node *)stalloc(sizeof (struct nbinary));
! n3->type = NSEMI;
! n3->nbinary.ch1 = n1;
! n3->nbinary.ch2 = n2;
! n1 = n3;
! }
! switch (tok) {
! case TBACKGND:
! case TSEMI:
! tok = readtoken();
/* fall through */
! case TNL:
! if (tok == TNL) {
parseheredoc();
if (nlflag)
return n1;
***************
*** 178,189 ****
checkkwd = 2;
if (tokendlist[peektoken()])
return n1;
- n2 = andor();
- n3 = (union node *)stalloc(sizeof (struct nbinary));
- n3->type = NSEMI;
- n3->nbinary.ch1 = n1;
- n3->nbinary.ch2 = n2;
- n1 = n3;
break;
case TEOF:
if (heredoclist)
--- 192,197 ----
>Release-Note:
>Audit-Trail:
From: "J.T. Conklin" <jtc>
To: GNATS administrator <gnats-admin>
Subject: Re: bin/236: ash(1) parser is broken w.r.t. backgnd commands
Date: Mon, 9 May 1994 16:40:12 -0700
`J.T. Conklin' made changes to this PR.
--- /var/tmp/gnats019085 Mon May 9 16:38:50 1994
+++ /var/tmp/gnatsa19085 Mon May 9 16:40:04 1994
@@ -43,6 +43,10 @@
terminated at each newline (as a memory optimization), so the
problem went unnoticed.
+
+ [ Note that this bug is _not_ fixed by the 4.4 shell.
+ --jtc ]
+
>How-To-Repeat:
$ sleep 1; sleep 10 &
State-Changed-From-To: open->analyzed
State-Changed-By: jtc
State-Changed-When: Wed May 11 09:55:04 1994
State-Changed-Why:
Submitted fix works. It will be applied against the 4.4 version of
the shell when it is integrated into NetBSD.
From: "J.T. Conklin" <jtc>
To: GNATS administrator <gnats-admin>
Subject: Re: bin/236: ash(1) parser is broken w.r.t. backgnd commands
Date: Wed, 11 May 1994 09:58:37 -0700
`J.T. Conklin' made changes to this PR.
--- /var/tmp/gnats029700 Wed May 11 09:56:47 1994
+++ /var/tmp/gnatsa29700 Wed May 11 09:58:29 1994
@@ -44,8 +44,13 @@
problem went unnoticed.
- [ Note that this bug is _not_ fixed by the 4.4 shell.
+ [ Note that this bug is _not_ fixed by the 4.4 shell. But
+ I was able to apply this patch by hand. So this bug will
+ be fixed when it is integrated into NetBSD.
+
--jtc ]
+
+
>How-To-Repeat:
State-Changed-From-To: analyzed->closed
State-Changed-By: jtc
State-Changed-When: Wed May 11 11:17:49 1994
State-Changed-Why:
Integrated 4.4 shell + this patch.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.