Hi,

we've found a regression in ksh. For following script (see below), ksh 2010-12-01 and older print two lines (one child, one parent), but 2010-12-12 and newer print three lines (one child, parent twice).

Reproducer:
===============cut here===========================
#!/bin/sh
cat >/tmp/test_parent <<EOF
#!/bin/ksh

/tmp/test_child >/tmp/abc |&

sleep 3600
print -p "hello world"
EOF

cat >/tmp/test_child <<EOF
#!/bin/ksh

read var
print $var
EOF

chmod +x /tmp/test_child /tmp/test_parent

/tmp/test_parent >/dev/null 2>&1 &
sleep 1
ps | sed -n -e '/sed /d' -e '/test_parent/p'  -e '/test_child/p'

exec >/dev/null 2>&1
killall test_child
killall test_parent
rm -f /tmp/test_child /tmp/test_parent
===============cut here===========================

Old working versions print:
$ ./reproducer.sh
 8263 pts/4    00:00:00 test_parent
 8265 pts/4    00:00:00 test_child

new versions print:
$ ./reproducer.sh
15093 pts/4    00:00:00 test_parent
15095 pts/4    00:00:00 test_parent
15096 pts/4    00:00:00 test_child

This is caused by following change:
===============cut here===========================
--- old/include/defs.h  Wed Nov  3 16:04:52 2010
+++ new/include/defs.h  Sun Dec  5 12:18:54 2010
@@ -162,6 +162,7 @@
        pid_t           cpid; \
        pid_t           spid;           /* subshell process id */ \
        pid_t           pipepid; \
+       pid_t           outpipepid; \
        int             topfd; \
        int             savesig; \
        unsigned char   *sigflag;       /* pointer to signal states */ \
--- old/sh/io.c Thu Dec  2 10:39:41 2010
+++ new/sh/io.c Sun Dec  5 19:32:44 2010
@@ -1399,7 +1399,7 @@
                        }
                        if(!np)
                        {
-                               if(flag==0 || tname)
+ if(flag==0 || tname || (flag==1 && fn==1 && (shp->fdstatus[fn]&IONOSEEK) && shp->outpipepid && shp->outpipepid==getpid()))
                                {
                                        if(fd==fn)
                                        {
--- old/sh/xec.c        Thu Dec  2 15:56:45 2010
+++ new/sh/xec.c        Sun Dec  5 19:33:28 2010
@@ -2928,6 +2928,7 @@
 #if !_std_malloc
        vmtrace(-1);
 #endif
+       shp->outpipepid = ((flags&FPOU)?getpid():0);
        /* This is the child process */
        if(shp->trapnote&SH_SIGTERM)
                sh_exit(SH_EXITSIG|SIGTERM);
===============cut here===========================

which is probably this change:
10-12-06 A bug in which a pipeline could terminate prematurely for a pipeline whose right hand side is a builtin, and whose left hand side ends in a simple command that has standard output redirected has been fixed.


Let me know if you need more information.

Michal


_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to