listing and activation of loglevel by number
[lttng-tools.git] / lttng-sessiond / main.c
index 0acf230e0d09c9553be4e0f2a688b3c8ca8bc244..0a6319f357ac99c2ddf8d3ddf33efe6bf8de7189 100644 (file)
 #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"
 #include "ust-ctl.h"
 #include "utils.h"
 
+#define CONSUMERD_FILE "lttng-consumerd"
+
 struct consumer_data {
        enum lttng_consumer_type type;
 
@@ -96,9 +98,18 @@ static pid_t ppid;          /* Parent PID for --sig-parent option */
 /* Consumer daemon specific control data */
 static struct consumer_data kconsumer_data = {
        .type = LTTNG_CONSUMER_KERNEL,
+       .err_unix_sock_path = KCONSUMERD_ERR_SOCK_PATH,
+       .cmd_unix_sock_path = KCONSUMERD_CMD_SOCK_PATH,
+};
+static struct consumer_data ustconsumer64_data = {
+       .type = LTTNG_CONSUMER64_UST,
+       .err_unix_sock_path = USTCONSUMERD64_ERR_SOCK_PATH,
+       .cmd_unix_sock_path = USTCONSUMERD64_CMD_SOCK_PATH,
 };
-static struct consumer_data ustconsumer_data = {
-       .type = LTTNG_CONSUMER_UST,
+static struct consumer_data ustconsumer32_data = {
+       .type = LTTNG_CONSUMER32_UST,
+       .err_unix_sock_path = USTCONSUMERD32_ERR_SOCK_PATH,
+       .cmd_unix_sock_path = USTCONSUMERD32_CMD_SOCK_PATH,
 };
 
 static int dispatch_thread_exit;
@@ -157,7 +168,66 @@ static struct ust_cmd_queue ust_cmd_queue;
  */
 static struct ltt_session_list *session_list_ptr;
 
-int ust_consumer_fd;
+int ust_consumerd64_fd = -1;
+int ust_consumerd32_fd = -1;
+
+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 =
+       __stringify(CONFIG_CONSUMERD64_LIBDIR);
+
+static
+void setup_consumerd_path(void)
+{
+       const char *bin, *libdir;
+
+       /*
+        * Allow INSTALL_BIN_PATH to be used as a target path for the
+        * native architecture size consumer if CONFIG_CONSUMER*_PATH
+        * has not been defined.
+        */
+#if (CAA_BITS_PER_LONG == 32)
+       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_bin[0]) {
+               consumerd64_bin = INSTALL_BIN_PATH "/" CONSUMERD_FILE;
+       }
+       if (!consumerd64_libdir[0]) {
+               consumerd64_libdir = INSTALL_LIB_PATH;
+       }
+#else
+#error "Unknown bitness"
+#endif
+
+       /*
+        * runtime env. var. overrides the build default.
+        */
+       bin = getenv("LTTNG_CONSUMERD32_BIN");
+       if (bin) {
+               consumerd32_bin = bin;
+       }
+       bin = getenv("LTTNG_CONSUMERD64_BIN");
+       if (bin) {
+               consumerd64_bin = bin;
+       }
+       libdir = getenv("LTTNG_TOOLS_CONSUMERD32_LIBDIR");
+       if (libdir) {
+               consumerd32_libdir = libdir;
+       }
+       libdir = getenv("LTTNG_TOOLS_CONSUMERD64_LIBDIR");
+       if (libdir) {
+               consumerd64_libdir = libdir;
+       }
+}
 
 /*
  * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
@@ -282,21 +352,22 @@ error:
  */
 static void teardown_kernel_session(struct ltt_session *session)
 {
-       if (session->kernel_session != NULL) {
-               DBG("Tearing down kernel session");
+       if (!session->kernel_session) {
+               DBG3("No kernel session when tearingdown session");
+               return;
+       }
 
-               /*
-                * If a custom kernel consumer was registered, close the socket before
-                * tearing down the complete kernel session structure
-                */
-               if (session->kernel_session->consumer_fd != kconsumer_data.cmd_sock) {
-                       lttcomm_close_unix_sock(session->kernel_session->consumer_fd);
-               }
+       DBG("Tearing down kernel session");
 
-               trace_kernel_destroy_session(session->kernel_session);
-               /* Extra precaution */
-               session->kernel_session = NULL;
+       /*
+        * If a custom kernel consumer was registered, close the socket before
+        * tearing down the complete kernel session structure
+        */
+       if (session->kernel_session->consumer_fd != kconsumer_data.cmd_sock) {
+               lttcomm_close_unix_sock(session->kernel_session->consumer_fd);
        }
+
+       trace_kernel_destroy_session(session->kernel_session);
 }
 
 /*
@@ -307,12 +378,18 @@ static void teardown_ust_session(struct ltt_session *session)
 {
        int ret;
 
+       if (!session->ust_session) {
+               DBG3("No UST session when tearingdown session");
+               return;
+       }
+
        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);
 }
 
@@ -1060,9 +1137,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;
                                        }
 
                                        /*
@@ -1430,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");
 
@@ -1446,13 +1526,115 @@ 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", 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 = NULL;
+
+                       if (consumerd64_libdir[0] != '\0') {
+                               char *tmp;
+                               size_t tmplen;
+
+                               tmp = getenv("LD_LIBRARY_PATH");
+                               if (!tmp) {
+                                       tmp = "";
+                               }
+                               tmplen = strlen("LD_LIBRARY_PATH=")
+                                       + strlen(consumerd64_libdir) + 1 /* : */ + strlen(tmp);
+                               tmpnew = zmalloc(tmplen + 1 /* \0 */);
+                               if (!tmpnew) {
+                                       ret = -ENOMEM;
+                                       goto error;
+                               }
+                               strcpy(tmpnew, "LD_LIBRARY_PATH=");
+                               strcat(tmpnew, consumerd64_libdir);
+                               if (tmp[0] != '\0') {
+                                       strcat(tmpnew, ":");
+                                       strcat(tmpnew, tmp);
+                               }
+                               ret = putenv(tmpnew);
+                               if (ret) {
+                                       ret = -errno;
+                                       goto error;
+                               }
+                       }
+                       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);
+                       if (consumerd64_libdir[0] != '\0') {
+                               free(tmpnew);
+                       }
+                       if (ret) {
+                               goto error;
+                       }
                        break;
