lib/atexit: fix occasional failure to unmount with CTRL-C #4957

Before this change CTRL-C could come in to exit rclone which would
start the atexit actions running. The Fuse unmount then signals rclone
to exit which wasn't waiting for the already running atexit actions to
complete.

This change makes sure that if the atexit actions are started they
should be completed.
This commit is contained in:
Nick Craig-Wood 2021-01-25 17:03:57 +00:00
parent e3e08a48cb
commit 8d847a4e94
1 changed files with 3 additions and 2 deletions

View File

@ -77,9 +77,10 @@ func IgnoreSignals() {
// Run all the at exit functions if they haven't been run already
func Run() {
// Take the lock here so we wait until all have run before returning
fnsMutex.Lock()
defer fnsMutex.Unlock()
exitOnce.Do(func() {
fnsMutex.Lock()
defer fnsMutex.Unlock()
for fnHandle := range fns {
(*fnHandle)()
}