Bug 5317 - (int-143013) Shell does not save command history / Busybox doesn't handle SIGHUP properly
(int-143013)
: Shell does not save command history / Busybox doesn't handle SIGHUP properly
Status: RESOLVED FIXED
Product: Core
Busybox
: 5.0/(1.2009.42-11)
: All Maemo
: Low normal with 10 votes (vote)
: Harmattan
Assigned To: Turo Janka
: busybox-bugs
: https://bugs.busybox.net/show_bug.cgi...
: upstream
:
:
  Show dependency tree
 
Reported: 2009-10-12 14:08 UTC by luarvique
Modified: 2010-11-22 20:22 UTC (History)
4 users (show)

See Also:


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description luarvique (reporter) 2009-10-12 14:08:19 UTC
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
Comment 1 Lucas Maneos 2009-10-12 20:59:02 UTC
Confirming.  History saving does work when exiting the shell with exit or
Ctrl-D instead of closing the terminal.

I think it may be indirectly related to the fix for bug 4174 (if ash didn't
save history when killed before that no one would notice).
Comment 2 Andre Klapper maemo.org 2009-10-14 20:21:02 UTC
When using Control+D or typing "exit" and then starting the Terminal again I
still do not get any history provided when pressing the Arrow Up key.
Running 1.2009.41-10 here, anything I'm missing?
Comment 3 Lucas Maneos 2009-10-14 20:32:23 UTC
Can you check ownership/group of /home/user/.ash_history?  It seems that
gainroot doesn't set $HOME correctly so when the root shell exits it overwrites
user's history with root owner/group.
Comment 4 Andre Klapper maemo.org 2009-10-14 20:38:31 UTC
-rw-r--r--   1 root   root
Comment 5 Lucas Maneos 2009-10-14 20:48:26 UTC
Comment 3 is wrong.  The root shell does overwrite the user's history file, but
it keeps the ownership if the file already exists.  So this is probably
triggered by becoming root before exiting the first terminal session after
unboxing/reflashing.

Anyway, since this is two separate bugs we should split them up.  Andre, is
int-143013 the "ash doesn't save history when killed" or the "root overwrites
user's history" one?
Comment 6 Andre Klapper maemo.org 2009-10-14 21:07:06 UTC
(In reply to comment #5)
> Anyway, since this is two separate bugs we should split them up.  Andre, is
> int-143013 the "ash doesn't save history when killed" or the "root overwrites
> user's history" one?

I just copied luarvique's (perfect) comment 0 to int-143013. :)
Comment 7 Lucas Maneos 2009-10-29 15:26:13 UTC
I sort of forgot about this one, sorry...

I filed the "gainroot shell writes on user's history" as bug 5896.

For the "doesn't save history when terminated by signal" case:

1. Start xterm.
2. Run "echo $$" and note the PID.
3. In another xterm or ssh session run "strace -p <PID>" and watch the output.
4. Exit the first xterm's shell by "exit" or Ctrl-D.
5. Repeat steps 1-3.
6. Close the new xterm window.

After step 4, the strace output is:

Nokia-N900-41-10:~# strace -p 2149
Process 2149 attached - interrupt to quit
read(0, "\4", 1)                        = 1
ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon echo ...}) = 0
rt_sigaction(SIGWINCH, {SIG_DFL, [WINCH], SA_RESTART|0x4000000}, {0x4cb7c,
[WINCH], SA_RESTART|0x4000000}, 8) = 0
open("/home/user/.ash_history", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x40002000
write(3, "blablabla"..., 202) = 202
close(3)                                = 0
munmap(0x40002000, 4096)                = 0
ioctl(10, TIOCSPGRP, [2149])            = 0
setpgid(0, 2149)                        = -1 EPERM (Operation not permitted)
close(10)                               = 0
exit_group(0)                           = ?
Process 2149 detached

ie, the history is clearly saved.  After step 6 however it is:

Nokia-N900-41-10:~# strace -p 2906
Process 2906 attached - interrupt to quit
read(0, 0xbefa920f, 1)                  = ? ERESTARTSYS (To be restarted)
--- SIGHUP (Hangup) @ 0 (0) ---
Process 2906 detached

ie, the shell process just terminates without saving the history.  It really
should install a signal handler that exits the shell cleanly, but a simpler
workaround without patching the source would be something like:

$ echo "trap exit SIGHUP SIGINT SIGTERM" >> /home/user/.profile
Comment 8 Josh Triplett 2009-12-16 02:34:33 UTC
Trapping SIGHUP alone seems sufficient to handle window closure.
Comment 9 Josh Triplett 2009-12-16 02:42:02 UTC
Also, for anyone who comes across this bug, gets ash to save history, and then
finds it only saves 15 lines, see bug 7014 for that.
Comment 10 Vincent Lefevre 2010-02-03 23:52:07 UTC
Similarly, the history is not saved when one types: exec some_command
For instance: exec zsh -l
Comment 11 Andre Klapper maemo.org 2010-11-22 18:27:01 UTC
This does not happen in Harmattan anymore (the version after Maemo5) which uses
Busybox 1.18, hence setting tentative Target Milestone to "Harmattan".
Tested with window closing (X button) and via "exit" command, in both cases
history was remembered. Bug 7014 is still valid in Harmattan though.
In case a fix for Maemo5 will be released (decision is up to Nokia) I will
reset the Target Milestone field to an earlier version than Harmattan.
Comment 12 Vincent Lefevre 2010-11-22 20:22:33 UTC
(In reply to comment #11)
> This does not happen in Harmattan anymore (the version after Maemo5) which uses
> Busybox 1.18, hence setting tentative Target Milestone to "Harmattan".
> Tested with window closing (X button) and via "exit" command, in both cases
> history was remembered.

Could you also try with "exec some_command" please?
(Typically, some_command could be another shell.)