mirror of
				https://github.com/tmux-plugins/tmux-continuum.git
				synced 2025-11-04 00:07:32 +00:00 
			
		
		
		
	Fix race condition in saving lock
Two consecutive calls to "date +%s" can return different values. Call "date" only once and reuse the result.
This commit is contained in:
		@@ -37,10 +37,11 @@ fetch_and_run_tmux_resurrect_save_script() {
 | 
				
			|||||||
main() {
 | 
					main() {
 | 
				
			||||||
	# Sometimes tmux starts multiple saves in parallel. We want only one
 | 
						# Sometimes tmux starts multiple saves in parallel. We want only one
 | 
				
			||||||
	# save to be running, otherwise we can get corrupted saved state.
 | 
						# save to be running, otherwise we can get corrupted saved state.
 | 
				
			||||||
	# The following implements a lock that auto-expires after 100...200s.
 | 
					 | 
				
			||||||
	local lockdir_prefix="/tmp/tmux-continuum-$(current_tmux_server_pid)-lock-"
 | 
						local lockdir_prefix="/tmp/tmux-continuum-$(current_tmux_server_pid)-lock-"
 | 
				
			||||||
	local lockdir1="${lockdir_prefix}$[ `date +%s` / 100 ]"
 | 
						# The following implements a lock that auto-expires after 100...200s.
 | 
				
			||||||
	local lockdir2="${lockdir_prefix}$[ `date +%s` / 100 + 1]"
 | 
						local lock_generation=$[ `date +%s` / 100 ]
 | 
				
			||||||
 | 
						local lockdir1="${lockdir_prefix}${lock_generation}"
 | 
				
			||||||
 | 
						local lockdir2="${lockdir_prefix}$[ $lock_generation + 1 ]"
 | 
				
			||||||
	if mkdir "$lockdir1"; then
 | 
						if mkdir "$lockdir1"; then
 | 
				
			||||||
		trap "rmdir "$lockdir1"" EXIT
 | 
							trap "rmdir "$lockdir1"" EXIT
 | 
				
			||||||
		if mkdir "$lockdir2"; then
 | 
							if mkdir "$lockdir2"; then
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user