aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-03-22 19:00:05 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-03-22 19:00:05 +0000
commit57abf9e947fa3f7d69f7adb97023b299916ee63c (patch)
treebcc36a5d96b56859763bd52a52377ed1c081326a /include
parent3fd104630020168ead90123e45d848d4d2d0a555 (diff)
downloadbusybox-w32-57abf9e947fa3f7d69f7adb97023b299916ee63c.tar.gz
busybox-w32-57abf9e947fa3f7d69f7adb97023b299916ee63c.tar.bz2
busybox-w32-57abf9e947fa3f7d69f7adb97023b299916ee63c.zip
libbb: make history saving/loading concurrent-safe
* all history writers 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 than MAXLINES * they do this atomically by creating new file and renaming it to old Unfortunately, this comes at a price: function old new delta load_history - 346 +346 read_line_input 3155 3358 +203 new_line_input_t 17 31 +14 ...irrelevant small jitter... ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/5 up/down: 573/-13) Total: 560 bytes
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/include/libbb.h b/include/libbb.h
index a2042fe5c..7bf9469cb 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1187,9 +1187,9 @@ unsigned long long bb_makedev(unsigned int major, unsigned int minor) FAST_FUNC;
1187#if ENABLE_FEATURE_EDITING 1187#if ENABLE_FEATURE_EDITING
1188/* It's NOT just ENABLEd or disabled. It's a number: */ 1188/* It's NOT just ENABLEd or disabled. It's a number: */
1189#ifdef CONFIG_FEATURE_EDITING_HISTORY 1189#ifdef CONFIG_FEATURE_EDITING_HISTORY
1190#define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0) 1190# define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0)
1191#else 1191#else
1192#define MAX_HISTORY 0 1192# define MAX_HISTORY 0
1193#endif 1193#endif
1194typedef struct line_input_t { 1194typedef struct line_input_t {
1195 int flags; 1195 int flags;
@@ -1197,7 +1197,11 @@ typedef struct line_input_t {
1197#if MAX_HISTORY 1197#if MAX_HISTORY
1198 int cnt_history; 1198 int cnt_history;
1199 int cur_history; 1199 int cur_history;
1200 USE_FEATURE_EDITING_SAVEHISTORY(const char *hist_file;) 1200#if ENABLE_FEATURE_EDITING_SAVEHISTORY
1201 unsigned cnt_history_in_file;
1202 off_t last_history_end;
1203 const char *hist_file;
1204#endif
1201 char *history[MAX_HISTORY + 1]; 1205 char *history[MAX_HISTORY + 1];
1202#endif 1206#endif
1203} line_input_t; 1207} line_input_t;