Bug 723

Summary: Busybox shell doesn't handle SIGHUP properly
Product: Busybox Reporter: Andre Klapper <a9016009>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: a9016009, busybox-cvs
Priority: P5    
Version: 1.12.x   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
URL: https://bugs.maemo.org/show_bug.cgi?id=5317
Host: Target:
Build:

Description Andre Klapper 2009-11-17 21:52:47 UTC
Forwarding from https://bugs.maemo.org/show_bug.cgi?id=5317 .
Unsure whether bug 625 is related here.

Also see https://bugs.maemo.org/show_bug.cgi?id=5317 .


SOFTWARE VERSION:
1.2009.41-10

STEPS TO REPRODUCE THE PROBLEM:
1. Open XTerm
2. Type and execute several commands
3. Exit XTerm
4. Open XTerm
5. Press UP arrow button

EXPECTED OUTCOME:
You should see the command you last typed at step #2.

ACTUAL OUTCOME:
Command history is empty.

REPRODUCIBILITY:
always

OTHER COMMENTS:
This may be indirectly related to the patch that was applied in Maemo to fix https://bugs.busybox.net/show_bug.cgi?id=185 (if ash didn't save history when killed before that no one would notice) - still in NEW state here.


------- Comment #9 From Tamminen Eero (Nokia) 2009-11-10 17:30:34 -------

Ctrl-d saves command history, as expected.
Killing X-term wiht "X" button does not, as that's done by XTerm to Busybox 
when the window is closed, according to strace:
# strace -f -p 2117
Process 2117 attached - interrupt to quit
read(0, 0xbe83d1cf, 1)                  = ? ERESTARTSYS (To be restarted)
--- SIGHUP (Hangup) @ 0 (0) ---
Process 2117 detached 

Seems like Busybox shell doesn't handle SIGHUP properly.  I.e. set some flag in
signal handler and in main loop exit gracefully (with history saving) when the
signal delivery interrupts its select() syscall.

(Other way to safely notify the main thread about the async signal delivery
would be using a pipe added to select(), but that's a bit of an overkill.)

WORKAROUND:
Setting trap handler in .profile
Comment 1 Denys Vlasenko 2009-11-18 10:51:24 UTC
Current version saves history after each command, thus does not have this problem:

# ./busybox ash
~/srcdevel/bbox/fix/busybox.t5 # kill -HUP $$
Hangup
# ./busybox ash
(pressed up arrow:)
~/srcdevel/bbox/fix/busybox.t5 # kill -HUP $$

> (Other way to safely notify the main thread about the async signal delivery
would be using a pipe added to select(), but that's a bit of an overkill.)

We do not have threads, nor use select/poll for input in our shells.
Comment 2 Denys Vlasenko 2009-11-29 02:11:43 UTC
It is already fixed for some time, including released versions.