bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Update on parent exiting after background command substitution


From: jneuheisel
Subject: Update on parent exiting after background command substitution
Date: Thu, 2 Jun 2005 13:03:51 -0400

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,  <unfinished ...>
[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 <unfinished ...>
[pid  5396] setpgid(5396, 5396 <unfinished ...>
[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,  <unfinished ...>
[pid  5329] write(1, "\33[40;joshua@hal:~\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 <unfinished ...>
[pid  5329] time( <unfinished ...>
[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 <unfinished ...>
[pid  5329] ioctl(0, TIOCSWINSZ <unfinished ...>
[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 <unfinished ...>
[pid  5329] ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS <unfinished ...>
[pid  5397] <... close resumed> )       = 0
[pid  5329] <... ioctl resumed> , {B38400 opost isig icanon echo ...}) = 0
[pid  5397] close(3 <unfinished ...>
[pid  5329] ioctl(0, SNDCTL_TMR_STOP or TCSETSW <unfinished ...>
[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])                = 0
[pid  5397] clone(Process 5398 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, 
child_tidptr=0xb7feb708) = 5398
[pid  5397] setpgid(5398, 5396)         = 0
[pid  5397] close(4)                    = 0
[pid  5397] close(4)                    = -1 EBADF (Bad file descriptor)
[pid  5398] setpgid(5398, 5396)         = 0
[pid  5397] clone( <unfinished ...>
[pid  5398] ioctl(255, TIOCSPGRP, [5396]) = 0
[pid  5398] close(5Process 5399 attached
 <unfinished ...>
[pid  5397] <... clone resumed> child_stack=0, 
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7feb708) 
= 5399
[pid  5398] <... close resumed> )       = 0
[pid  5397] setpgid(5399, 5396 <unfinished ...>
[pid  5398] close(6 <unfinished ...>
[pid  5397] <... setpgid resumed> )     = 0
[pid  5398] <... close resumed> )       = 0
[pid  5329] write(2, "\n", 1 <unfinished ...>
[pid  5398] close(3 <unfinished ...>
[pid  5329] <... write resumed> )       = 1
[pid  5397] close(3 <unfinished ...>
[pid  5329] write(2, "0:$ ", 4 <unfinished ...>
[pid  5397] <... close resumed> )       = 0
[pid  5329] <... write resumed> )       = 4
[pid  5397] close(5 <unfinished ...>
[pid  5329] read(0,  <unfinished ...>
[pid  5397] <... close resumed> )       = 0
[pid  5329] <... read resumed> 0xbfffe51f, 1) = -1 EIO (Input/output error)
[pid  5397] close(6)                    = 0
[pid  5398] <... close resumed> )       = 0
[pid  5329] ioctl(0, SNDCTL_TMR_STOP or TCSETSW <unfinished ...>
[pid  5398] dup2(4, 1 <unfinished ...>
[pid  5329] <... ioctl resumed> , {B38400 opost isig icanon echo ...}) = 0
[pid  5398] <... dup2 resumed> )        = 1
[pid  5397] ioctl(255, TIOCSPGRP <unfinished ...>
[pid  5398] close(4 <unfinished ...>
[pid  5397] <... ioctl resumed> , [5396]) = 0
[pid  5398] <... close resumed> )       = 0
[pid  5399] setpgid(5399, 5396)         = 0
[pid  5399] ioctl(255, TIOCSPGRP, [5396]) = 0
[pid  5397] waitpid(-1, Process 5397 suspended
 <unfinished ...>
[pid  5398] pipe( <unfinished ...>
[pid  5399] close(5 <unfinished ...>
[pid  5398] <... pipe resumed> [3, 4])  = 0
[pid  5399] <... close resumed> )       = 0
[pid  5399] close(6)                    = 0
[pid  5399] dup2(3, 0)                  = 0
[pid  5399] close(3)                    = 0
[pid  5329] write(2, "exit\n", 5)       = 5
[pid  5398] munmap(0xb7de4000, 4096)    = 0
[pid  5398] munmap(0xb7de3000, 4096)    = 0
[pid  5398] exit_group(0)               = ?
Process 5397 resumed
Process 5398 detached
[pid  5329] stat64("/home/joshua/.bash_history", {st_mode=S_IFREG|0600, 
st_size=12650, ...}) = 0
[pid  5329] open("/home/joshua/.bash_history", O_WRONLY|O_APPEND|O_LARGEFILE 
<unfinished ...>
[pid  5397] <... waitpid resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 
5398
[pid  5329] <... open resumed> )        = 3
[pid  5397] waitpid(-1, Process 5397 suspended
 <unfinished ...>
[pid  5399] pipe( <unfinished ...>
[pid  5329] write(3, "echo $$\nman strace\nman strace\n$("..., 38 <unfinished 
...>
[pid  5399] <... pipe resumed> [3, 4])  = 0
[pid  5329] <... write resumed> )       = 38
[pid  5329] close(3)                    = 0
[pid  5329] open("/home/joshua/.bash_history", O_RDONLY|O_LARGEFILE) = 3
[pid  5329] fstat64(3, {st_mode=S_IFREG|0600, st_size=12688, ...}) = 0
[pid  5329] read(3, "pwd\nls\nvi vis_dev.{h,c}\nvi vd.c\n"..., 12688) = 12688
[pid  5329] close(3)                    = 0
[pid  5399] munmap(0xb7de4000, 4096 <unfinished ...>
[pid  5329] open("/home/joshua/.bash_history", O_WRONLY|O_TRUNC|O_LARGEFILE 
<unfinished ...>
[pid  5399] <... munmap resumed> )      = 0
[pid  5399] munmap(0xb7de3000, 4096)    = 0
[pid  5399] exit_group(0)               = ?
Process 5397 resumed
Process 5399 detached
[pid  5329] <... open resumed> )        = 3
[pid  5329] write(3, "vi vis_dev.c\nvi vd.c\nmake\ncvs ud"..., 12656) = 12656
[pid  5329] close(3)                    = 0
[pid  5397] <... waitpid resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 
5399
[pid  5329] ioctl(255, TIOCSPGRP, [5329]) = 0
[pid  5397] ioctl(255, TIOCSPGRP, [5329]) = 0
[pid  5329] setpgid(0, 5329)            = 0
[pid  5329] munmap(0xb7de4000, 4096)    = 0
[pid  5397] close(3 <unfinished ...>
[pid  5329] munmap(0xb7de3000, 4096 <unfinished ...>
[pid  5397] <... close resumed> )       = -1 EBADF (Bad file descriptor)
[pid  5329] <... munmap resumed> )      = 0
[pid  5329] exit_group(0)               = ?
Process 5329 detached
[pid  5397] --- SIGCHLD (Child exited) @ 0 (0) ---
[pid  5397] waitpid(-1, 0xbfffe40c, WNOHANG) = -1 ECHILD (No child processes)
[pid  5397] munmap(0xb7de4000, 4096)    = 0
[pid  5397] munmap(0xb7de3000, 4096)    = 0
[pid  5397] exit_group(0)               = ?
Process 5397 detached
<... read resumed> "", 128)             = 0
--- SIGCHLD (Child exited) @ 0 (0) ---
waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WNOHANG) = 5397
waitpid(-1, 0xbfffe774, WNOHANG)        = -1 ECHILD (No child processes)
close(3)                                = 0
ioctl(255, TIOCSPGRP, [5329])           = -1 EPERM (Operation not permitted)
munmap(0xb7de4000, 4096)                = 0
munmap(0xb7de3000, 4096)                = 0
exit_group(0)                           = ?
Process 5396 detached




reply via email to

[Prev in Thread] Current Thread [Next in Thread]