Fix: libc internal mutex races with run_as
[lttng-tools.git] / src / bin / lttng-consumerd / lttng-consumerd.c
index 626fbb73a1fe960b1cdfc03fc44789c46442e8e6..7ecbe7a3439a9f148719289a703da8014968357a 100644 (file)
@@ -109,7 +109,9 @@ static void sighandler(int sig)
                return;
        }
 
-       lttng_consumer_should_exit(ctx);
+       if (ctx) {
+               lttng_consumer_should_exit(ctx);
+       }
 }
 
 /*
@@ -312,6 +314,7 @@ int main(int argc, char **argv)
 {
        int ret = 0, retval = 0;
        void *status;
+       struct lttng_consumer_local_data *tmp_ctx;
 
        if (set_signal_handler()) {
                retval = -1;
@@ -419,6 +422,10 @@ int main(int argc, char **argv)
                set_ulimit();
        }
 
+       if (run_as_create_worker(argv[0]) < 0) {
+               goto exit_init_data;
+       }
+
        /* create the consumer instance with and assign the callbacks */
        ctx = lttng_consumer_create(opt_type, lttng_consumer_read_subbuffer,
                NULL, lttng_consumer_on_recv_stream, NULL);
@@ -626,7 +633,10 @@ exit_health_thread:
 exit_health_pipe:
 
 exit_init_data:
-       lttng_consumer_destroy(ctx);
+       tmp_ctx = ctx;
+       ctx = NULL;
+       cmm_barrier();  /* Clear ctx for signal handler. */
+       lttng_consumer_destroy(tmp_ctx);
        lttng_consumer_cleanup();
 
        if (health_consumerd) {
@@ -637,6 +647,9 @@ exit_health_consumerd_cleanup:
 exit_options:
 
 exit_set_signal_handler:
+       /* Ensure all prior call_rcu are done. */
+       rcu_barrier();
+
        if (!retval) {
                exit(EXIT_SUCCESS);
        } else {
This page took 0.023239 seconds and 4 git commands to generate.