1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

Remove broken iousepipe/sh_iounpipe (re: a2196f94)

After that commit, iousepipe(), sh_iounpipe(), and supporting flags
were all broken and dead code. Since all command substitutions use
temp files now, they're unused; remove them.

I'm experimenting with reintroducing pipes to command substitutions
in a consistent way, as this is needed for them to wait for
grandchildren. If and when I ever manage to figure out how to do
that in a way that doesn't cause severe hanging and crashing bugs,
these functions may return in some form.

Related: https://github.com/ksh93/ksh/issues/124
This commit is contained in:
Martijn Dekker 2022-07-22 07:06:09 +02:00
parent ce3cc66d58
commit 39e467dab3
7 changed files with 18 additions and 65 deletions

View file

@ -329,7 +329,6 @@ struct Shell_s
char redir0; /* redirect of 0 */
char intrace; /* set when trace expands PS4 */
char *readscript; /* set before reading a script */
int subdup; /* bitmask for dups of 1 */
int *inpipe; /* input pipe pointer */
int *outpipe; /* output pipe pointer */
int cpipe[3];

View file

@ -721,7 +721,7 @@ struct argnod *sh_argprocsub(struct argnod *argp)
ap->argflag |= ARG_MAKE;
ap->argflag &= ~ARG_RAW;
fd = argp->argflag&ARG_RAW;
if(fd==0 && sh.subshell)
if(fd==0 && sh.comsub)
sh_subtmpfile();
#if SHOPT_DEVFD
sfwrite(sh.stk,e_devfdNN,8);

View file

@ -1173,7 +1173,7 @@ int sh_redirect(struct ionod *iop, int flag)
memset(ap, 0, ARGVAL);
if(iof&IOPUT)
ap->argflag = ARG_RAW;
else if(sh.subshell)
else if(sh.comsub)
sh_subtmpfile();
ap->argchn.ap = (struct argnod*)fname;
ap = sh_argprocsub(ap);
@ -1241,16 +1241,12 @@ int sh_redirect(struct ionod *iop, int flag)
}
if(sh.subshell && dupfd==1)
{
if(sfset(sfstdout,0,0)&SF_STRING)
if(sh.comsub)
sh_subtmpfile();
if(sh.comsub==1)
sh.subdup |= 1<<fn;
dupfd = sffileno(sfstdout);
}
else if(sh.sftable[dupfd])
sfsync(sh.sftable[dupfd]);
if(dupfd!=1 && fn < 10)
sh.subdup &= ~(1<<fn);
}
else if(fd=='-' && fname[1]==0)
{

View file

@ -89,7 +89,6 @@ static struct subshell
pid_t cpid;
int coutpipe;
int cpipe;
int subdup;
char subshare;
char comsub;
unsigned int rand_seed; /* parent shell $RANDOM seed */
@ -500,8 +499,6 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub)
subshell_data = sp;
sp->options = sh.options;
sp->jobs = job_subsave();
sp->subdup = sh.subdup;
sh.subdup = 0;
/* make sure initialization has occurred */
if(!sh.pathlist)
{
@ -872,7 +869,6 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub)
sh.exitval |= SH_EXITSIG;
}
sh.subshare = sp->subshare;
sh.subdup = sp->subdup;
sh.subshell--; /* decrease level of virtual subshells */
sh.realsubshell--; /* decrease ${.sh.subshell} */
subshell_data = sp->prev;
@ -898,11 +894,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub)
if(nsig>0)
kill(sh.current_pid,nsig);
if(sp->subpid)
{
job_wait(sp->subpid);
if(comsub)
sh_iounpipe();
}
sh.comsub = sp->comsub;
if(comsub && iop && sp->pipefd<0)
sfseek(iop,(off_t)0,SEEK_SET);

View file

