rc: fix Xpipefd unbalancing the redir stack

Xpipefd wants the pipe descriptor to be closed in turfredir(), so
it pushes the redirection, but this breaks Xpopredir after normal
redirection. so we shuffle the Xpipefd redir to the bottom of the
stack.
This commit is contained in:
cinap_lenrek 2018-09-08 14:49:00 +02:00
parent 217e8a0619
commit 2839760066
3 changed files with 18 additions and 1 deletions

View file

@ -123,6 +123,21 @@ pushredir(int type, int from, int to)
runq->redir = rp;
}
void
shuffleredir(void)
{
redir **rr, *rp;
rp = runq->redir;
if(rp==0)
return;
runq->redir = rp->next;
rp->next = runq->startredir;
for(rr = &runq->redir; *rr != rp->next; rr = &((*rr)->next))
;
*rr = rp;
}
var*
newvar(char *name, var *next)
{

View file

@ -55,6 +55,7 @@ void readhere(void);
word* searchpath(char*);
void setstatus(char*);
void setvar(char*, word*);
void shuffleredir(void);
void skipnl(void);
void start(code*, int, var*);
int truestatus(void);

View file

@ -185,7 +185,8 @@ Xpipefd(void)
default:
addwaitpid(pid);
close(sidefd);
pushredir(ROPEN, mainfd, mainfd); /* isn't this a noop? */
pushredir(ROPEN, mainfd, mainfd);
shuffleredir(); /* shuffle redir to bottom of stack for turfredir() */
strcpy(name, Fdprefix);
inttoascii(name+strlen(name), mainfd);
pushword(name);