Geoff Kuenning wrote:
> But right now, if all three of those shells exit simultaneously--for > whatever reason--there is a significant probability that the history > file will end up zero-length. That's not theoretical; I've experienced > it multiple times. And that's a bug, plain and simple. And I suspect > that it can be fixed on 99+% of all deployed systems by just adding > O_EXCL to the open. ---- > > This would be where I am glaringly guilty of bad writing, because if I > had written clearly you wouldn't have said that. I am most definitely > NOT asking for "no overwrite" behavior. I'm just asking for "no > simultaneous opens for write"--i.e., O_EXCL. ---- A zero length file!?? How might it do that. Presumably, you are writing your histories in append mode, and from the bash man page: If the histappend shell option is enabled (see the description of shopt under SHELL BUILTIN COMMANDS below), the lines are appended to the history file, otherwise the history file is over‐ written. --- If you have histappend set and are still ending up with a zero length file, I'd say there's a definitely bug there somewhere. It may not be in bash, but you might try some testing and seeing what happens if you set the file attribute "append-only" on the file (need to be root to set it) but that might quickly point at the culprit, as append-only on a file won't let you open for writing, except in append mode (you can still read it though): > sudo chattr +a log > echo "ttt" >log -bash: log: Operation not permitted > echo "ttt" >>log > cat log ttt Because of the root-requirement, it's not a solution for this problem. Bash opening the file in O_APPEND *should* be sufficient. If not, I'd be more inclined to think it a fault in libc...though bash might be specifying buffering, perhaps, when maybe it shouldn't?