Use the consumerd_bin variables for kernel consumers too
[lttng-tools.git] / lttng-sessiond / main.c
index 0a78f27bad9e9e6f85ad9e86008030464b924a39..c6ecb2737f2db2ef7e1c9efe0263b7f1d635242b 100644 (file)
@@ -50,7 +50,7 @@
 #include "event.h"
 #include "futex.h"
 #include "hashtable.h"
-#include "kernel-ctl.h"
+#include "kernel.h"
 #include "lttng-sessiond.h"
 #include "shm.h"
 #include "ust-app.h"
@@ -171,10 +171,10 @@ static struct ltt_session_list *session_list_ptr;
 int ust_consumerd64_fd = -1;
 int ust_consumerd32_fd = -1;
 
-static const char *consumerd32_path =
-       __stringify(CONFIG_CONSUMERD32_PATH);
-static const char *consumerd64_path =
-       __stringify(CONFIG_CONSUMERD64_PATH);
+static const char *consumerd32_bin =
+       __stringify(CONFIG_CONSUMERD32_BIN);
+static const char *consumerd64_bin =
+       __stringify(CONFIG_CONSUMERD64_BIN);
 static const char *consumerd32_libdir =
        __stringify(CONFIG_CONSUMERD32_LIBDIR);
 static const char *consumerd64_libdir =
@@ -183,7 +183,7 @@ static const char *consumerd64_libdir =
 static
 void setup_consumerd_path(void)
 {
-       const char *path, *libdir;
+       const char *bin, *libdir;
 
        /*
         * Allow INSTALL_BIN_PATH to be used as a target path for the
@@ -191,15 +191,15 @@ void setup_consumerd_path(void)
         * has not been defined.
         */
 #if (CAA_BITS_PER_LONG == 32)
-       if (!consumerd32_path[0]) {
-               consumerd32_path = INSTALL_BIN_PATH "/" CONSUMERD_FILE;
+       if (!consumerd32_bin[0]) {
+               consumerd32_bin = INSTALL_BIN_PATH "/" CONSUMERD_FILE;
        }
        if (!consumerd32_libdir[0]) {
                consumerd32_libdir = INSTALL_LIB_PATH;
        }
 #elif (CAA_BITS_PER_LONG == 64)
-       if (!consumerd64_path[0]) {
-               consumerd64_path = INSTALL_BIN_PATH "/" CONSUMERD_FILE;
+       if (!consumerd64_bin[0]) {
+               consumerd64_bin = INSTALL_BIN_PATH "/" CONSUMERD_FILE;
        }
        if (!consumerd64_libdir[0]) {
                consumerd64_libdir = INSTALL_LIB_PATH;
@@ -211,13 +211,13 @@ void setup_consumerd_path(void)
        /*
         * runtime env. var. overrides the build default.
         */
-       path = getenv("LTTNG_CONSUMERD32_PATH");
-       if (path) {
-               consumerd32_path = path;
+       bin = getenv("LTTNG_CONSUMERD32_BIN");
+       if (bin) {
+               consumerd32_bin = bin;
        }
-       path = getenv("LTTNG_CONSUMERD64_PATH");
-       if (path) {
-               consumerd64_path = path;
+       bin = getenv("LTTNG_CONSUMERD64_BIN");
+       if (bin) {
+               consumerd64_bin = bin;
        }
        libdir = getenv("LTTNG_TOOLS_CONSUMERD32_LIBDIR");
        if (libdir) {
@@ -1508,7 +1508,9 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
 {
        int ret;
        pid_t pid;
+       const char *consumer_to_use;
        const char *verbosity;
+       struct stat st;
 
        DBG("Spawning consumerd");
 
@@ -1524,15 +1526,30 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                }
                switch (consumer_data->type) {
                case LTTNG_CONSUMER_KERNEL:
-                       execl(INSTALL_BIN_PATH "/lttng-consumerd",
-                                       "lttng-consumerd", verbosity, "-k",
-                                       "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
-                                       "--consumerd-err-sock", consumer_data->err_unix_sock_path,
-                                       NULL);
+                       /*
+                        * Find out which consumerd to execute. We will first
+                        * try the 64-bit path, then the 32-bit one, then
+                        * fallback on sessiond's installation directory.
+                        */
+                       if (stat(consumerd64_bin, &st) == 0) {
+                               consumer_to_use = consumerd64_bin;
+                       } else if (stat(consumerd32_bin, &st) == 0) {
+                               consumer_to_use = consumerd32_bin;
+                       } else if (stat(INSTALL_BIN_PATH "/" CONSUMERD_FILE, &st) == 0) {
+                               consumer_to_use = INSTALL_BIN_PATH "/" CONSUMERD_FILE;
+                       } else {
+                               break;
+                       }
+                       DBG("Using kernel consumer at: %s",  consumer_to_use);
+                       execl(consumer_to_use,
+                               "lttng-consumerd", verbosity, "-k",
+                               "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
+                               "--consumerd-err-sock", consumer_data->err_unix_sock_path,
+                               NULL);
                        break;
                case LTTNG_CONSUMER64_UST:
                {
-                       char *tmpnew;
+                       char *tmpnew = NULL;
 
                        if (consumerd64_libdir[0] != '\0') {
                                char *tmp;
@@ -1561,7 +1578,8 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                        goto error;
                                }
                        }
-                       ret = execl(consumerd64_path, verbosity, "-u",
+                       DBG("Using 64-bit UST consumer at: %s",  consumerd64_bin);
+                       ret = execl(consumerd64_bin, verbosity, "-u",
                                        "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        NULL);
@@ -1575,7 +1593,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                }
                case LTTNG_CONSUMER32_UST:
                {
-                       char *tmpnew;
+                       char *tmpnew = NULL;
 
                        if (consumerd32_libdir[0] != '\0') {
                                char *tmp;
@@ -1604,7 +1622,8 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                        goto error;
                                }
                        }
-                       ret = execl(consumerd32_path, verbosity, "-u",
+                       DBG("Using 32-bit UST consumer at: %s",  consumerd32_bin);
+                       ret = execl(consumerd32_bin, verbosity, "-u",
                                        "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        NULL);
@@ -2073,6 +2092,11 @@ static int list_lttng_ust_global_events(char *channel_name,
                case LTTNG_UST_FUNCTION:
                        tmp[i].type = LTTNG_EVENT_FUNCTION;
                        break;
+               case LTTNG_UST_TRACEPOINT_LOGLEVEL:
+                       /* TODO */
+                       ret = -LTTCOMM_NOT_IMPLEMENTED;
+                       goto error;
+                       break;
                }
                i++;
        }
@@ -2191,7 +2215,13 @@ static int cmd_disable_channel(struct ltt_session *session,
                        goto error;
                }
 
-               ret = ust_app_disable_channel_all(usess, uchan);
+               /* Already disabled */
+               if (!uchan->enabled) {
+                       DBG2("UST channel %s already disabled", channel_name);
+                       break;
+               }
+
+               ret = ust_app_disable_channel_glb(usess, uchan);
                if (ret < 0) {
                        ret = LTTCOMM_UST_DISABLE_FAIL;
                        goto error;
@@ -2299,28 +2329,32 @@ static int cmd_enable_channel(struct ltt_session *session,
                                goto error;
                        }
 
-                       rcu_read_lock();
-                       hashtable_add_unique(usess->domain_global.channels, &uchan->node);
-                       rcu_read_unlock();
-                       DBG2("UST channel %s added to global domain HT", attr->name);
-
                        /* Add channel to all registered applications */
-                       ret = ust_app_create_channel_all(usess, uchan);
+                       ret = ust_app_create_channel_glb(usess, uchan);
                        if (ret != 0) {
                                ret = LTTCOMM_UST_CHAN_FAIL;
                                goto error;
                        }
+
+                       rcu_read_lock();
+                       hashtable_add_unique(usess->domain_global.channels, &uchan->node);
+                       rcu_read_unlock();
+
+                       DBG2("UST channel %s added to global domain HT", attr->name);
                } else {
                        /* If already enabled, everything is OK */
                        if (uchan->enabled) {
-                               ret = LTTCOMM_OK;
-                               goto error;
+                               break;
                        }
 
-                       ret = ust_app_enable_channel_all(usess, uchan);
+                       ret = ust_app_enable_channel_glb(usess, uchan);
                        if (ret < 0) {
-                               ret = LTTCOMM_UST_ENABLE_FAIL;
-                               goto error;
+                               if (ret != -EEXIST) {
+                                       ret = LTTCOMM_UST_CHAN_ENABLE_FAIL;
+                                       goto error;
+                               } else {
+                                       ret = LTTCOMM_OK;
+                               }
                        }
                }
 
@@ -2378,6 +2412,7 @@ static int cmd_disable_event(struct ltt_session *session, int domain,
        {
                struct ltt_ust_session *usess;
                struct ltt_ust_channel *uchan;
+               struct ltt_ust_event *uevent;
 
                usess = session->ust_session;
 
@@ -2388,12 +2423,20 @@ static int cmd_disable_event(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               ret = ust_app_disable_event(usess, uchan, event_name);
+               uevent = trace_ust_find_event_by_name(uchan->events, event_name);
+               if (uevent == NULL) {
+                       ret = LTTCOMM_UST_EVENT_NOT_FOUND;
+                       goto error;
+               }
+
+               ret = ust_app_disable_event_glb(usess, uchan, uevent);
                if (ret < 0) {
                        ret = LTTCOMM_UST_DISABLE_FAIL;
                        goto error;
                }
 
+               uevent->enabled = 0;
+
                DBG2("Disable UST event %s in channel %s completed", event_name,
                                channel_name);
 
@@ -2457,7 +2500,7 @@ static int cmd_disable_event_all(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               ret = ust_app_disable_event_all(usess, uchan);
+               ret = ust_app_disable_all_event_glb(usess, uchan);
                if (ret < 0) {
                        ret = LTTCOMM_UST_DISABLE_FAIL;
                        goto error;
@@ -2500,21 +2543,18 @@ static int cmd_add_context(struct ltt_session *session, int domain,
                break;
        case LTTNG_DOMAIN_UST:
        {
-               /*
-               struct ltt_ust_session *usess;
+               struct ltt_ust_session *usess = session->ust_session;
 
-               cds_list_for_each_entry(usess, &session->ust_session_list.head, list) {
-                       ret = context_ust_add(usess, ctx,
-                                       event_name, channel_name, domain);
-                       if (ret != LTTCOMM_OK) {
-                               goto error;
-                       }
+               ret = context_ust_add(usess, domain, ctx, event_name, channel_name);
+               if (ret != LTTCOMM_OK) {
+                       goto error;
                }
                break;
-               */
        }
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
        default:
-               /* TODO: UST other domains */
                ret = LTTCOMM_NOT_IMPLEMENTED;
                goto error;
        }
@@ -2580,10 +2620,10 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
        }
        case LTTNG_DOMAIN_UST:
        {
-               struct ltt_ust_channel *uchan;
-               struct ltt_ust_event *uevent;
                struct lttng_channel *attr;
+               struct ltt_ust_channel *uchan;
 
+               /* Get channel from global UST domain */
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
                if (uchan == NULL) {
@@ -2594,14 +2634,14 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
                                goto error;
                        }
                        snprintf(attr->name, NAME_MAX, "%s", channel_name);
+                       attr->name[NAME_MAX - 1] = '\0';
 
                        /* Use the internal command enable channel */
                        ret = cmd_enable_channel(session, domain, attr);
-                       if (ret < 0) {
+                       if (ret != LTTCOMM_OK) {
                                free(attr);
                                goto error;
                        }
-
                        free(attr);
 
                        /* Get the newly created channel reference back */
@@ -2614,31 +2654,12 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
                        }
                }
 
-               uevent = trace_ust_find_event_by_name(uchan->events, event->name);
-               if (uevent == NULL) {
-                       uevent = trace_ust_create_event(event);
-                       if (uevent == NULL) {
-                               ret = LTTCOMM_FATAL;
-                               goto error;
-                       }
-
-               }
+               /* At this point, the session and channel exist on the tracer */
 
-               ret = ust_app_create_event_all(usess, uchan, uevent);
-               if (ret < 0) {
-                       ret = LTTCOMM_UST_ENABLE_FAIL;
+               ret = event_ust_enable_tracepoint(usess, domain, uchan, event);
+               if (ret != LTTCOMM_OK) {
                        goto error;
                }
-
-               /* Add ltt ust event to channel */
-               rcu_read_lock();
-               hashtable_add_unique(uchan->events, &uevent->node);
-               rcu_read_unlock();
-
-               uevent->enabled = 1;
-
-               DBG3("UST ltt event %s added to channel %s", uevent->attr.name,
-                               uchan->name);
                break;
        }
        case LTTNG_DOMAIN_UST_EXEC_NAME:
@@ -2675,15 +2696,16 @@ static int cmd_enable_event_all(struct ltt_session *session, int domain,
                        if (ret != LTTCOMM_OK) {
                                goto error;
                        }
-               }
 
-               /* Get the newly created kernel channel pointer */
-               kchan = trace_kernel_get_channel_by_name(channel_name,
-                               session->kernel_session);
-               if (kchan == NULL) {
-                       /* This sould not happen... */
-                       ret = LTTCOMM_FATAL;
-                       goto error;
+                       /* Get the newly created kernel channel pointer */
+                       kchan = trace_kernel_get_channel_by_name(channel_name,
+                                       session->kernel_session);
+                       if (kchan == NULL) {
+                               /* This sould not happen... */
+                               ret = LTTCOMM_FATAL;
+                               goto error;
+                       }
+
                }
 
                switch (event_type) {
@@ -2708,6 +2730,8 @@ static int cmd_enable_event_all(struct ltt_session *session, int domain,
                        ret = LTTCOMM_KERN_ENABLE_FAIL;
                        goto error;
                }
+
+               /* Manage return value */
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
@@ -3260,7 +3284,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                        /* Start the UST consumer daemons */
                        /* 64-bit */
                        pthread_mutex_lock(&ustconsumer64_data.pid_mutex);
-                       if (consumerd64_path[0] != '\0' &&
+                       if (consumerd64_bin[0] != '\0' &&
                                        ustconsumer64_data.pid == 0 &&
                                        cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) {
                                pthread_mutex_unlock(&ustconsumer64_data.pid_mutex);
@@ -3276,7 +3300,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                                pthread_mutex_unlock(&ustconsumer64_data.pid_mutex);
                        }
                        /* 32-bit */
-                       if (consumerd32_path[0] != '\0' &&
+                       if (consumerd32_bin[0] != '\0' &&
                                        ustconsumer32_data.pid == 0 &&
                                        cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) {
                                pthread_mutex_unlock(&ustconsumer32_data.pid_mutex);
@@ -3825,13 +3849,13 @@ static int parse_args(int argc, char **argv)
                        opt_verbose_consumer += 1;
                        break;
                case 'u':
-                       consumerd32_path= optarg;
+                       consumerd32_bin= optarg;
                        break;
                case 'U':
                        consumerd32_libdir = optarg;
                        break;
                case 't':
-                       consumerd64_path = optarg;
+                       consumerd64_bin = optarg;
                        break;
                case 'T':
                        consumerd64_libdir = optarg;
This page took 0.029294 seconds and 4 git commands to generate.