-               case LTTNG_CONSUMER_UST:
-                       execl(INSTALL_BIN_PATH "/lttng-consumerd",
-                                       "lttng-consumerd", verbosity, "-u", NULL);
+               }
+               case LTTNG_CONSUMER32_UST:
+               {
+                       char *tmpnew = NULL;
+
+                       if (consumerd32_libdir[0] != '\0') {
+                               char *tmp;
+                               size_t tmplen;
+
+                               tmp = getenv("LD_LIBRARY_PATH");
+                               if (!tmp) {
+                                       tmp = "";
+                               }
+                               tmplen = strlen("LD_LIBRARY_PATH=")
+                                       + strlen(consumerd32_libdir) + 1 /* : */ + strlen(tmp);
+                               tmpnew = zmalloc(tmplen + 1 /* \0 */);
+                               if (!tmpnew) {
+                                       ret = -ENOMEM;
+                                       goto error;
+                               }
+                               strcpy(tmpnew, "LD_LIBRARY_PATH=");
+                               strcat(tmpnew, consumerd32_libdir);
+                               if (tmp[0] != '\0') {
+                                       strcat(tmpnew, ":");
+                                       strcat(tmpnew, tmp);
+                               }
+                               ret = putenv(tmpnew);
+                               if (ret) {
+                                       ret = -errno;
+                                       goto error;
+                               }
+                       }
+                       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);
+                       if (consumerd32_libdir[0] != '\0') {
+                               free(tmpnew);
+                       }
+                       if (ret) {
+                               goto error;
+                       }
                        break;
+               }
                default:
                        perror("unknown consumer type");
                        exit(EXIT_FAILURE);
@@ -1467,6 +1649,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                perror("start consumer fork");
                ret = -errno;
        }
+error:
        return ret;
 }
 
