From: Mathieu Desnoyers Date: Tue, 23 Aug 2011 23:53:12 +0000 (-0400) Subject: Add env var UST_REGISTER_TIMEOUT X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=cf12a773f3885500c37e26cf80e8ac05e1309572;p=ust.git Add env var UST_REGISTER_TIMEOUT Signed-off-by: Mathieu Desnoyers --- diff --git a/README b/README index 3d7e18e..399263d 100644 --- a/README +++ b/README @@ -45,10 +45,18 @@ USAGE: - 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: diff --git a/include/lttng-ust-comm.h b/include/lttng-ust-comm.h index 0ae99ab..e896f1a 100644 --- a/include/lttng-ust-comm.h +++ b/include/lttng-ust-comm.h @@ -31,11 +31,12 @@ #include /* - * 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" diff --git a/libust/lttng-ust-comm.c b/libust/lttng-ust-comm.c index a9f5797..8f0cb85 100644 --- a/libust/lttng-ust-comm.c +++ b/libust/lttng-ust-comm.c @@ -339,30 +339,44 @@ quit: 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; } /* @@ -374,12 +388,12 @@ int get_timeout(struct timespec *constructor_timeout) 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); @@ -401,14 +415,23 @@ void __attribute__((constructor)) lttng_ust_comm_init(void) 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)