Skip to contentSkip to conversation

libsemanage: block on store lock by default

PATCH Superseded Stephen Smalley 1 participant 1 message Jul 22 SELinux security module

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 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
index 77d0ed8a..1ff86e60 100644
@@ -37,7 +37,7 @@
 #include "semanage_conf.h"
 #include "semanage_store.h"
 
-#define SEMANAGE_COMMIT_READ_WAIT 5
+#define SEMANAGE_COMMIT_READ_WAIT -1
 
 static 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