mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Researching #483 revealed several instances in coprocess cleanup where sh_close() is called with a file descriptor of -1 (which flags that the pipe is already closed). As offeeb62d1, this sets errno to EBADF. While the race condition triggered by this was fixed in411481eb, it's still better to avoid it. This re-applies most of the changes reverted in80767b1f.
This commit is contained in:
parent
411481eb04
commit
7a06d911e0
3 changed files with 14 additions and 8 deletions
|
|
@ -395,10 +395,11 @@ int job_reap(register int sig)
|
|||
/* check for coprocess completion */
|
||||
if(pid==sh.cpid)
|
||||
{
|
||||
sh_close(sh.coutpipe);
|
||||
sh_close(sh.cpipe[1]);
|
||||
sh.cpipe[1] = -1;
|
||||
sh.coutpipe = -1;
|
||||
if(sh.coutpipe > -1)
|
||||
sh_close(sh.coutpipe);
|
||||
if(sh.cpipe[1] > -1)
|
||||
sh_close(sh.cpipe[1]);
|
||||
sh.coutpipe = sh.cpipe[1] = -1;
|
||||
}
|
||||
else if(sh.subshell)
|
||||
sh_subjobcheck(pid);
|
||||
|
|
|
|||
|
|
@ -1275,10 +1275,13 @@ static noreturn void exscript(register char *path,register char *argv[],char **e
|
|||
sh.bckpid = 0;
|
||||
sh.st.ioset=0;
|
||||
/* clean up any cooperating processes */
|
||||
if(sh.cpipe[0]>0)
|
||||
if(sh.cpipe[0] > -1)
|
||||
sh_pclose(sh.cpipe);
|
||||
if(sh.cpid && sh.outpipe)
|
||||
if(sh.cpid && sh.outpipe && *sh.outpipe > -1)
|
||||
{
|
||||
sh_close(*sh.outpipe);
|
||||
*sh.outpipe = -1;
|
||||
}
|
||||
sh.cpid = 0;
|
||||
if(sp=fcfile())
|
||||
while(sfstack(sp,SF_POPSTACK));
|
||||
|
|
|
|||
|
|
@ -455,8 +455,10 @@ void sh_subjobcheck(pid_t pid)
|
|||
{
|
||||
if(sp->cpid==pid)
|
||||
{
|
||||
sh_close(sp->coutpipe);
|
||||
sh_close(sp->cpipe);
|
||||
if(sp->coutpipe > -1)
|
||||
sh_close(sp->coutpipe);
|
||||
if(sp->cpipe > -1)
|
||||
sh_close(sp->cpipe);
|
||||
sp->coutpipe = sp->cpipe = -1;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue