Introduce build/env/argument override for 32-bit compat consumer
[lttng-tools.git] / lttng-sessiond / main.c
index d1cc3fa8f81a3aec484e6ca476720ff9a3e7fa48..d0c1d406863c471cadfb948f43380c9acc62128b 100644 (file)
@@ -159,6 +159,24 @@ static struct ltt_session_list *session_list_ptr;
 
 int ust_consumer_fd;
 
+static const char *compat32_consumer_bindir =
+       __stringify(CONFIG_COMPAT_BIN_DIR);
+static const char *compat32_consumer_prog = "lttng-consumerd";
+
+static
+void setup_compat32_consumer(void)
+{
+       const char *bindir;
+
+       /*
+        * runtime env. var. overrides the build default.
+        */
+       bindir = getenv("LTTNG_TOOLS_COMPAT_BIN_DIR");
+       if (bindir) {
+               compat32_consumer_bindir = bindir;
+       }
+}
+
 /*
  * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
  */
@@ -305,8 +323,14 @@ static void teardown_kernel_session(struct ltt_session *session)
  */
 static void teardown_ust_session(struct ltt_session *session)
 {
+       int ret;
+
        DBG("Tearing down UST session(s)");
 
+       ret = ust_app_destroy_trace_all(session->ust_session);
+       if (ret) {
+               ERR("Error in ust_app_destroy_trace_all");
+       }
        trace_ust_destroy_session(session->ust_session);
 }
 
@@ -1054,9 +1078,10 @@ static void *thread_manage_apps(void *data)
                                        /* Register applicaton to the session daemon */
                                        ret = ust_app_register(&ust_cmd.reg_msg,
                                                        ust_cmd.sock);