@@ -1703,10 +1886,7 @@ static int create_ust_session(struct ltt_session *session,
 
        DBG("Creating UST session");
 
-       session_lock_list();
-       uid = session_list_ptr->count;
-       session_unlock_list();
-
+       uid = session->uid;
        lus = trace_ust_create_session(session->path, uid, domain);
        if (lus == NULL) {
                ret = LTTCOMM_UST_SESS_FAIL;
@@ -1840,7 +2020,14 @@ static void list_lttng_channels(int domain, struct ltt_session *session,
                                uchan->attr.switch_timer_interval;
                        channels[i].attr.read_timer_interval =
                                uchan->attr.read_timer_interval;
-                       channels[i].attr.output = uchan->attr.output;
+                       channels[i].enabled = uchan->enabled;
+                       switch (uchan->attr.output) {
+                       case LTTNG_UST_MMAP:
+                       default:
+                               channels[i].attr.output = LTTNG_EVENT_MMAP;
+                               break;
+                       }
+                       i++;
                }
                break;
        }
@@ -1858,6 +2045,7 @@ static int list_lttng_ust_global_events(char *channel_name,
        int i = 0, ret = 0;
        unsigned int nb_event = 0;
        struct cds_lfht_iter iter;
+       struct cds_lfht_node *node;
        struct ltt_ust_channel *uchan;
        struct ltt_ust_event *uevent;
        struct lttng_event *tmp;
@@ -1866,11 +2054,17 @@ static int list_lttng_ust_global_events(char *channel_name,
 
        rcu_read_lock();
 
-       /* Count events in all channels */
-       cds_lfht_for_each_entry(ust_global->channels, &iter, uchan, node) {
-               nb_event += hashtable_get_count(uchan->events);
+       node = hashtable_lookup(ust_global->channels, (void *) channel_name,
+                       strlen(channel_name), &iter);
+       if (node == NULL) {
+               ret = -LTTCOMM_UST_CHAN_NOT_FOUND;
+               goto error;
        }
 
+       uchan = caa_container_of(node, struct ltt_ust_channel, node);
+
+       nb_event += hashtable_get_count(uchan->events);
+
        if (nb_event == 0) {
                ret = nb_event;
                goto error;
@@ -1884,24 +2078,25 @@ static int list_lttng_ust_global_events(char *channel_name,
                goto error;
        }
 
-       cds_lfht_for_each_entry(ust_global->channels, &iter, uchan, node) {
-               cds_lfht_for_each_entry(uchan->events, &iter, uevent, node) {
-                       strncpy(tmp[i].name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN);
-                       tmp[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
-                       tmp[i].enabled = uevent->enabled;
-                       switch (uevent->attr.instrumentation) {
-                       case LTTNG_UST_TRACEPOINT:
-                               tmp[i].type = LTTNG_EVENT_TRACEPOINT;
-                               break;
-                       case LTTNG_UST_PROBE:
-                               tmp[i].type = LTTNG_EVENT_PROBE;
-                               break;
-                       case LTTNG_UST_FUNCTION:
-                               tmp[i].type = LTTNG_EVENT_FUNCTION;
-                               break;
-                       }
-                       i++;
+       cds_lfht_for_each_entry(uchan->events, &iter, uevent, node) {
+               strncpy(tmp[i].name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN);
+               tmp[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+               tmp[i].enabled = uevent->enabled;
+               switch (uevent->attr.instrumentation) {
+               case LTTNG_UST_TRACEPOINT:
+                       tmp[i].type = LTTNG_EVENT_TRACEPOINT;
+                       break;
+               case LTTNG_UST_PROBE:
+                       tmp[i].type = LTTNG_EVENT_PROBE;
+                       break;
+               case LTTNG_UST_FUNCTION:
+                       tmp[i].type = LTTNG_EVENT_FUNCTION;
+                       break;
+               case LTTNG_UST_TRACEPOINT_LOGLEVEL:
+                       tmp[i].type = LTTNG_EVENT_TRACEPOINT_LOGLEVEL;
+                       break;
                }
+               i++;
        }
 
        ret = nb_event;
@@ -1990,22 +2185,58 @@ static int cmd_disable_channel(struct ltt_session *session,
                int domain, char *channel_name)
 {
        int ret;
+       struct ltt_ust_session *usess;
+
+       usess = session->ust_session;
 
        switch (domain) {
-               case LTTNG_DOMAIN_KERNEL:
-                       ret = channel_kernel_disable(session->kernel_session,
-                                       channel_name);
-                       if (ret != LTTCOMM_OK) {
-                               goto error;
-                       }
+       case LTTNG_DOMAIN_KERNEL:
+       {
+               ret = channel_kernel_disable(session->kernel_session,
+                               channel_name);
+               if (ret != LTTCOMM_OK) {
+                       goto error;
+               }
 
-                       kernel_wait_quiescent(kernel_tracer_fd);
-                       break;
-               case LTTNG_DOMAIN_UST_PID:
+               kernel_wait_quiescent(kernel_tracer_fd);
+               break;
+       }
+       case LTTNG_DOMAIN_UST:
+       {
+               struct ltt_ust_channel *uchan;
+
+               /* Get channel in global UST domain HT */
+               uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
+                               channel_name);
+               if (uchan == NULL) {
+                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+                       goto error;
+               }
+
+               /* Already disabled */
+               if (!uchan->enabled) {
+                       DBG2("UST channel %s already disabled", channel_name);
                        break;
-               default:
-                       ret = LTTCOMM_UNKNOWN_DOMAIN;
+               }
+
+               ret = ust_app_disable_channel_glb(usess, uchan);
+               if (ret < 0) {
+                       ret = LTTCOMM_UST_DISABLE_FAIL;
                        goto error;
+               }
+
+               uchan->enabled = 0;
+
+               break;
+       }
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+               ret = LTTCOMM_NOT_IMPLEMENTED;
+               goto error;
+       default:
+               ret = LTTCOMM_UNKNOWN_DOMAIN;
+               goto error;
        }
 
        ret = LTTCOMM_OK;
@@ -2052,14 +2283,14 @@ error:
  * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
  */
 static int cmd_enable_channel(struct ltt_session *session,
-               struct lttng_domain *domain, struct lttng_channel *attr)
+               int domain, struct lttng_channel *attr)
 {
        int ret;
        struct ltt_ust_session *usess = session->ust_session;
 
        DBG("Enabling channel %s for session %s", attr->name, session->name);
 
-       switch (domain->type) {
+       switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
        {
                struct ltt_kernel_channel *kchan;
@@ -2096,69 +2327,44 @@ static int cmd_enable_channel(struct ltt_session *session,
                                goto error;
                        }
 
+                       /* Add channel to all registered applications */
+                       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 {
-                       ret = LTTCOMM_UST_CHAN_EXIST;
-                       goto error;
-               }
+                       /* If already enabled, everything is OK */
+                       if (uchan->enabled) {
+                               break;
+                       }
 
-               /* Add channel to all registered applications */
-               ret = ust_app_create_channel_all(usess, uchan);
-               if (ret != 0) {
-                       goto error;
+                       ret = ust_app_enable_channel_glb(usess, uchan);
+                       if (ret < 0) {
+                               if (ret != -EEXIST) {
+                                       ret = LTTCOMM_UST_CHAN_ENABLE_FAIL;
+                                       goto error;
+                               } else {
+                                       ret = LTTCOMM_OK;
+                               }
+                       }
                }
 
                uchan->enabled = 1;
 
                break;
        }
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
        case LTTNG_DOMAIN_UST_PID:
-       {
-               /*
-               int sock;
-               struct ltt_ust_channel *uchan;
-               struct ltt_ust_session *usess;
-               struct ust_app *app;
-
-               usess = trace_ust_get_session_by_pid(&session->ust_session_list,
-                               domain->attr.pid);
-               if (usess == NULL) {
-                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
-                       goto error;
-               }
-
-               app = ust_app_get_by_pid(domain->attr.pid);
-               if (app == NULL) {
-                       ret = LTTCOMM_APP_NOT_FOUND;
-                       goto error;
-               }
-               sock = app->sock;
-
-               uchan = trace_ust_get_channel_by_name(attr->name, usess);
-               if (uchan == NULL) {
-                       ret = channel_ust_create(usess, attr, sock);
-               } else {
-                       ret = channel_ust_enable(usess, uchan, sock);
-               }
-
-               if (ret != LTTCOMM_OK) {
-                       goto error;
-               }
-
-               ret = copy_ust_channel_to_app(usess, attr, app);
-               if (ret != LTTCOMM_OK) {
-                       goto error;
-               }
-
-               DBG("UST channel %s created for app sock %d with pid %d",
-                               attr->name, app->sock, domain->attr.pid);
-               */
                ret = LTTCOMM_NOT_IMPLEMENTED;
                goto error;
-       }
        default:
                ret = LTTCOMM_UNKNOWN_DOMAIN;
                goto error;
@@ -2182,15 +2388,17 @@ static int cmd_disable_event(struct ltt_session *session, int domain,
        case LTTNG_DOMAIN_KERNEL:
        {
                struct ltt_kernel_channel *kchan;
+               struct ltt_kernel_session *ksess;
 
-               kchan = trace_kernel_get_channel_by_name(channel_name,
-                               session->kernel_session);
+               ksess = session->kernel_session;
+
+               kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
                if (kchan == NULL) {
                        ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
                        goto error;
                }
 
-               ret = event_kernel_disable_tracepoint(session->kernel_session, kchan, event_name);
+               ret = event_kernel_disable_tracepoint(ksess, kchan, event_name);
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
@@ -2199,11 +2407,43 @@ static int cmd_disable_event(struct ltt_session *session, int domain,
                break;
        }
        case LTTNG_DOMAIN_UST:
+       {
+               struct ltt_ust_session *usess;
+               struct ltt_ust_channel *uchan;
+               struct ltt_ust_event *uevent;
+
+               usess = session->ust_session;
+
+               uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
+                               channel_name);
+               if (uchan == NULL) {
+                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+                       goto error;
+               }
+
+               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);
+
+               break;
+       }
        case LTTNG_DOMAIN_UST_EXEC_NAME:
        case LTTNG_DOMAIN_UST_PID:
        case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
        default:
-               /* TODO: Other UST domains */
                ret = LTTCOMM_NOT_IMPLEMENTED;
                goto error;
        }
@@ -2221,26 +2461,57 @@ static int cmd_disable_event_all(struct ltt_session *session, int domain,
                char *channel_name)
 {
        int ret;
-       struct ltt_kernel_channel *kchan;
 
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
-               kchan = trace_kernel_get_channel_by_name(channel_name,
-                               session->kernel_session);
+       {
+               struct ltt_kernel_session *ksess;
+               struct ltt_kernel_channel *kchan;
+
+               ksess = session->kernel_session;
+
+               kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
                if (kchan == NULL) {
                        ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
                        goto error;
                }
 
-               ret = event_kernel_disable_all(session->kernel_session, kchan);
+               ret = event_kernel_disable_all(ksess, kchan);
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
 
                kernel_wait_quiescent(kernel_tracer_fd);
                break;
+       }
+       case LTTNG_DOMAIN_UST:
+       {
+               struct ltt_ust_session *usess;
+               struct ltt_ust_channel *uchan;
+
+               usess = session->ust_session;
+
+               uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
+                               channel_name);
+               if (uchan == NULL) {
+                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+                       goto error;
+               }
+
+               ret = ust_app_disable_all_event_glb(usess, uchan);
+               if (ret < 0) {
+                       ret = LTTCOMM_UST_DISABLE_FAIL;
+                       goto error;
+               }
+
+               DBG2("Disable all UST event in channel %s completed", channel_name);
+
+               break;
+       }
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
        default:
-               /* TODO: Userspace tracing */
                ret = LTTCOMM_NOT_IMPLEMENTED;
                goto error;
        }
@@ -2270,21 +2541,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;
        }
@@ -2297,6 +2565,12 @@ error:
 
 /*
  * Command LTTNG_ENABLE_EVENT processed by the client thread.
+ *
+ * TODO: currently, both events and loglevels are kept within the same
+ * namespace for UST global registry/app registery, so if an event
+ * happen to have the same name as the loglevel (very unlikely though),
+ * and an attempt is made to enable/disable both in the same session,
+ * the first to be created will be the only one allowed to exist.
  */
 static int cmd_enable_event(struct ltt_session *session, int domain,
                char *channel_name, struct lttng_event *event)
@@ -2324,8 +2598,10 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
                        ret = channel_kernel_create(session->kernel_session,
                                        attr, kernel_poll_pipe[1]);
                        if (ret != LTTCOMM_OK) {
+                               free(attr);
                                goto error;
                        }
+                       free(attr);
                }
 
                /* Get the newly created kernel channel pointer */
@@ -2348,42 +2624,46 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
        }
        case LTTNG_DOMAIN_UST:
        {
+               struct lttng_channel *attr;
                struct ltt_ust_channel *uchan;
-               struct ltt_ust_event *uevent;
 
+               /* Get channel from global UST domain */
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
                if (uchan == NULL) {
-                       /* TODO: Create default channel */
-                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
-                       goto error;
-               }
-
-               uevent = trace_ust_find_event_by_name(uchan->events, event->name);
-               if (uevent == NULL) {
-                       uevent = trace_ust_create_event(event);
-                       if (uevent == NULL) {
+                       /* Create default channel */
+                       attr = channel_new_default_attr(domain);
+                       if (attr == NULL) {
                                ret = LTTCOMM_FATAL;
                                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 != LTTCOMM_OK) {
+                               free(attr);
+                               goto error;
+                       }
+                       free(attr);
 
-               ret = ust_app_create_event_all(usess, uchan, uevent);
-               if (ret < 0) {
-                       ret = LTTCOMM_UST_ENABLE_FAIL;
-                       goto error;
+                       /* Get the newly created channel reference back */
+                       uchan = trace_ust_find_channel_by_name(
+                                       usess->domain_global.channels, channel_name);
+                       if (uchan == NULL) {
+                               /* Something is really wrong */
+                               ret = LTTCOMM_FATAL;
+                               goto error;
+                       }
                }
 
-               /* Add ltt ust event to channel */
-               rcu_read_lock();
-               hashtable_add_unique(uchan->events, &uevent->node);
-               rcu_read_unlock();
-
-               uevent->enabled = 1;
+               /* At this point, the session and channel exist on the tracer */
 
-               DBG3("UST ltt event %s added to channel %s", uevent->attr.name,
-                               uchan->name);
+               ret = event_ust_enable_tracepoint(usess, domain, uchan, event);
+               if (ret != LTTCOMM_OK) {
+                       goto error;
+               }
                break;
        }
        case LTTNG_DOMAIN_UST_EXEC_NAME:
@@ -2420,15 +2700,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) {
@@ -2453,6 +2734,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;
                }
@@ -2638,7 +2921,6 @@ static int cmd_stop_trace(struct ltt_session *session)
                kernel_wait_quiescent(kernel_tracer_fd);
        }
 
-       /* Flag session that trace should start automatically */
        if (usess) {
                usess->start_trace = 0;
 
@@ -2988,8 +3270,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                                        ret = LTTCOMM_KERN_CONSUMER_FAIL;
                                        goto error;
                                }
+                       } else {
+                               pthread_mutex_unlock(&kconsumer_data.pid_mutex);
                        }
-                       pthread_mutex_unlock(&kconsumer_data.pid_mutex);
                }
                break;
        case LTTNG_DOMAIN_UST:
@@ -3002,20 +3285,39 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                                        goto error;
                                }
                        }
-                       /* Start the kernel consumer daemon */
-                       pthread_mutex_lock(&ustconsumer_data.pid_mutex);
-                       if (ustconsumer_data.pid == 0 &&
+                       /* Start the UST consumer daemons */
+                       /* 64-bit */
+                       pthread_mutex_lock(&ustconsumer64_data.pid_mutex);
+                       if (consumerd64_bin[0] != '\0' &&
+                                       ustconsumer64_data.pid == 0 &&
                                        cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) {
-                               pthread_mutex_unlock(&ustconsumer_data.pid_mutex);
-                               ret = start_consumerd(&ustconsumer_data);
+                               pthread_mutex_unlock(&ustconsumer64_data.pid_mutex);
+                               ret = start_consumerd(&ustconsumer64_data);
                                if (ret < 0) {
-                                       ret = LTTCOMM_KERN_CONSUMER_FAIL;
+                                       ret = LTTCOMM_UST_CONSUMER64_FAIL;
+                                       ust_consumerd64_fd = -EINVAL;
                                        goto error;
                                }
 
-                               ust_consumer_fd = ustconsumer_data.cmd_sock;
+                               ust_consumerd64_fd = ustconsumer64_data.cmd_sock;
+                       } else {
+                               pthread_mutex_unlock(&ustconsumer64_data.pid_mutex);
+                       }
+                       /* 32-bit */
+                       if (consumerd32_bin[0] != '\0' &&
+                                       ustconsumer32_data.pid == 0 &&
+                                       cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) {
+                               pthread_mutex_unlock(&ustconsumer32_data.pid_mutex);
+                               ret = start_consumerd(&ustconsumer32_data);
+                               if (ret < 0) {
+                                       ret = LTTCOMM_UST_CONSUMER32_FAIL;
+                                       ust_consumerd32_fd = -EINVAL;
+                                       goto error;
+                               }
+                               ust_consumerd32_fd = ustconsumer32_data.cmd_sock;
+                       } else {
+                               pthread_mutex_unlock(&ustconsumer32_data.pid_mutex);
                        }
-                       pthread_mutex_unlock(&ustconsumer_data.pid_mutex);
                }
                break;
        }
