Parent shell sometimes exits after command substitution and back-grounding

2005-06-02 Thread jneuheisel
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/tmp/REMOVEME/LOCAL/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H  -I.  -I/tmp/REMOVEME/bash-3.0 
-I/tmp/REMOVEME/bash-3.0/include -I/tmp/REMOVEME/bash-3.0/lib   -g -O2
uname output: Linux hal.barc.equinoxsensors.com 2.6.11.11 #1 SMP Wed Jun 1 
09:06:51 EDT 2005 i686 i686 i386 GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 3.0
Patch Level: 16
Release Status: release

Description:
bash 3.0 sometimes incorrectly exits when executing an interactive 
background
command that contains process substitution.  This happened with bash 3.0
and patch 14, so I compiled bash 3.0 with all the patches up to 16, and 
it
still happens.

Repeat-By:
In an interactive shell, repeatedly execute the command:
prompt>  echo $(ls * | sort -n) &
After a random number of executions, the parent shell will exit with
a return value of 0.

Fix:
Unknown


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Update on parent exiting after background command substitution

2005-06-02 Thread jneuheisel
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/tmp/REMOVEME/LOCAL/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H  -I.  -I/tmp/REMOVEME/bash-3.0 
-I/tmp/REMOVEME/bash-3.0/include -I/tmp/REMOVEME/bash-3.0/lib   -g -O2
uname output: Linux hal.barc.equinoxsensors.com 2.6.11.11 #1 SMP Wed Jun 1 
09:06:51 EDT 2005 i686 i686 i386 GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 3.0
Patch Level: 16
Release Status: release

Description:
I had previously sent a bug-report explaining that a parent bash
process would sometimes exit if a background interactive command was issued
that contained a process substitution.  I now have found the cause of the
problem, and detail that below.

Repeat-By:
Begin an interactive bash session.
Execute the command "$(:|:)&", without the quotes.
Continue to execute the above command until the parent shell
exits.

Fix:
While I don't have a fix, I do know what went wrong.  I've copied
an strace-capture of the problem below.

The parent bash shell is process 5329.  It reads the input, and
forks.  The child is process 5396.  This process forks, and the child is
5397.  This process forks twice, and its children are 5398 and 5399.

The problem starts with the following system call:
[pid  5398] ioctl(255, TIOCSPGRP, [5396]) = 0
Here, process 5398 sets the foreground group to 5396 (which I think
is not the correct thing to do).  Now, the parent bash shell tries to
read from stdin, and gets rejected since it is no longer in the foreground
group for the terminal:
[pid  5329] read(0,  
[pid  5329] <... read resumed> 0xbfffe51f, 1) = -1 EIO (Input/output error)
Receiving the error, the parent shell exits.

This also helps to explain why the problem only sometimes occurs.
The problem will only show if the ioctl(TIOCSPGRP) call happens before the
read() call.



Process 5329 attached - interrupt to quit
read(0, "$", 1) = 1
write(2, "$", 1)= 1
read(0, "(", 1) = 1
write(2, "(", 1)= 1
read(0, ":", 1) = 1
write(2, ":", 1)= 1
read(0, "|", 1) = 1
write(2, "|", 1)= 1
read(0, ":", 1) = 1
write(2, ":", 1)= 1
read(0, ")", 1) = 1
write(2, ")", 1)= 1
read(0, "&", 1) = 1
write(2, "&", 1)= 1
read(0, "\r", 1)= 1
write(2, "\n", 1)   = 1
ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
time(NULL)  = 1117725134
pipe([3, 4])= 0
clone(Process 5396 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, 
child_tidptr=0xb7feb708) = 5396
[pid  5329] setpgid(5396, 5396) = 0
[pid  5329] close(3)= 0
[pid  5329] close(4 
[pid  5396] setpgid(5396, 5396 
[pid  5329] <... close resumed> )   = 0
[pid  5396] <... setpgid resumed> ) = 0
[pid  5396] close(4)= 0
[pid  5396] read(3, "", 1)  = 0
[pid  5396] close(3)= 0
[pid  5396] pipe([3, 4])= 0
[pid  5396] clone(Process 5397 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, 
child_tidptr=0xb7feb708) = 5397
[pid  5396] setpgid(5397, 5329) = 0
[pid  5329] write(1, "[1] 5396\n", 9)   = 9
[pid  5396] close(4)= 0
[pid  5396] read(3,  
[pid  5329] write(1, "\33[40;[EMAIL PROTECTED]:~\7", 18) = 18
[pid  5329] time(NULL)  = 1117725134
[pid  5329] stat64("/var/spool/mail/joshua", {st_mode=S_IFREG|0660, st_size=0, 
...}) = 0
[pid  5397] setpgid(5397, 5329 
[pid  5329] time( 
[pid  5397] <... setpgid resumed> ) = 0
[pid  5329] <... time resumed> NULL)= 1117725134
[pid  5329] ioctl(255, TIOCSPGRP, [5329]) = 0
[pid  5329] ioctl(0, TIOCGWINSZ, {ws_row=34, ws_col=92, ws_xpixel=1020, 
ws_ypixel=764}) = 0
[pid  5397] dup2(4, 1 
[pid  5329] ioctl(0, TIOCSWINSZ 
[pid  5397] <... dup2 resumed> )= 1
[pid  5329] <... ioctl resumed> , {ws_row=34, ws_col=92, ws_xpixel=1020, 
ws_ypixel=764}) = 0
[pid  5397] close(4 
[pid  5329] ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS 
[pid  5397] <... close resumed> )   = 0
[pid  5329] <... ioctl resumed> , {B38400 opost isig icanon echo ...}) = 0
[pid  5397] close(3 
[pid  5329] ioctl(0, SNDCTL_TMR_STOP or TCSETSW 
[pid  5397] <... close resumed> )   = 0
[pid  5329] <... ioctl resumed> , {B38400 opost isig -icanon -echo ...}) = 0
[pid  5397] pipe([3, 4])= 0
[pid  5397] pipe([5, 6])