-                                       if (ret < 0) {
-                                               /* Only critical ENOMEM error can be returned here */
+                                       if (ret == -ENOMEM) {
                                                goto error;
+                                       } else if (ret < 0) {
+                                               break;
                                        }
 
                                        /*
@@ -1790,6 +1815,7 @@ static void list_lttng_sessions(struct lttng_session *sessions)
                sessions[i].path[PATH_MAX - 1] = '\0';
                strncpy(sessions[i].name, session->name, NAME_MAX);
                sessions[i].name[NAME_MAX - 1] = '\0';
+               sessions[i].enabled = session->enabled;
                i++;
        }
 }
@@ -2512,6 +2538,10 @@ static int cmd_start_trace(struct ltt_session *session)
        ksession = session->kernel_session;
        usess = session->ust_session;
 
+       if (session->enabled)
+               return LTTCOMM_UST_START_FAIL;
+       session->enabled = 1;
+
        /* Kernel tracing */
        if (ksession != NULL) {
                struct ltt_kernel_channel *kchan;
@@ -2591,11 +2621,15 @@ static int cmd_stop_trace(struct ltt_session *session)
        int ret;
        struct ltt_kernel_channel *kchan;
        struct ltt_kernel_session *ksession;
-       //struct ltt_ust_session *usess;
-       //struct ltt_ust_channel *ustchan;
+       struct ltt_ust_session *usess;
 
        /* Short cut */
        ksession = session->kernel_session;
+       usess = session->ust_session;
+
+       if (!session->enabled)
+               return LTTCOMM_UST_START_FAIL;
+       session->enabled = 0;
 
        /* Kernel tracer */
        if (ksession != NULL) {
@@ -2623,32 +2657,16 @@ static int cmd_stop_trace(struct ltt_session *session)
                kernel_wait_quiescent(kernel_tracer_fd);
        }
 
-#ifdef DISABLE
-       /* Stop each UST session */
-       DBG("Stop UST tracing");
-       cds_list_for_each_entry(usess, &session->ust_session_list.head, list) {
-               /* Flush all buffers before stopping */
-               ret = ustctl_flush_buffer(usess->sock, usess->metadata->obj);
-               if (ret < 0) {
-                       ERR("UST metadata flush failed");
-               }
-
-               cds_list_for_each_entry(ustchan, &usess->channels.head, list) {
-                       ret = ustctl_flush_buffer(usess->sock, ustchan->obj);
-                       if (ret < 0) {
-                               ERR("UST flush buffer error");
-                       }
-               }
+       /* Flag session that trace should start automatically */
+       if (usess) {
+               usess->start_trace = 0;
 
-               ret = ustctl_stop_session(usess->sock, usess->handle);
+               ret = ust_app_stop_trace_all(usess);
                if (ret < 0) {
-                       ret = LTTCOMM_KERN_STOP_FAIL;
+                       ret = LTTCOMM_UST_START_FAIL;
                        goto error;
                }
-
-               ustctl_wait_quiescent(usess->sock);
        }
-#endif
 
        ret = LTTCOMM_OK;
 
@@ -2683,6 +2701,8 @@ static int cmd_destroy_session(struct ltt_session *session, char *name)
 
        /* Clean kernel session teardown */
        teardown_kernel_session(session);
+       /* UST session teardown */
+       teardown_ust_session(session);
 
        /*
         * Must notify the kernel thread here to update it's poll setin order
@@ -2821,14 +2841,14 @@ static ssize_t cmd_list_channels(int domain, struct ltt_session *session,
                if (session->kernel_session != NULL) {
                        nb_chan = session->kernel_session->channel_count;
                }
-               DBG3("Number of kernel channels %ld", nb_chan);
+               DBG3("Number of kernel channels %zd", nb_chan);
                break;
        case LTTNG_DOMAIN_UST:
                if (session->ust_session != NULL) {
                        nb_chan = hashtable_get_count(
                                        session->ust_session->domain_global.channels);
                }
-               DBG3("Number of UST global channels %ld", nb_chan);
+               DBG3("Number of UST global channels %zd", nb_chan);
                break;
        default:
                *channels = NULL;
@@ -3439,6 +3459,7 @@ static void usage(void)
        fprintf(stderr, "      --kconsumerd-cmd-sock PATH     Specify path for the kernel consumer command socket\n");
        fprintf(stderr, "      --ustconsumerd-err-sock PATH   Specify path for the UST consumer error socket\n");
        fprintf(stderr, "      --ustconsumerd-cmd-sock PATH   Specify path for the UST consumer command socket\n");
+       fprintf(stderr, "      --ustconsumerd-compat32 PATH   Specify path for the 32-bit UST consumer daemon binary\n");
        fprintf(stderr, "  -d, --daemonize                    Start as a daemon.\n");
        fprintf(stderr, "  -g, --group NAME                   Specify the tracing group name. (default: tracing)\n");
        fprintf(stderr, "  -V, --version                      Show version number.\n");
@@ -3462,6 +3483,7 @@ static int parse_args(int argc, char **argv)
                { "kconsumerd-err-sock", 1, 0, 'E' },
                { "ustconsumerd-cmd-sock", 1, 0, 'D' },
                { "ustconsumerd-err-sock", 1, 0, 'F' },
+               { "ustconsumerd-compat32", 1, 0, 'u' },
                { "daemonize", 0, 0, 'd' },
                { "sig-parent", 0, 0, 'S' },
                { "help", 0, 0, 'h' },
@@ -3475,7 +3497,7 @@ static int parse_args(int argc, char **argv)
 
        while (1) {
                int option_index = 0;
-               c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:C:E:D:F:Z",
+               c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:C:E:D:F:Z:u",
                                long_options, &option_index);
                if (c == -1) {
                        break;
@@ -3498,7 +3520,7 @@ static int parse_args(int argc, char **argv)
                        opt_daemon = 1;
                        break;
                case 'g':
-                       opt_tracing_group = strdup(optarg);
+                       opt_tracing_group = optarg;
                        break;
                case 'h':
                        usage();
@@ -3531,6 +3553,9 @@ static int parse_args(int argc, char **argv)
                case 'Z':
                        opt_verbose_consumer += 1;
                        break;
+               case 'u':
+                       compat32_consumer_bindir = optarg;
+                       break;
                default:
                        /* Unknown option or other error.
                         * Error is printed by getopt, just return */
@@ -3857,6 +3882,8 @@ int main(int argc, char **argv)
                goto error;
        }
 
+       setup_compat32_consumer();
+
        /* Parse arguments */
        progname = argv[0];
        if ((ret = parse_args(argc, argv) < 0)) {
This page took 0.025475 seconds and 4 git commands to generate.