@ -166,43 +166,6 @@ static inline double timeval_to_double(struct timeval tv)
}
#endif
/*
* The following two functions allow command substitution for non-builtins
* to use a pipe and to wait for the pipe to close before restoring to a
* temp file.
*/
static int subpipe[3],subdup,tsetio,usepipe;
static int iousepipe(void)
{
if(usepipe)
{
usepipe++;
sh_iounpipe();
}
if(sh_rpipe(subpipe) < 0)
return(0);
usepipe++;
subpipe[2] = sh_fcntl(subpipe[1],F_DUPFD,10);
sh_close(subpipe[1]);
return(1);
}
void sh_iounpipe(void)
{
char buff[SF_BUFSIZE];
if(!usepipe)
return;
--usepipe;
sh_close(subpipe[2]);
while(read(subpipe[0],buff,sizeof(buff))>0)
;
sh_close(subpipe[0]);
subpipe[0] = -1;
tsetio = 0;
usepipe = 0;
}
/*
* print time <t> in h:m:s format with precision <p>
*/
@ -1282,7 +1245,7 @@ int sh_exec(register const Shnode_t *t, int flags)
bp->sigset = 0;
bp->notify = 0;
bp->flags = (OPTIMIZE!=0);
if(sh.subshell && nv_isattr(np,BLT_NOSFIO))
if(sh.comsub && nv_isattr(np,BLT_NOSFIO))
sh_subtmpfile();
if(argn)
sh.exitval = (*sh.bltinfun)(argn,com,(void*)bp);
@ -1482,7 +1445,7 @@ int sh_exec(register const Shnode_t *t, int flags)
register pid_t parent;
int no_fork,jobid;
int pipes[3];
if(sh.subshell)
if(sh.comsub)
sh_subtmpfile();
if(no_fork = check_exec_optimization(type,execflg,execflg2,t->fork.forkio))
job.parent=parent=0;
@ -1860,7 +1823,7 @@ int sh_exec(register const Shnode_t *t, int flags)
echeck = 1;
job.exitval = 0;
job.curjobid = 0;
if(sh.subshell)
if(sh.comsub)
sh_subtmpfile();
sh.inpipe = pvo;
sh.outpipe = pvn;
@ -2938,7 +2901,6 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid)
if(sig>0)
kill(sh.current_pid,sig);
sh_sigcheck();
usepipe=0;
return(0);
}

View file

@ -413,13 +413,13 @@ unset foo
unset foo
foo=$(false) > /dev/null && err_exit 'failed command substitution with redirection not returning false'
expected=foreback
got=`print -n fore; (sleep 2;print back)&`
got=`print -n fore; (sleep .01; print back)&`
[[ $got == $expected ]] || err_exit "\`\` command substitution background process output error (expected '$expected', got '$got')"
got=$(print -n fore; (sleep .2;print back)&)
got=$(print -n fore; (sleep .01; print back)&)
[[ $got == $expected ]] || err_exit "\$() command substitution background process output error (expected '$expected', got '$got')"
got=${ print -n fore; (sleep 2;print back)& }
got=${ print -n fore; (sleep .01; print back)& }
[[ $got == $expected ]] || err_exit "\${} shared-state command substitution background process output error (expected '$expected', got '$got')"
function abc { sleep 2; print back; }
function abc { sleep .01; print back; }
function abcd { abc & }
got=$(print -n fore;abcd)
[[ $got == $expected ]] || err_exit "\$() command substitution background with function process output error (expected '$expected', got '$got')"

View file

@ -121,11 +121,15 @@ $0
$SHELL -c 'x=$(
cat << EOF
EOF)' 2> /dev/null || err_exit 'here-doc cannot be terminated by )'
if [[ $( IFS=:;cat <<-!
got=$( IFS=:; cat <<-!
$IFS$(print hi)$IFS
!) != :hi: ]]
then err_exit '$IFS unset by command substitution in here docs'
fi
!
)
exp=:hi:
[[ $got == "$exp" ]] || err_exit '$IFS unset by command substitution in here docs' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
if x=$($SHELL -c 'cat <<< "hello world"' 2> /dev/null)
then [[ $x == 'hello world' ]] || err_exit '<<< documents not working'
x=$($SHELL -c 'v="hello world";cat <<< $v' 2> /dev/null)