I have attached a different fix that doesn't have the problem the last one
does.  However, if the last command in the pipeline is a shell built-in, it
could hang for large output.

Let me know if this works for you.



On Fri, Jul 25, 2014 at 4:04 AM, Dr. Werner Fink <wer...@suse.de> wrote:

> On Thu, Jul 24, 2014 at 11:35:01AM -0400, David Korn wrote:
> > I finally got a chance to look at this.
> >
> > The problem is that the standard is ambiguous about when a command
> > substitution ends.
> >
> > The bourne shell used a pipe for command substitution and command
> > substitution  terminated when the pipe closed.  Thus, if you had a
> command
> > the wrote on standard output, forked and exited and the child wrote on
> that
> > pipe, the output from both processes was part of the command
> substitution.
> >
> > ksh considered the command substitution done when the command completed
> and
> > used memory for files less that 64K(IOBSIZE)  and this created a tmp file
> > if it was larger.
> >
> > I tried to restore the old bourne shell semantics for `` so that the
> > foreback test would work.  However, this caused the example you have to
> > hang.  Here is a change which should fix this by using pipes for all ``
> not
> > just large ones.  Here is the one line patch:
> >
> > --- old/sh/subshell.c      Wed Apr  2 09:57:00 2014
> > +++new/sh/subshell.c       Thu Jul 24 11:19:43 2014
> > @@ -593,7 +574,7 @@
> >                         sp->tmpfd = -1;
> >                         sp->pipefd = -1;
> >                         /* use sftmp() file for standard output */
> > -                       if(!(iop = sftmp(comsub==1?PIPE_BUF:IOBSIZE)))
> > +                       if(!(iop = sftmp(comsub==1?0:IOBSIZE)))
> >                         {
> >                                 sfswap(sp->saveout,sfstdout);
> >
> > errormsg(SH_DICT,ERROR_system(1),e_tmpcreate);
> >
> >
> > Let me know.
> >
>
> This works for the specific code but break other tests,
> from ksh test suite
>
>  [ 1162s] test subshell begins at 2014-07-25+07:39:05
>  [ 1175s] foo
>  [ 1175s]        subshell.sh[642]: nested command substitution with 2>&1
> not working
>  [ 1178s] test subshell failed at 2014-07-25+07:39:21 with exit code 1 [
> 70 tests 1 error ]
>  [ 1178s] test subshell(C.UTF-8) begins at 2014-07-25+07:39:21
>  [ 1194s] foo
>  [ 1194s]        subshell.sh[642]: nested command substitution with 2>&1
> not working
>  [ 1197s] test subshell(C.UTF-8) failed at 2014-07-25+07:39:40 with exit
> code 1 [ 70 tests 1 error ]
>  [ 1197s] test subshell(shcomp) begins at 2014-07-25+07:39:40
>  [ 1211s] foo
>  [ 1211s]        shcomp-subshell.ksh[642]: nested command substitution
> with 2>&1 not working
>  [ 1214s] test subshell(shcomp) failed at 2014-07-25+07:39:57 with exit
> code 1 [ 70 tests 1 error ]
>
> from my own test suite
>
>  [ 1233s] ++ /tmp/ksh-build.D5gJUl/bin/ksh -k -c 'd=`/bin/echo x y=z`;
> echo $d x y=z'
>  [ 1233s] + result='x
>  [ 1233s] x'
>  [ 1233s] + test 'x
>  [ 1233s] x' = 'x x'
>  [ 1233s] + exit 1
>
> also further tests do fail
>
>  result=$(/tmp/ksh-build.D5gJUl/bin/ksh -c 'echo | echo "x`/bin/echo y`"')
>  echo "$result"
>  x
>  y
>
This doesn't happen with the new version.

>  result=$(/tmp/ksh-build.D5gJUl/bin/ksh -c 'echo | echo "x$(/bin/echo y)"')
>  echo "$result"
>  xy
>
> now it seems that newlines will cause trouble.
>
> Also the question rise why there is this difference between `...` and
> $(...) or
> why not map `...` to $(...) ?
>
The reason is backward compatibility.  With the Bourne shell, `...` used
pipes and waited for the pipe to close to decide when `` is complete.
$(...) uses temp file and if a process in `` forks and the parent exits,
$(...) won't get the output from the parent like `` will.


>
> Werner
>
> --
>   "Having a smoking section in a restaurant is like having
>           a peeing section in a swimming pool." -- Edward Burr
>

Attachment: subhang.patch
Description: Binary data

_______________________________________________
ast-developers mailing list
ast-developers@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to