+static
+int setup_ust_apps(void)
+{
+ const char *ust_app_path;
+ int ret = 0;
+ uid_t uid;
+
+ assert(!ust_app.wait_shm_mmap);
+
+ uid = getuid();
+ /*
+ * Disallow ust apps tracing for setuid binaries, because we
+ * cannot use the environment variables anyway.
+ */
+ if (uid != geteuid()) {
+ DBG("UST app tracing disabled for setuid binary.");
+ assert(ust_app.allowed == 0);
+ ret = 0;
+ goto end;
+ }
+ ust_app_path = get_lttng_ust_app_path();
+ if (!ust_app_path) {
+ DBG("LTTNG_UST_APP_PATH environment variable not set.");
+ assert(ust_app.allowed == 0);
+ ret = -ENOENT;
+ goto end;
+ }
+ /*
+ * The LTTNG_UST_APP_PATH env. var. disables global and local
+ * sessiond connections.
+ */
+ ust_app.allowed = 1;
+ snprintf(ust_app.sock_path, PATH_MAX, "%s/%s",
+ ust_app_path, LTTNG_UST_SOCK_FILENAME);
+ snprintf(ust_app.wait_shm_path, PATH_MAX, "%s/%s",
+ ust_app_path,
+ LTTNG_UST_WAIT_FILENAME);
+
+ ust_app.wait_shm_mmap = get_map_shm(&ust_app);
+ if (!ust_app.wait_shm_mmap) {
+ WARN("Unable to get map shm for ust_app. Disabling LTTng-UST ust_app tracing.");
+ ust_app.allowed = 0;
+ ret = -EIO;
+ goto end;
+ }
+
+ lttng_pthread_getname_np(ust_app.procname, LTTNG_UST_CONTEXT_PROCNAME_LEN);
+end:
+ return ret;
+}
+