On 12/02, Eduardo A. Bustamante López wrote:
On Tue, Dec 02, 2014 at 11:29:59PM +0530, Darshit Shah wrote:On 12/02, Darshit Shah wrote:[...]>When I attempt to detach a running Screen session using `screen -Drr >,session name` command, the original shell which contained the screen >session does not return to a prompt. It instead remains hung and a while >later I get the message: > >Warning: Program '/bin/bash' crashedYou're using screen's power detach (-D -r), from 'man screen': | -D -r Reattach a session. If necessary detach and logout remotely first. Notice the *logout* part. If you check screen.c (from GNU screen's source code), you will find: | 1896 *D_POWER SIG_POWER_BYE power detach -- attacher kills his parent | 1897 *D_REMOTE_POWER SIG_POWER_BYE remote power detach -- both Then, in attacher.c, function Attach(how): 185 if (ret == SIG_POWER_BYE) 186 { 187 int ppid; 188 if (setgid(real_gid) || setuid(real_uid)) 189 Panic(errno, "setuid/gid"); 190 if ((ppid = getppid()) > 1) 191 Kill(ppid, SIGHUP); /* notice this part */ 192 exit(0); 193 } It sends a SIGHUP to the parent process, i.e. bash. So, now that we know that, let's test it: Shell 1: dualbus@hp:~$ PS1='remote> ' remote> echo "$BASH_VERSION" 4.3.30(1)-maint remote> screen -S bug -s ~/local/bin/bash [... screen issues a clear screen... ] dualbus@hp:~$ Shell 2: dualbus@hp:~$ PS1='attacher> ' attacher> screen -Drr bug [... gets the cleared screen from before ...] dualbus@hp:~$ Shell 1: [remote power detached from 3739.bug] zsh: hangup ~/local/bin/bash ^ this tells us that bash was killed by a SIGHUP Now, let's try again, ignoring SIGHUP: Shell 1: dualbus@hp:~$ PS1='$$ remote> ' 3994 remote> trap '' HUP # ignore SIGHUP 3994 remote> screen -S bug -s ~/local/bin/bash [.. again screen clears the terminal ..] dualbus@hp:~$ Shell 2: dualbus@hp:~$ PS1='$$ attacher> ' 3954 attacher> screen -Drr bug [.. we get the cleared screen ..] dualbus@hp:~$ Shell 1: [remote power detached from 4043.bug] 3994 remote> echo I am alive I am alive #1 shell survived the power detach, because we ignored the SIGHUP sent by screen to its parent. Now... what does this mean? I means that: * It's not a bash bug. Bash is supposed to die from SIGHUP if you're not doing anything to handle it. In fact, if you're using that screen's feature, it's *supposed* to log out/kill its parent shell. * It happens to other shells.I just recompiled my Bash with debugging symbols and attempted to run Bash under gdb. Here is the trace I received: [remote power detached from 19442.pts-1.mordor] Program received signal SIGHUP, Hangup.Yep, dies from SIGHUP. Don't use screen's power detach (-D -r) if you don't want this to happen. I normally use (-d -r), which doesn't have this effect.
Hey Eduardo,Thanks a lot for such a detailed explanation of why this happens. I guess I didn't read the Screen Man page correctly and started using power detach.
For a long time I had no issues, but it seems like Konsole has problems when Bash suddenly exits like that. None of the other emulators gave any serious problems, but Konsole would be stuck with a crash notice. It was this crash notice which led me to believe that the fault is in Bash.
I'll start using the normal detach, -d -r, and also report this issue to the Konsole team and see such exits can be handled more gracefully by them.
-- Thanking You, Darshit Shah
pgplVLO8rdo1o.pgp
Description: PGP signature