@@ -3057,7 +3359,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        }
        case LTTNG_ENABLE_CHANNEL:
        {
-               ret = cmd_enable_channel(cmd_ctx->session, &cmd_ctx->lsm->domain,
+               ret = cmd_enable_channel(cmd_ctx->session, cmd_ctx->lsm->domain.type,
                                &cmd_ctx->lsm->u.channel.chan);
                break;
        }
@@ -3438,8 +3740,14 @@ static void usage(void)
        fprintf(stderr, "  -a, --apps-sock PATH               Specify path for apps unix socket\n");
        fprintf(stderr, "      --kconsumerd-err-sock PATH     Specify path for the kernel consumer error socket\n");
        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, "      --ustconsumerd32-err-sock PATH Specify path for the 32-bit UST consumer error socket\n");
+       fprintf(stderr, "      --ustconsumerd64-err-sock PATH Specify path for the 64-bit UST consumer error socket\n");
+       fprintf(stderr, "      --ustconsumerd32-cmd-sock PATH Specify path for the 32-bit UST consumer command socket\n");
+       fprintf(stderr, "      --ustconsumerd64-cmd-sock PATH Specify path for the 64-bit UST consumer command socket\n");
+       fprintf(stderr, "      --consumerd32-path PATH     Specify path for the 32-bit UST consumer daemon binary\n");
+       fprintf(stderr, "      --consumerd32-libdir PATH   Specify path for the 32-bit UST consumer daemon libraries\n");
+       fprintf(stderr, "      --consumerd64-path PATH     Specify path for the 64-bit UST consumer daemon binary\n");
+       fprintf(stderr, "      --consumerd64-libdir PATH   Specify path for the 64-bit UST consumer daemon libraries\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");
@@ -3461,8 +3769,14 @@ static int parse_args(int argc, char **argv)
                { "apps-sock", 1, 0, 'a' },
                { "kconsumerd-cmd-sock", 1, 0, 'C' },
                { "kconsumerd-err-sock", 1, 0, 'E' },
