mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +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:
parent
ce3cc66d58
commit
39e467dab3
7 changed files with 18 additions and 65 deletions
|
@ -329,7 +329,6 @@ struct Shell_s
|
||||||
char redir0; /* redirect of 0 */
|
char redir0; /* redirect of 0 */
|
||||||
char intrace; /* set when trace expands PS4 */
|
char intrace; /* set when trace expands PS4 */
|
||||||
char *readscript; /* set before reading a script */
|
char *readscript; /* set before reading a script */
|
||||||
int subdup; /* bitmask for dups of 1 */
|
|
||||||
int *inpipe; /* input pipe pointer */
|
int *inpipe; /* input pipe pointer */
|
||||||
int *outpipe; /* output pipe pointer */
|
int *outpipe; /* output pipe pointer */
|
||||||
int cpipe[3];
|
int cpipe[3];
|
||||||
|
|
|
@ -721,7 +721,7 @@ struct argnod *sh_argprocsub(struct argnod *argp)
|
||||||
ap->argflag |= ARG_MAKE;
|
ap->argflag |= ARG_MAKE;
|
||||||
ap->argflag &= ~ARG_RAW;
|
ap->argflag &= ~ARG_RAW;
|
||||||
fd = argp->argflag&ARG_RAW;
|
fd = argp->argflag&ARG_RAW;
|
||||||
if(fd==0 && sh.subshell)
|
if(fd==0 && sh.comsub)
|
||||||
sh_subtmpfile();
|
sh_subtmpfile();
|
||||||
#if SHOPT_DEVFD
|
#if SHOPT_DEVFD
|
||||||
sfwrite(sh.stk,e_devfdNN,8);
|
sfwrite(sh.stk,e_devfdNN,8);
|
||||||
|
|
|
@ -1173,7 +1173,7 @@ int sh_redirect(struct ionod *iop, int flag)
|
||||||
memset(ap, 0, ARGVAL);
|
memset(ap, 0, ARGVAL);
|
||||||
if(iof&IOPUT)
|
if(iof&IOPUT)
|
||||||
ap->argflag = ARG_RAW;
|
ap->argflag = ARG_RAW;
|
||||||
else if(sh.subshell)
|
else if(sh.comsub)
|
||||||
sh_subtmpfile();
|
sh_subtmpfile();
|
||||||
ap->argchn.ap = (struct argnod*)fname;
|
ap->argchn.ap = (struct argnod*)fname;
|
||||||
ap = sh_argprocsub(ap);
|
ap = sh_argprocsub(ap);
|
||||||
|
@ -1241,16 +1241,12 @@ int sh_redirect(struct ionod *iop, int flag)
|
||||||
}
|
}
|
||||||
if(sh.subshell && dupfd==1)
|
if(sh.subshell && dupfd==1)
|
||||||
{
|
{
|
||||||
if(sfset(sfstdout,0,0)&SF_STRING)
|
if(sh.comsub)
|
||||||
sh_subtmpfile();
|
sh_subtmpfile();
|
||||||
if(sh.comsub==1)
|
|
||||||
sh.subdup |= 1<<fn;
|
|
||||||
dupfd = sffileno(sfstdout);
|
dupfd = sffileno(sfstdout);
|
||||||
}
|
}
|
||||||
else if(sh.sftable[dupfd])
|
else if(sh.sftable[dupfd])
|
||||||
sfsync(sh.sftable[dupfd]);
|
sfsync(sh.sftable[dupfd]);
|
||||||
if(dupfd!=1 && fn < 10)
|
|
||||||
sh.subdup &= ~(1<<fn);
|
|
||||||
}
|
}
|
||||||
else if(fd=='-' && fname[1]==0)
|
else if(fd=='-' && fname[1]==0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -89,7 +89,6 @@ static struct subshell
|
||||||
pid_t cpid;
|
pid_t cpid;
|
||||||
int coutpipe;
|
int coutpipe;
|
||||||
int cpipe;
|
int cpipe;
|
||||||
int subdup;
|
|
||||||
char subshare;
|
char subshare;
|
||||||
char comsub;
|
char comsub;
|
||||||
unsigned int rand_seed; /* parent shell $RANDOM seed */
|
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;
|
subshell_data = sp;
|
||||||
sp->options = sh.options;
|
sp->options = sh.options;
|
||||||
sp->jobs = job_subsave();
|
sp->jobs = job_subsave();
|
||||||
sp->subdup = sh.subdup;
|
|
||||||
sh.subdup = 0;
|
|
||||||
/* make sure initialization has occurred */
|
/* make sure initialization has occurred */
|
||||||
if(!sh.pathlist)
|
if(!sh.pathlist)
|
||||||
{
|
{
|
||||||
|
@ -872,7 +869,6 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub)
|
||||||
sh.exitval |= SH_EXITSIG;
|
sh.exitval |= SH_EXITSIG;
|
||||||
}
|
}
|
||||||
sh.subshare = sp->subshare;
|
sh.subshare = sp->subshare;
|
||||||
sh.subdup = sp->subdup;
|
|
||||||
sh.subshell--; /* decrease level of virtual subshells */
|
sh.subshell--; /* decrease level of virtual subshells */
|
||||||
sh.realsubshell--; /* decrease ${.sh.subshell} */
|
sh.realsubshell--; /* decrease ${.sh.subshell} */
|
||||||
subshell_data = sp->prev;
|
subshell_data = sp->prev;
|
||||||
|
@ -898,11 +894,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub)
|
||||||
if(nsig>0)
|
if(nsig>0)
|
||||||
kill(sh.current_pid,nsig);
|
kill(sh.current_pid,nsig);
|
||||||
if(sp->subpid)
|
if(sp->subpid)
|
||||||
{
|
|
||||||
job_wait(sp->subpid);
|
job_wait(sp->subpid);
|
||||||
if(comsub)
|
|
||||||
sh_iounpipe();
|
|
||||||
}
|
|
||||||
sh.comsub = sp->comsub;
|
sh.comsub = sp->comsub;
|
||||||
if(comsub && iop && sp->pipefd<0)
|
if(comsub && iop && sp->pipefd<0)
|
||||||
sfseek(iop,(off_t)0,SEEK_SET);
|
sfseek(iop,(off_t)0,SEEK_SET);
|
||||||
|
|
|
@ -166,43 +166,6 @@ static inline double timeval_to_double(struct timeval tv)
|
||||||
}
|
}
|
||||||
#endif
|
#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>
|
* 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->sigset = 0;
|
||||||
bp->notify = 0;
|
bp->notify = 0;
|
||||||
bp->flags = (OPTIMIZE!=0);
|
bp->flags = (OPTIMIZE!=0);
|
||||||
if(sh.subshell && nv_isattr(np,BLT_NOSFIO))
|
if(sh.comsub && nv_isattr(np,BLT_NOSFIO))
|
||||||
sh_subtmpfile();
|
sh_subtmpfile();
|
||||||
if(argn)
|
if(argn)
|
||||||
sh.exitval = (*sh.bltinfun)(argn,com,(void*)bp);
|
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;
|
register pid_t parent;
|
||||||
int no_fork,jobid;
|
int no_fork,jobid;
|
||||||
int pipes[3];
|
int pipes[3];
|
||||||
if(sh.subshell)
|
if(sh.comsub)
|
||||||
sh_subtmpfile();
|
sh_subtmpfile();
|
||||||
if(no_fork = check_exec_optimization(type,execflg,execflg2,t->fork.forkio))
|
if(no_fork = check_exec_optimization(type,execflg,execflg2,t->fork.forkio))
|
||||||
job.parent=parent=0;
|
job.parent=parent=0;
|
||||||
|
@ -1860,7 +1823,7 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
echeck = 1;
|
echeck = 1;
|
||||||
job.exitval = 0;
|
job.exitval = 0;
|
||||||
job.curjobid = 0;
|
job.curjobid = 0;
|
||||||
if(sh.subshell)
|
if(sh.comsub)
|
||||||
sh_subtmpfile();
|
sh_subtmpfile();
|
||||||
sh.inpipe = pvo;
|
sh.inpipe = pvo;
|
||||||
sh.outpipe = pvn;
|
sh.outpipe = pvn;
|
||||||
|
@ -2938,7 +2901,6 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid)
|
||||||
if(sig>0)
|
if(sig>0)
|
||||||
kill(sh.current_pid,sig);
|
kill(sh.current_pid,sig);
|
||||||
sh_sigcheck();
|
sh_sigcheck();
|
||||||
usepipe=0;
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,13 +413,13 @@ unset foo
|
||||||
unset foo
|
unset foo
|
||||||
foo=$(false) > /dev/null && err_exit 'failed command substitution with redirection not returning false'
|
foo=$(false) > /dev/null && err_exit 'failed command substitution with redirection not returning false'
|
||||||
expected=foreback
|
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 == $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 == $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')"
|
[[ $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 & }
|
function abcd { abc & }
|
||||||
got=$(print -n fore;abcd)
|
got=$(print -n fore;abcd)
|
||||||
[[ $got == $expected ]] || err_exit "\$() command substitution background with function process output error (expected '$expected', got '$got')"
|
[[ $got == $expected ]] || err_exit "\$() command substitution background with function process output error (expected '$expected', got '$got')"
|
||||||
|
|
|
@ -121,11 +121,15 @@ $0
|
||||||
$SHELL -c 'x=$(
|
$SHELL -c 'x=$(
|
||||||
cat << EOF
|
cat << EOF
|
||||||
EOF)' 2> /dev/null || err_exit 'here-doc cannot be terminated by )'
|
EOF)' 2> /dev/null || err_exit 'here-doc cannot be terminated by )'
|
||||||
if [[ $( IFS=:;cat <<-!
|
|
||||||
|
got=$( IFS=:; cat <<-!
|
||||||
$IFS$(print hi)$IFS
|
$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)
|
if x=$($SHELL -c 'cat <<< "hello world"' 2> /dev/null)
|
||||||
then [[ $x == 'hello world' ]] || err_exit '<<< documents not working'
|
then [[ $x == 'hello world' ]] || err_exit '<<< documents not working'
|
||||||
x=$($SHELL -c 'v="hello world";cat <<< $v' 2> /dev/null)
|
x=$($SHELL -c 'v="hello world";cat <<< $v' 2> /dev/null)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue