git: 9front

Download patch

ref: 44a1831030df5708e11289f09715ea3663e78113
parent: 8db1d37a6cba6bf402a94e335c10dacc88badaca
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri May 29 22:03:18 EDT 2020

rc: avoid forking for final command that has variable assignments (to get $apid right)

basically, we want the following commands to print
the same pid twice:

rc -c 'cat /dev/pid &;echo $apid'

vs:

rc -c 'a=1 cat /dev/pid &;echo $apid'

basically, Xsimple() calls exitnext() to determine if
a simple command should be promoted to exec, by peeking
ahead into the code and searching for Xexit instruction.

Xexit might not follow immediately after the Xsimple
instruction because of redirections, which exitnext()
would skip.

but it would not skip the Xunlocal instructions that
where added by the variable assignment.

--- a/sys/src/cmd/rc/simple.c
+++ b/sys/src/cmd/rc/simple.c
@@ -12,7 +12,7 @@
 int
 exitnext(void){
 	union code *c=&runq->code[runq->pc];
-	while(c->f==Xpopredir) c++;
+	while(c->f==Xpopredir || c->f==Xunlocal) c++;
 	return c->f==Xexit;
 }
 
--