[Top][All Lists]

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

Re: Bash crashes on detaching Screen

From: Eduardo A . Bustamante López
Subject: Re: Bash crashes on detaching Screen
Date: Tue, 2 Dec 2014 13:44:01 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

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' crashed

You're using screen's power detach (-D -r), from 'man screen':
|       -D -r   Reattach a session. If necessary detach and logout remotely 

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:
address@hidden:~$ PS1='remote> '
remote> echo "$BASH_VERSION"
remote> screen -S bug -s ~/local/bin/bash
[... screen issues a clear screen... ]

Shell 2:
address@hidden:~$ PS1='attacher> '
attacher> screen -Drr bug
[... gets the cleared screen from before ...]

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:
address@hidden:~$ PS1='$$ remote> '
3994 remote> trap '' HUP # ignore SIGHUP
3994 remote> screen -S bug -s ~/local/bin/bash
[.. again screen clears the terminal ..]

Shell 2:
address@hidden:~$ PS1='$$ attacher> '
3954 attacher> screen -Drr bug
[.. we get the cleared screen ..]

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.

reply via email to

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