Bug 149

Summary: shell history file is overwritten after every command
Product: Busybox Reporter: Andre Klapper <a9016009>
Component: OtherAssignee: unassigned
Status: RESOLVED DUPLICATE    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
URL: https://bugs.maemo.org/show_bug.cgi?id=4174
Host: Target:
Build:
Attachments: Patch: make history saving/loading concurrent-safe

Description Andre Klapper 2009-03-05 12:49:11 UTC
Forwarding from https://bugs.maemo.org/show_bug.cgi?id=4174 .

VERSION: 1.10.2

STEPS TO REPRODUCE THE PROBLEM:
1. Establish a shell session (osso-xterm or ssh, user or root, doesn't matter).
2. Run "ls -l .ash_history" repeatedly.

EXPECTED OUTCOME:
History file is only updated when shell exits.

ACTUAL OUTCOME:
History file is re-written after every command entered
(libbb/linedit.c:remember_in_history).  This is causing unnecessary wear on the
flash and wastes a bit of power.  There are also side-effects with the way
loading the history is handled (will post another bug shortly).

REPRODUCIBILITY:
Always.

OTHER COMMENTS:
There's no way to disable history saving as in most shells by setting an
environment variable, and unsetting HISTFILE doesn't change anything.

The logic of when to save/load still seems the same currently in both trunk (r23938) and the busybox_1_13_stable branch (r24175).
Comment 1 Denys Vlasenko 2009-03-22 18:56:46 UTC
Created attachment 181 [details]
Patch: make history saving/loading concurrent-safe

Please try this patch.

It makes the following changes:
* all history writes always append (not overwrite) history files
* they reload history if they detect that file length has changed since last
write
* they trim history file only when it grows 4 times longer thna MAXLINES
* they do this atomically by creating new file and renaming it to old.
Comment 2 Denys Vlasenko 2009-03-23 06:43:43 UTC

*** This bug has been marked as a duplicate of bug 185 ***