[PATCH] ash: add support for history buffer
Dennis Groenen
tj.groenen at gmail.com
Wed Jul 27 13:59:21 UTC 2011
On 07/23/2011 05:50 PM, Denys Vlasenko wrote:
> On Wednesday 13 July 2011 15:43, Dennis Groenen wrote:
>> On 07/13/2011 03:13 PM, Laurent Bercot wrote:
>>> Specialized filesystems such as jffs2 or yaffs2 still can, however.
>> Good point, but a lot of, for example closed, embedded/mobile devices
>> require a lot of hacking around to get something custom (like a
>> different fs) running.
>>> Why shouldn't it be? Either you want to reduce the number of writes
>>> to the filesystem, or you don't. Delayed writing, which is configured
>>> at the filesystem layer, accomplishes this for every application without
>>> the need for patching. Applications can always fsync() when they need
>>> synchronous writes.
>> True, but generally those writes from other applications are going to
>> happen anyway. E.g. if I save a file in application X, it will need to
>> be written out, and be written out completely. For BusyBox's history,
>> this isn't the case. I don't see why a file has to be written out after
>> each appended line here. Vi doesn't write out a file after each new line
>> either, does it?
> sh can crash.
> sh can be killed by a signal.
> sh can be run in parallel from two terminals, and saving at exit creates
> unfairness: whoever exits last overwrites the history of other guys.
>
The issues you've described are very valid, and are somewhat inevitable
when using volatile memory as a buffer. One needs to take these issues
into account when deciding whether to use a history buffer or not.
> Nevertheless, I am not firmly against saving only on exit.
> Actually, I think that's the option you'd like.
> So, (1) it would largely solve your problem
> and (2) it would also be welcomed by people who like
> more bash-like behavior wrt history saving.
>
> Can you code up a patch which does this?
>
I don't think I'm skilled enough to create a 'true' in-memory buffer to
temporarily store the history, i.e. one that doesn't use a regular file
in e.g. /tmp as the buffer. I'm assuming here that you didn't like the
way how I implemented saving history on exit in my original patch.
On a side note, using a regular file in /tmp does solve all the issues
you've posed before. If sh gets killed or crashes, the regular file
persists and will be written out upon the next (clean) shell exit.
You'll only lose (some) history if /tmp gets cleared during a shell
session. Also, as libbb/lineedit.c isn't touched, BusyBox' original code
for dealing with parallel terminals is preserved, thus this sort of
buffer isn't less unfair than vanilla BusyBox.
--Dennis
P.s. I've attached a revised version of my original patch for those
interested in it. It has better error handling and is more secure. Do
note that it still uses a regular file in /tmp as the history buffer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ash-add-support-for-history-buffer.patch
Type: text/x-patch
Size: 4196 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20110727/7f3f58ea/attachment.bin>
More information about the busybox
mailing list