gitk: Synchronize config file writes
commiteaf7e835e61de98488592e02b31da9f44fd4505d
authorMax Kirillov <max@max630.net>
Wed, 4 Mar 2015 03:58:18 +0000 (4 05:58 +0200)
committerPaul Mackerras <paulus@samba.org>
Sun, 15 Mar 2015 03:14:22 +0000 (15 14:14 +1100)
treead5ac2e5ed7164a5f83eb5a214eb72a46fe25ada
parent1dd29606b69279605f42b715e491aaf8cd0fea60
gitk: Synchronize config file writes

If several gitk instances are closed simultaneously, the savestuff
procedure can run at the same time, resulting in a conflict which may
cause losing of some of the instance's changes, failing the saving
operation or even corrupting the configuration file. This can happen,
for example, at user session closing, or at group closing of all
instances of an application which is possible in some desktop
environments.

To avoid this, make sure that only one saving operation is in
progress.  It is guarded by existence of the $config_file_tmp
file. Creating the file and moving it to $config_file are both atomic
operations, so it should be reliable.

Reading does not need to be syncronized, because moving is an atomic
operation, and the $config_file always refers to a full and correct file.
But, if there is a stale $config_file_tmp file, report it at gitk start.
If such file is detected when saving, just report it abort the save, as
for other errors in saving.

Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Paul Mackerras <paulus@samba.org>
gitk