[lttng-dev] [RFC PATCH LTTNG-UST] Fix: Decrement sem_count when disabling local apps
Jérémie Galarneau
jeremie.galarneau at efficios.com
Tue Jul 7 12:48:02 EDT 2015
LTTng-UST will deadlock waiting on the "constructor_wait" semaphore
if local apps, handled the session daemon running under the current UID,
are disabled or "not_allowed".
This deadlock can be triggered by setting an infinite registration
timeout and clearing the HOME environment variable, which will cause
setup_local_apps() to fail to determine the local_apps sock_path, thus
leaving local_apps.allowed == 0.
Given that local_apps are not allowed at this point, the local_apps
listener thread will not be launched. Therefore, the constructor_wait
will not be waited on.
The fix proposed here consists in decrementing "sem_count" if an error
precluding the launch the the local_apps listener thread occurs.
Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
---
liblttng-ust/lttng-ust-comm.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c
index b290204..c91627f 100644
--- a/liblttng-ust/lttng-ust-comm.c
+++ b/liblttng-ust/lttng-ust-comm.c
@@ -373,6 +373,7 @@ void print_cmd(int cmd, int handle)
static
int setup_local_apps(void)
{
+ int ret = 0;
const char *home_dir;
uid_t uid;
@@ -382,13 +383,16 @@ int setup_local_apps(void)
*/
if (uid != geteuid()) {
assert(local_apps.allowed == 0);
- return 0;
+ goto end;
}
home_dir = get_lttng_home_dir();
if (!home_dir) {
WARN("HOME environment variable not set. Disabling LTTng-UST per-user tracing.");
assert(local_apps.allowed == 0);
- return -ENOENT;
+ ret = -ENOENT;
+ goto end;
+ } else {
+ DBG("home_dir: %s", home_dir);
}
local_apps.allowed = 1;
snprintf(local_apps.sock_path, PATH_MAX, "%s/%s/%s",
@@ -398,7 +402,15 @@ int setup_local_apps(void)
snprintf(local_apps.wait_shm_path, PATH_MAX, "/%s-%u",
LTTNG_UST_WAIT_FILENAME,
uid);
- return 0;
+end:
+ if (!local_apps.allowed) {
+ /*
+ * Don't wait on the "local" listener thread since we won't be
+ * communicating with the local session daemon.
+ */
+ uatomic_add(&sem_count, -1);
+ }
+ return ret;
}
/*
--
2.4.4
More information about the lttng-dev
mailing list