When an instance is instructed to stop, a semaphore is increased to
signal this condition. The inst_running() function uses sem_trywait()
on this semaphore, returning false if the semaphore could be passed,
thus telling the caller that the instance should be stopped.
However, since sem_trywait() decreases the semaphore, subsequent calls
to inst_running() will return true again.
This commit changes inst_running() to increase the semaphore in case
it was decreased by sem_trywait(). However, there remains a small
window of opportunity where the function may return different values
to different callers if multiple processes from the same instance call
the function at the same time.
return 0
fi
+ # The next invocation of inst_running() will return true if we don't
+ # increase the semaphore here, since sem_trywait() decreased it.
+ if ! sem_post "$__inst_sem"; then
+ log_warn "Could not post semaphore $__inst_sem"
+ fi
+
return 1
}