Bug 149 - shell history file is overwritten after every command
Summary: shell history file is overwritten after every command
Status: RESOLVED DUPLICATE of bug 185
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: PC Linux
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL: https://bugs.maemo.org/show_bug.cgi?i...
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-05 12:49 UTC by Andre Klapper
Modified: 2009-03-23 06:43 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Patch: make history saving/loading concurrent-safe (6.08 KB, patch)
2009-03-22 18:56 UTC, Denys Vlasenko
Details

Note You need to log in before you can comment on or make changes to this bug.
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 ***