Commit Graph

7 Commits

Author SHA1 Message Date
v9v
ff63f86678
continuum_save.sh: Improvements to locking code
* moved the locking to a separate function "acquire_lock"
* changed $[ ] to $(( )), for consistency with the rest of the file
* taking the lock only after checking all other preconditions (they are non-mutating and thread-safe)
2019-07-13 14:16:42 +02:00
v9v
3917404668
Fix race condition in saving lock
Two consecutive calls to "date +%s" can return different values. Call "date" only once and reuse the result.
2019-07-09 10:46:56 +02:00
v9v
800488ca6f
Replace flock with mkdir
flock is not supported on MacOS.

`mkdir` locks have a drawback: they are not cleaned up automatically. If the lock owner crashed before cleaning up the lock, the directory will stay in the filesystem and the lock will be never acquired by someone else. To avoid that, we create temporary locks (the lockdir name changes every 100 seconds). We grab two lock (N and N+1) to avoid the case where process A grabs lock N and process B grabs lock N+1 and both enter the critical section.
2019-07-08 15:58:42 +02:00
v9v
10e612d72c
Handle missing flock
If flock is not installed, fall back to the thread-unsafe version.
2019-07-05 19:33:12 +02:00
v9v
721890d22f Fix race condition in autosave
Fixes the case where multiple tmux sessions call auto-save at the same time, which occasionally results in multiple instances of save_all() running in parallel and causing issues like #3 and tmux-plugins/tmux-resurrect#294.

The sequence in main() is:
1. Check enough_time_since_last_run_passed
2. Save
3. Update last_save_timestamp.

The race here is:
* process A finishes step 1 and is busy with step 2. The timestamp is not updated yet.
* process B comes to step 1, sees the old timestamp and proceeds to step 2, too.
2019-07-04 20:21:02 +02:00
Bruno Sutic
bdc47273d3
Properly quote scripts 2015-02-20 15:48:36 +01:00
Bruno Sutic
20a83738c0
Rename the plugin to 'tmux-continuum' 2015-02-20 13:38:09 +01:00