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.
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.
- this caused issues with the restore missing some processes and putting
others in the wrong place.
- I think this may need some work with the tmux-resurrect plugin to fix if auto
restore is to be used.
Do not count `tmux source-file .tmux.conf` as a tmux process when checking if
other tmux server is running.
Previously, this caused interpolation command not to be inserted into
`status-right` because `tmux source-file` was falsely detected as another tmux
server.