- Link application with -lust.
- (TODO: start tracing with the "lttng" command from lttng-tools)
- Note: libust debug can be activated by either of the following means:
- - Setting the environment variable "UST_DEBUG" when launching the
- application.
- - Compiling libust with -DUST_DEBUG.
+ENVIRONMENT VARIABLES:
+
+ - libust debug can be activated by setting the environment variable
+ "UST_DEBUG" when launching the application. It can also be enabled
+ at compile-time by compiling libust with -DUST_DEBUG.
+
+ - The environment variable "UST_REGISTER_TIMEOUT" can be used to
+ specify how long the applications should wait for sessiond
+ "registration done" command before proceeding to execute the main
+ program. The default is 3000ms (3 seconds). The timeout value is
+ specified in milliseconds. The value -1 means "don't wait". The value
+ 0 means "wait forever".
TRACE VIEWER:
#include <ust/lttng-ust-abi.h>
/*
- * TODO: allow override of constructor timeout with an environment
- * variable.
+ * Default timeout the application waits for the sessiond to send its
+ * "register done" command. Can be overridden with the environment
+ * variable "UST_REGISTER_TIMEOUT". Note that if the sessiond is not
+ * found, the application proceeds directly without any delay.
*/
-#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_S 3
-#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_NS 0
+#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000
#define LTTNG_RUNDIR "/var/run/lttng"
return NULL;
}
+/*
+ * Return values: -1: don't wait. 0: wait forever. 1: timeout wait.
+ */
static
int get_timeout(struct timespec *constructor_timeout)
{
- struct timespec constructor_delay =
- {
- .tv_sec = LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_S,
- .tv_nsec = LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_NS,
- };
- struct timespec realtime;
+ long constructor_delay_ms = LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS;
+ char *str_delay;
int ret;
- ret = clock_gettime(CLOCK_REALTIME, &realtime);
- if (ret)
- return ret;
+ str_delay = getenv("UST_REGISTER_TIMEOUT");
+ if (str_delay) {
+ constructor_delay_ms = strtol(str_delay, NULL, 10);
+ }
+
+ switch (constructor_delay_ms) {
+ case -1:/* fall-through */
+ case 0:
+ return constructor_delay_ms;
+ default:
+ break;
+ }
+
+ /*
+ * If we are unable to find the current time, don't wait.
+ */
+ ret = clock_gettime(CLOCK_REALTIME, constructor_timeout);
+ if (ret) {
+ return -1;
+ }
- constructor_timeout->tv_sec =
- realtime.tv_sec + constructor_delay.tv_sec;
constructor_timeout->tv_nsec =
- constructor_delay.tv_nsec + realtime.tv_nsec;
+ constructor_timeout->tv_nsec + (constructor_delay_ms * 1000000UL);
if (constructor_timeout->tv_nsec >= 1000000000UL) {
constructor_timeout->tv_sec++;
constructor_timeout->tv_nsec -= 1000000000UL;
}
- return 0;
+ return 1;
}
/*
void __attribute__((constructor)) lttng_ust_comm_init(void)
{
struct timespec constructor_timeout;
+ int timeout_mode;
int ret;
init_usterr();
- ret = get_timeout(&constructor_timeout);
- assert(!ret);
+ timeout_mode = get_timeout(&constructor_timeout);
ret = sem_init(&constructor_wait, 0, 2);
assert(!ret);
ret = pthread_create(&local_apps.ust_listener, NULL,
ust_listener_thread, &local_apps);
- ret = sem_timedwait(&constructor_wait, &constructor_timeout);
- if (ret < 0 && errno == ETIMEDOUT) {
- ERR("Timed out waiting for ltt-sessiond");
- } else {
+ switch (timeout_mode) {
+ case 1: /* timeout wait */
+ ret = sem_timedwait(&constructor_wait, &constructor_timeout);
+ if (ret < 0 && errno == ETIMEDOUT) {
+ ERR("Timed out waiting for ltt-sessiond");
+ } else {
+ assert(!ret);
+ }
+ break;
+ case 0: /* wait forever */
+ ret = sem_wait(&constructor_wait);
assert(!ret);
+ break;
+ case -1:/* no timeout */
+ break;
}
pthread_mutex_unlock(<tng_ust_comm_mutex);
-
}
void __attribute__((destructor)) lttng_ust_comm_exit(void)