libbb: make history saving/loading concurrent-safe
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 22 Mar 2009 19:00:05 +0000 (19:00 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 22 Mar 2009 19:00:05 +0000 (19:00 -0000)
commit57abf9e947fa3f7d69f7adb97023b299916ee63c
treebcc36a5d96b56859763bd52a52377ed1c081326a
parent3fd104630020168ead90123e45d848d4d2d0a555
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
include/libbb.h
libbb/lineedit.c