Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fallback to a read lock on fork preparation.
The reason to acquire a write lock is that there is a corner case where the forking application is going to actually create additional threads in an atfork() handler that runs before ours instead of doing something more sensible like an immediate exec(). If such an application were to create threads then there is a chance one of those threads could cause a call into pkcs11-provider that would end up acquiring a read lock, which we will destroy as part of the post fork atfork() handler. Note that pthread creation or even pthread lock initialization functions are not considered async-sginal-safe fucntions, so this is all a shot in the dark anyway ... Given this premise, falling back to a read lock, which will prevent modification of the slots is sufficient in most cases. Although there is a slight chance again that resetting the locks can cause a thread to obtain a write lock while another thread holds a now defunct read lock, such that there is modification of the slots while a separate thread is reading this information, this is so rare it is not worth dealing with (and there is nothing we can do anyway). At least two threads won't be writing at the same time, that could be really problematic. Use of atfork() is also so rare that the chance of this happening in any reasonable application can be considered infinitesimally small. Signed-off-by: Simo Sorce <simo@redhat.com>
- Loading branch information