-               { "ustconsumerd-cmd-sock", 1, 0, 'D' },
-               { "ustconsumerd-err-sock", 1, 0, 'F' },
+               { "ustconsumerd32-cmd-sock", 1, 0, 'G' },
+               { "ustconsumerd32-err-sock", 1, 0, 'H' },
+               { "ustconsumerd64-cmd-sock", 1, 0, 'D' },
+               { "ustconsumerd64-err-sock", 1, 0, 'F' },
+               { "consumerd32-path", 1, 0, 'u' },
+               { "consumerd32-libdir", 1, 0, 'U' },
+               { "consumerd64-path", 1, 0, 't' },
+               { "consumerd64-libdir", 1, 0, 'T' },
                { "daemonize", 0, 0, 'd' },
                { "sig-parent", 0, 0, 'S' },
                { "help", 0, 0, 'h' },
@@ -3476,7 +3790,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:t",
                                long_options, &option_index);
                if (c == -1) {
                        break;
@@ -3499,7 +3813,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();
@@ -3517,10 +3831,16 @@ static int parse_args(int argc, char **argv)
                        snprintf(kconsumer_data.cmd_unix_sock_path, PATH_MAX, "%s", optarg);
                        break;
                case 'F':
-                       snprintf(ustconsumer_data.err_unix_sock_path, PATH_MAX, "%s", optarg);
+                       snprintf(ustconsumer64_data.err_unix_sock_path, PATH_MAX, "%s", optarg);
                        break;
                case 'D':
-                       snprintf(ustconsumer_data.cmd_unix_sock_path, PATH_MAX, "%s", optarg);
+                       snprintf(ustconsumer64_data.cmd_unix_sock_path, PATH_MAX, "%s", optarg);
+                       break;
+               case 'H':
+                       snprintf(ustconsumer32_data.err_unix_sock_path, PATH_MAX, "%s", optarg);
+                       break;
+               case 'G':
+                       snprintf(ustconsumer32_data.cmd_unix_sock_path, PATH_MAX, "%s", optarg);
                        break;
                case 'q':
                        opt_quiet = 1;
@@ -3532,6 +3852,18 @@ static int parse_args(int argc, char **argv)
                case 'Z':
                        opt_verbose_consumer += 1;
                        break;
+               case 'u':
+                       consumerd32_bin= optarg;
+                       break;
+               case 'U':
+                       consumerd32_libdir = optarg;
+                       break;
+               case 't':
+                       consumerd64_bin = optarg;
+                       break;
+               case 'T':
+                       consumerd64_libdir = optarg;
+                       break;
                default:
                        /* Unknown option or other error.
                         * Error is printed by getopt, just return */
@@ -3655,10 +3987,17 @@ static int set_permissions(void)
                perror("chown");
        }
 
