libsemanage: block on store lock by default
Stephen Smalley
maintainerPATCH v2 1/1 libsemanage: block on store lock by default
semanage_get_lock() polls the store lock once per second and gives up after sh->timeout seconds, which is hard-coded to 5 with no configuration setting to control it. A single semodule transaction on a real policy routinely takes more than 5 seconds, so any overlap makes the second caller fail. This requires rpm scriptlets, ansible, or other scripted usage of semodule fragile.
Change the default timeout to -1 (wait indefinitely) and in that case use a blocking flock() instead of polling. Try a non-blocking flock() first for the common case where the lock is not held and if it is held, inform the user so they know why it may be taking longer than normal. Retain the timeout logic in case we decide to re-introduce other configurable settings in the future.
Several other minor cleanups are included as well, e.g. there is no need to pass O_TRUNC for the lock file, and there is no need to set O_CLOEXEC a second time via fcntl() since open() already passed it.
---
v2 adds errno checking for the first flock() call so that we do not ignore errors other than EAGAIN/EWOULDBLOCK.
libsemanage/src/handle.c | 2 +- libsemanage/src/semanage_store.c | 81 +++++++++++++++----------------- 2 files changed, 39 insertions(+), 44 deletions(-)
libsemanage/src/handle.c +1 -1
@@ -37,7 +37,7 @@#include "semanage_conf.h" #include "semanage_store.h" -#define SEMANAGE_COMMIT_READ_WAIT 5 +#define SEMANAGE_COMMIT_READ_WAIT -1static char *private_semanage_root =NULL ;
libsemanage/src/semanage_store.c +38 -43
105 lines not on this page · raw message
Signature · 1 line
2.55.0