Add env var UST_REGISTER_TIMEOUT
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 23 Aug 2011 23:53:12 +0000 (19:53 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 23 Aug 2011 23:53:12 +0000 (19:53 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
README
include/lttng-ust-comm.h
libust/lttng-ust-comm.c

diff --git a/README b/README
index 3d7e18e3de27f59a124de7ecbf0a9d4f64f5ec9c..399263d5e1e8faf8807f84e1b98c33acb36e0fe4 100644 (file)
--- 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:
index 0ae99ab4d01c214025ab16943f959caee1f7104f..e896f1a1015f3e52f042c0f8df1b8e3724715d5e 100644 (file)
 #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"
 
index a9f5797df671cc8af4ff5e2f01f4408ab0143360..8f0cb85b95d2074c1ff2c362e69ce3de1eb7e994 100644 (file)
@@ -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(&lttng_ust_comm_mutex);
-
 }
 
 void __attribute__((destructor)) lttng_ust_comm_exit(void)
This page took 0.027829 seconds and 4 git commands to generate.