-       /* ustconsumer error socket path */
-       ret = chown(ustconsumer_data.err_unix_sock_path, 0, gid);
+       /* 64-bit ustconsumer error socket path */
+       ret = chown(ustconsumer64_data.err_unix_sock_path, 0, gid);
+       if (ret < 0) {
+               ERR("Unable to set group on %s", ustconsumer64_data.err_unix_sock_path);
+               perror("chown");
+       }
+
+       /* 32-bit ustconsumer compat32 error socket path */
+       ret = chown(ustconsumer32_data.err_unix_sock_path, 0, gid);
        if (ret < 0) {
-               ERR("Unable to set group on %s", ustconsumer_data.err_unix_sock_path);
+               ERR("Unable to set group on %s", ustconsumer32_data.err_unix_sock_path);
                perror("chown");
        }
 
@@ -3712,21 +4051,22 @@ error:
 static int set_consumer_sockets(struct consumer_data *consumer_data)
 {
        int ret;
-       const char *path = consumer_data->type == LTTNG_CONSUMER_KERNEL ?
-                       KCONSUMERD_PATH : USTCONSUMERD_PATH;
-
-       if (strlen(consumer_data->err_unix_sock_path) == 0) {
-               snprintf(consumer_data->err_unix_sock_path, PATH_MAX,
-                       consumer_data->type == LTTNG_CONSUMER_KERNEL ?
-                               KCONSUMERD_ERR_SOCK_PATH :
-                               USTCONSUMERD_ERR_SOCK_PATH);
-       }
+       const char *path;
 
-       if (strlen(consumer_data->cmd_unix_sock_path) == 0) {
-               snprintf(consumer_data->cmd_unix_sock_path, PATH_MAX,
-                       consumer_data->type == LTTNG_CONSUMER_KERNEL ?
-                               KCONSUMERD_CMD_SOCK_PATH :
-                               USTCONSUMERD_CMD_SOCK_PATH);
+       switch (consumer_data->type) {
+       case LTTNG_CONSUMER_KERNEL:
+               path = KCONSUMERD_PATH;
+               break;
+       case LTTNG_CONSUMER64_UST:
+               path = USTCONSUMERD64_PATH;
+               break;
+       case LTTNG_CONSUMER32_UST:
+               path = USTCONSUMERD32_PATH;
+               break;
+       default:
+               ERR("Consumer type unknown");
+               ret = -EINVAL;
+               goto error;
        }
 
        ret = mkdir(path, S_IRWXU | S_IRWXG);
@@ -3858,6 +4198,8 @@ int main(int argc, char **argv)
                goto error;
        }
 
+       setup_consumerd_path();
+
        /* Parse arguments */
        progname = argv[0];
        if ((ret = parse_args(argc, argv) < 0)) {
@@ -3953,10 +4295,16 @@ int main(int argc, char **argv)
                        goto exit;
                }
 
-               ret = set_consumer_sockets(&ustconsumer_data);
+               ret = set_consumer_sockets(&ustconsumer64_data);
                if (ret < 0) {
                        goto exit;
                }
+
+               ret = set_consumer_sockets(&ustconsumer32_data);
+               if (ret < 0) {
+                       goto exit;
+               }
+
                /* Setup kernel tracer */
                init_kernel_tracer();
 
This page took 0.036559 seconds and 4 git commands to generate.