Fix: resolve full path of LTTNG_UST_CLOCK_PLUGIN
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index a2afb8f757626b71f24655d7b682ac38c483a019..9f0bcdc41e8ad0788f5ac841ddabd12de8363d2f 100644 (file)
@@ -564,8 +564,7 @@ static void wait_consumer(struct consumer_data *consumer_data)
        ret = waitpid(consumer_data->pid, &status, 0);
        if (ret == -1) {
                PERROR("consumerd waitpid pid: %d", consumer_data->pid)
-       }
-       if (!WIFEXITED(status)) {
+       } else  if (!WIFEXITED(status)) {
                ERR("consumerd termination with error: %d",
                                WEXITSTATUS(ret));
        }
@@ -1855,6 +1854,8 @@ static void *thread_dispatch_ust_registration(void *data)
                .count = 0,
        };
 
+       rcu_register_thread();
+
        health_register(health_sessiond, HEALTH_SESSIOND_TYPE_APP_REG_DISPATCH);
 
        if (testpoint(sessiond_thread_app_reg_dispatch)) {
@@ -1867,12 +1868,16 @@ static void *thread_dispatch_ust_registration(void *data)
 
        DBG("[thread] Dispatch UST command started");
 
-       while (!CMM_LOAD_SHARED(dispatch_thread_exit)) {
+       for (;;) {
                health_code_update();
 
                /* Atomically prepare the queue futex */
                futex_nto1_prepare(&ust_cmd_queue.futex);
 
+               if (CMM_LOAD_SHARED(dispatch_thread_exit)) {
+                       break;
+               }
+
                do {
                        struct ust_app *app = NULL;
                        ust_cmd = NULL;
@@ -2088,6 +2093,7 @@ error_testpoint:
                ERR("Health error occurred in %s", __func__);
        }
        health_unregister(health_sessiond);
+       rcu_unregister_thread();
        return NULL;
 }
 
@@ -2520,7 +2526,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                        } else {
                                DBG("Could not find any valid consumerd executable");
                                ret = -EINVAL;
-                               break;
+                               goto error;
                        }
                        DBG("Using kernel consumer at: %s",  consumer_to_use);
                        ret = execl(consumer_to_use,
@@ -2710,7 +2716,6 @@ static int init_kernel_tracer(void)
        kernel_tracer_fd = open(module_proc_lttng, O_RDWR);
        if (kernel_tracer_fd < 0) {
                DBG("Failed to open %s", module_proc_lttng);
-               ret = -1;
                goto error_open;
        }
 
@@ -3058,7 +3063,6 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
        case LTTNG_CREATE_SESSION:
        case LTTNG_CREATE_SESSION_SNAPSHOT:
        case LTTNG_CREATE_SESSION_LIVE:
-       case LTTNG_CALIBRATE:
        case LTTNG_LIST_SESSIONS:
        case LTTNG_LIST_TRACEPOINTS:
        case LTTNG_LIST_SYSCALLS:
@@ -3900,12 +3904,6 @@ error_add_context:
                ret = LTTNG_OK;
                break;
        }
-       case LTTNG_CALIBRATE:
-       {
-               ret = cmd_calibrate(cmd_ctx->lsm->domain.type,
-                               &cmd_ctx->lsm->u.calibrate);
-               break;
-       }
        case LTTNG_REGISTER_CONSUMER:
        {
                struct consumer_data *cdata;
@@ -4332,7 +4330,7 @@ error:
        }
 
        lttng_poll_clean(&events);
-
+       stop_threads();
        rcu_unregister_thread();
        return NULL;
 }
@@ -5527,6 +5525,44 @@ error:
        return ret;
 }
 
+static int set_clock_plugin_env(void)
+{
+       int ret = 0;
+       const char *original_env_value;
+       char *full_path = NULL;
+       char *new_env_value = NULL;
+
+       original_env_value = getenv("LTTNG_UST_CLOCK_PLUGIN");
+       if (!original_env_value) {
+               goto end;
+       }
+
+       full_path = utils_expand_path(original_env_value);
+       if (!full_path) {
+               ERR("Failed to expand LTTNG_UST_CLOCK_PLUGIN path \"%s\"",
+                               original_env_value);
+               ret = -1;
+               goto end;
+       }
+        ret = asprintf(&new_env_value, "LTTNG_UST_CLOCK_PLUGIN=%s",
+                       full_path);
+       free(full_path);
+       if (ret < 0) {
+               PERROR("asprintf");
+               goto end;
+       }
+
+       DBG("Updating environment: %s", new_env_value);
+       ret = putenv(new_env_value);
+       if (ret) {
+               free(new_env_value);
+               PERROR("putenv of LTTNG_UST_CLOCK_PLUGIN");
+               goto end;
+       }
+end:
+       return ret;
+}
+
 /*
  * main
  */
@@ -5568,6 +5604,12 @@ int main(int argc, char **argv)
                goto exit_options;
        }
 
+       ret = set_clock_plugin_env();
+       if (ret) {
+               retval = -1;
+               goto exit_options;
+       }
+
        /* Daemonize */
        if (opt_daemon || opt_background) {
                int i;
@@ -6154,6 +6196,12 @@ exit_client:
 exit_health:
 
 exit_init_data:
+       /*
+        * Wait for all pending call_rcu work to complete before tearing
+        * down data structures. call_rcu worker may be trying to
+        * perform lookups in those structures.
+        */
+       rcu_barrier();
        /*
         * sessiond_cleanup() is called when no other thread is running, except
         * the ht_cleanup thread, which is needed to destroy the hash tables.
This page took 0.026381 seconds and 4 git commands to generate.