maemo.org Bugzilla – Bug 5317
Shell does not save command history / Busybox doesn't handle SIGHUP properly
Last modified: 2010-11-22 20:22:33 UTC
You need to log in before you can comment on or make changes to this bug.
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
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).
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?
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.
-rw-r--r-- 1 root root
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?
(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. :)
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
Trapping SIGHUP alone seems sufficient to handle window closure.
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.
Similarly, the history is not saved when one types: exec some_command For instance: exec zsh -l
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.
(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.)