Merge branch 'master' into benchmark
authorDavid Goulet <dgoulet@efficios.com>
Mon, 9 Jan 2012 21:35:12 +0000 (16:35 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 9 Jan 2012 21:35:12 +0000 (16:35 -0500)
Signed-off-by: David Goulet <dgoulet@efficios.com>
1  2 
Makefile.am
configure.ac
lttng-sessiond/Makefile.am
lttng-sessiond/main.c

diff --combined Makefile.am
index ae88bcaa0cadc5a541533cd7dbb27bdd8d3d76d1,3b6344fa6cc271517eeb24c52de6236cafb8777d..fa7f5ec565a6a4944f55ac413826d488307efdd8
@@@ -1,8 -1,9 +1,10 @@@
  ACLOCAL_AMFLAGS = -I config
  
 -SUBDIRS = common \
 +SUBDIRS = benchmark \
++                common \
                  liblttng-sessiond-comm \
                  libkernelctl \
+                 liblttng-ht \
                  liblttng-kconsumer \
                  liblttng-ustconsumer \
                  liblttng-consumer \
@@@ -17,6 -18,3 +19,6 @@@ endi
  SUBDIRS += tests \
             include \
             doc
 +
 +bench:
 +      ./benchmark/runall.sh
diff --combined configure.ac
index e4084aed308d7ab1b7ec341a8b5f9955be1ccaba,6bddf8783c61556ea368408f30115ee566167011..eb0b3a05a97a4ff8f4356f4f537819bd1796b80c
@@@ -1,4 -1,4 +1,4 @@@
- AC_INIT([lttng-tools],[2.0-pre14],[david.goulet@polymtl.ca],[],[http://lttng.org])
+ AC_INIT([lttng-tools],[2.0-pre16],[david.goulet@polymtl.ca],[],[http://lttng.org])
  AC_CONFIG_AUX_DIR([config])
  AC_CANONICAL_TARGET
  AC_CANONICAL_HOST
@@@ -57,13 -57,8 +57,13 @@@ AC_CHECK_LIB([popt], [poptGetContext], 
        [AC_MSG_ERROR([Cannot find libpopt. Use [LDFLAGS]=-Ldir to specify its location.])]
  )
  
 +# Needed for benchmark time
 +AC_CHECK_DECL([caa_get_cycles], [],
 +      [AC_MSG_ERROR([liburcu liburcu_version or newer is needed])], [[#include <urcu/arch.h>]]
 +)
 +
  # URCU library version needed or newer
- liburcu_version=">= 0.6.6"
+ liburcu_version=">= 0.6.7"
  
  # Check liburcu needed function calls
  AC_CHECK_DECL([cds_list_add], [],
@@@ -137,13 -132,14 +137,15 @@@ AC_SUBST(DEFAULT_INCLUDES
  AC_CONFIG_FILES([
        Makefile
        include/Makefile
 +      benchmark/Makefile
+       common/Makefile
        libkernelctl/Makefile
        liblttng-consumer/Makefile
        liblttng-kconsumer/Makefile
        liblttng-ustconsumer/Makefile
        liblttngctl/Makefile
        liblttng-sessiond-comm/Makefile
+       liblttng-ht/Makefile
        lttng-consumerd/Makefile
        lttng-sessiond/Makefile
        lttng/Makefile
index db621d8e38999fcee97c5e48ae5a9ad85a6506ce,8fcea947e2fcf20497a8965bfb1aea551bb27602..829f9abb03bf58012ec4b5bf87933effdc8b8c48
@@@ -1,4 -1,4 +1,4 @@@
 -AM_CPPFLAGS = -I$(top_srcdir)/include \
 +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/benchmark \
                          -DINSTALL_BIN_PATH=\""$(bindir)"\" \
                          -DINSTALL_LIB_PATH=\""$(libdir)"\"
  
@@@ -13,7 -13,6 +13,6 @@@ COMPAT=compat/compat-poll.
  endif
  
  lttng_sessiond_SOURCES = utils.c utils.h \
-                        hashtable.c hashtable.h \
                         compat/poll.h $(COMPAT) \
                         trace-kernel.c trace-kernel.h \
                         kernel.c kernel.h \
@@@ -24,9 -23,7 +23,7 @@@
                         futex.c futex.h \
                         shm.c shm.h \
                         session.c session.h \
-                        ../hashtable/rculfhash.c \
-                        ../hashtable/rculfhash.h \
-                        ../hashtable/hash.c ../hashtable/hash.h
+                        lttng-ust-ctl.h lttng-ust-abi.h
  
  if HAVE_LIBLTTNG_UST_CTL
  lttng_sessiond_SOURCES += trace-ust.c ust-app.c ust-consumer.c ust-consumer.h
@@@ -40,7 -37,8 +37,9 @@@ lttng_sessiond_LDADD = -lrt -lurcu-comm
                 $(top_builddir)/liblttng-sessiond-comm/liblttng-sessiond-comm.la \
                 $(top_builddir)/libkernelctl/libkernelctl.la \
                 $(top_builddir)/liblttngctl/liblttngctl.la \
-                $(top_builddir)/benchmark/liblttng-benchmark.la
++               $(top_builddir)/benchmark/liblttng-benchmark.la \
+                $(top_builddir)/common/libcommon.la \
+                $(top_builddir)/liblttng-ht/liblttng-ht.la
  
  if HAVE_LIBLTTNG_UST_CTL
  lttng_sessiond_LDADD += -llttng-ust-ctl
diff --combined lttng-sessiond/main.c
index d8f2125a4834066761d41cd6a0133ecfaddeb87c,91db9677abdfd24a6d781db11bd47951f95fbed9..6d6af18e23c35acd599226efb279ab9a71895d5d
  #include <config.h>
  
  #include <lttng-consumerd.h>
+ #include <lttng-ht.h>
  #include <lttng-sessiond-comm.h>
  #include <lttng/lttng-consumer.h>
  
  #include <lttngerr.h>
+ #include <runas.h>
  
  #include "channel.h"
  #include "compat/poll.h"
  #include "context.h"
  #include "event.h"
  #include "futex.h"
- #include "hashtable.h"
  #include "kernel.h"
  #include "lttng-sessiond.h"
  #include "shm.h"
@@@ -77,8 -78,6 +78,8 @@@ struct consumer_data 
        char cmd_unix_sock_path[PATH_MAX];
  };
  
 +#include "benchmark.h"
 +
  /* Const values */
  const char default_home_dir[] = DEFAULT_HOME_DIR;
  const char default_tracing_group[] = LTTNG_DEFAULT_TRACING_GROUP;
@@@ -94,6 -93,7 +95,7 @@@ const char *progname
  const char *opt_tracing_group;
  static int opt_sig_parent;
  static int opt_daemon;
+ static int opt_no_kernel;
  static int is_root;                   /* Set to 1 if the daemon is running as root */
  static pid_t ppid;          /* Parent PID for --sig-parent option */
  static char *rundir;
@@@ -459,10 -459,9 +461,9 @@@ static void cleanup(void
  
        pthread_mutex_destroy(&kconsumer_data.pid_mutex);
  
-       DBG("Closing kernel fd");
-       close(kernel_tracer_fd);
-       if (is_root) {
+       if (is_root && !opt_no_kernel) {
+               DBG2("Closing kernel fd");
+               close(kernel_tracer_fd);
                DBG("Unloading kernel modules");
                modprobe_remove_kernel_modules();
        }
        close(thread_quit_pipe[0]);
        close(thread_quit_pipe[1]);
  
 +      /* OUTPUT BENCHMARK RESULTS */
 +      bench_init();
 +
 +      if (getenv("BENCH_UST_NOTIFY")) {
 +              bench_print_ust_notification();
 +      }
 +
 +      if (getenv("BENCH_UST_REGISTER")) {
 +              bench_print_ust_register();
 +              bench_print_ust_unregister();
 +      }
 +
 +      if (getenv("BENCH_BOOT_PROCESS")) {
 +              bench_print_boot_process();
 +      }
 +
 +      bench_close();
 +      /* END BENCHMARK */
 +
        /* <fun> */
-       MSG("%c[%d;%dm*** assert failed :-) *** ==> %c[%dm%c[%d;%dm"
+       DBG("%c[%d;%dm*** assert failed :-) *** ==> %c[%dm%c[%d;%dm"
                        "Matthew, BEET driven development works!%c[%dm",
                        27, 1, 31, 27, 0, 27, 1, 33, 27, 0);
        /* </fun> */
@@@ -533,7 -513,8 +534,8 @@@ static void clean_command_ctx(struct co
   * Send all stream fds of kernel channel to the consumer.
   */
  static int send_kconsumer_channel_streams(struct consumer_data *consumer_data,
-               int sock, struct ltt_kernel_channel *channel)
+               int sock, struct ltt_kernel_channel *channel,
+               uid_t uid, gid_t gid)
  {
        int ret;
        struct ltt_kernel_stream *stream;
                lkm.u.stream.state = stream->state;
                lkm.u.stream.output = channel->channel->attr.output;
                lkm.u.stream.mmap_len = 0;      /* for kernel */
+               lkm.u.stream.uid = uid;
+               lkm.u.stream.gid = gid;
                strncpy(lkm.u.stream.path_name, stream->pathname, PATH_MAX - 1);
                lkm.u.stream.path_name[PATH_MAX - 1] = '\0';
                DBG("Sending stream %d to consumer", lkm.u.stream.stream_key);
@@@ -626,6 -609,8 +630,8 @@@ static int send_kconsumer_session_strea
                lkm.u.stream.state = LTTNG_CONSUMER_ACTIVE_STREAM;
                lkm.u.stream.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
                lkm.u.stream.mmap_len = 0;      /* for kernel */
+               lkm.u.stream.uid = session->uid;
+               lkm.u.stream.gid = session->gid;
                strncpy(lkm.u.stream.path_name, session->metadata->pathname, PATH_MAX - 1);
                lkm.u.stream.path_name[PATH_MAX - 1] = '\0';
                DBG("Sending metadata stream %d to consumer", lkm.u.stream.stream_key);
        }
  
        cds_list_for_each_entry(chan, &session->channel_list.head, list) {
-               ret = send_kconsumer_channel_streams(consumer_data, sock, chan);
+               ret = send_kconsumer_channel_streams(consumer_data, sock, chan,
+                               session->uid, session->gid);
                if (ret < 0) {
                        goto error;
                }
@@@ -665,8 -651,6 +672,8 @@@ static int notify_ust_apps(int active
  
        DBG("Notifying applications of session daemon state: %d", active);
  
 +      tracepoint(ust_notify_apps_start);
 +
        /* See shm.c for this call implying mmap, shm and futex calls */
        wait_shm_mmap = shm_ust_get_mmap(wait_shm_path, is_root);
        if (wait_shm_mmap == NULL) {
        /* Wake waiting process */
        futex_wait_update((int32_t *) wait_shm_mmap, active);
  
 +      tracepoint(ust_notify_apps_stop);
 +
        /* Apps notified successfully */
        return 0;
  
@@@ -802,7 -784,8 +809,8 @@@ static int update_kernel_stream(struct 
                                 */
                                if (session->kernel_session->consumer_fds_sent == 1) {
                                        ret = send_kconsumer_channel_streams(consumer_data,
-                                                       session->kernel_session->consumer_fd, channel);
+                                                       session->kernel_session->consumer_fd, channel,
+                                                       session->uid, session->gid);
                                        if (ret < 0) {
                                                goto error;
                                        }
@@@ -849,8 -832,6 +857,8 @@@ static void *thread_manage_kernel(void 
        char tmp;
        struct lttng_poll_event events;
  
 +      tracepoint(sessiond_th_kern_start);
 +
        DBG("Thread manage kernel started");
  
        ret = create_thread_poll_set(&events, 2);
                /* Zeroed the poll events */
                lttng_poll_reset(&events);
  
 +              tracepoint(sessiond_th_kern_poll);
 +
                /* Poll infinite value of time */
                ret = lttng_poll_wait(&events, -1);
                if (ret < 0) {
@@@ -955,8 -934,6 +963,8 @@@ static void *thread_manage_consumer(voi
        struct lttng_poll_event events;
        struct consumer_data *consumer_data = data;
  
 +      tracepoint(sessiond_th_kcon_start);
 +
        DBG("[thread] Manage consumer started");
  
        ret = lttcomm_listen_unix_sock(consumer_data->err_sock);
  
        nb_fd = LTTNG_POLL_GETNB(&events);
  
 +      tracepoint(sessiond_th_kcon_poll);
 +
        /* Inifinite blocking call, waiting for transmission */
        ret = lttng_poll_wait(&events, -1);
        if (ret < 0) {
@@@ -1114,8 -1089,6 +1122,8 @@@ static void *thread_manage_apps(void *d
        struct ust_command ust_cmd;
        struct lttng_poll_event events;
  
 +      tracepoint(sessiond_th_apps_start);
 +
        DBG("[thread] Manage application started");
  
        rcu_register_thread();
  
                DBG("Apps thread polling on %d fds", nb_fd);
  
 +              tracepoint(sessiond_th_apps_poll);
 +
                /* Inifinite blocking call, waiting for transmission */
                ret = lttng_poll_wait(&events, -1);
                if (ret < 0) {
                                        ERR("Apps command pipe error");
                                        goto error;
                                } else if (revents & LPOLLIN) {
 +                                      tracepoint(ust_register_read_start);
                                        /* Empty pipe */
                                        ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
                                        if (ret < 0 || ret < sizeof(ust_cmd)) {
                                                perror("read apps cmd pipe");
                                                goto error;
                                        }
 +                                      tracepoint(ust_register_read_stop);
  
 +                                      tracepoint(ust_register_add_start);
                                        /* Register applicaton to the session daemon */
                                        ret = ust_app_register(&ust_cmd.reg_msg,
                                                        ust_cmd.sock);
                                        } else if (ret < 0) {
                                                break;
                                        }
 +                                      tracepoint(ust_register_add_stop);
  
 +                                      tracepoint(ust_register_done_start);
                                        /*
                                         * Add channel(s) and event(s) to newly registered apps
                                         * from lttng global UST domain.
                                         */
                                        update_ust_app(ust_cmd.sock);
  
-                                       ret = ustctl_register_done(ust_cmd.sock);
+                                       ret = ust_app_register_done(ust_cmd.sock);
                                        if (ret < 0) {
                                                /*
                                                 * If the registration is not possible, we simply
                                                DBG("Apps with sock %d added to poll set",
                                                                ust_cmd.sock);
                                        }
 -
 +                                      tracepoint(ust_register_done_stop);
                                        break;
                                }
                        } else {
                                 * the event at poll_wait.
                                 */
                                if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
 +                                      tracepoint(ust_unregister_start);
 +
                                        /* Removing from the poll set */
                                        ret = lttng_poll_del(&events, pollfd);
                                        if (ret < 0) {
  
                                        /* Socket closed on remote end. */
                                        ust_app_unregister(pollfd);
 +
 +                                      tracepoint(ust_unregister_stop);
                                        break;
                                }
                        }
@@@ -1260,8 -1222,6 +1268,8 @@@ static void *thread_dispatch_ust_regist
        struct cds_wfq_node *node;
        struct ust_command *ust_cmd = NULL;
  
 +      tracepoint(sessiond_th_dispatch_start);
 +
        DBG("[thread] Dispatch UST command started");
  
        while (!dispatch_thread_exit) {
                futex_nto1_prepare(&ust_cmd_queue.futex);
  
                do {
 +                      tracepoint(sessiond_th_dispatch_block);
 +
                        /* Dequeue command for registration */
                        node = cds_wfq_dequeue_blocking(&ust_cmd_queue.queue);
                        if (node == NULL) {
                                break;
                        }
  
 +                      tracepoint(ust_dispatch_register_start);
 +
                        ust_cmd = caa_container_of(node, struct ust_command, node);
  
                        DBG("Dispatching UST registration pid:%d ppid:%d uid:%d"
                        free(ust_cmd);
                } while (node != NULL);
  
 +              tracepoint(ust_dispatch_register_stop);
 +
                /* Futex wait on queue. Blocking call on futex() */
                futex_nto1_wait(&ust_cmd_queue.futex);
        }
@@@ -1336,8 -1290,6 +1344,8 @@@ static void *thread_registration_apps(v
         */
        struct ust_command *ust_cmd = NULL;
  
 +      tracepoint(sessiond_th_reg_start);
 +
        DBG("[thread] Manage application registration started");
  
        ret = lttcomm_listen_unix_sock(apps_sock);
        while (1) {
                DBG("Accepting application registration");
  
 +              tracepoint(sessiond_th_reg_poll);
 +
                nb_fd = LTTNG_POLL_GETNB(&events);
  
                /* Inifinite blocking call, waiting for transmission */
                                        ERR("Register apps socket poll error");
                                        goto error;
                                } else if (revents & LPOLLIN) {
 +                                      /* Registration starts here. Recording cycles */
 +                                      tracepoint(ust_register_start);
 +
                                        sock = lttcomm_accept_unix_sock(apps_sock);
                                        if (sock < 0) {
                                                goto error;
                                         * barrier with the exchange in cds_wfq_enqueue.
                                         */
                                        futex_nto1_wake(&ust_cmd_queue.futex);
 +
 +                                      tracepoint(ust_register_stop);
                                }
                        }
                }
@@@ -1643,7 -1588,7 +1651,7 @@@ static pid_t spawn_consumerd(struct con
                                }
                        }
                        DBG("Using 64-bit UST consumer at: %s",  consumerd64_bin);
-                       ret = execl(consumerd64_bin, verbosity, "-u",
+                       ret = execl(consumerd64_bin, "lttng-consumerd", verbosity, "-u",
                                        "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        NULL);
                                }
                        }
                        DBG("Using 32-bit UST consumer at: %s",  consumerd32_bin);
-                       ret = execl(consumerd32_bin, verbosity, "-u",
+                       ret = execl(consumerd32_bin, "lttng-consumerd", verbosity, "-u",
                                        "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        NULL);
@@@ -1800,7 -1745,7 +1808,7 @@@ static int mount_debugfs(char *path
        int ret;
        char *type = "debugfs";
  
-       ret = mkdir_recursive(path, S_IRWXU | S_IRWXG, geteuid(), getegid());
+       ret = mkdir_recursive_run_as(path, S_IRWXU | S_IRWXG, geteuid(), getegid());
        if (ret < 0) {
                PERROR("Cannot create debugfs path");
                goto error;
@@@ -1936,9 -1881,8 +1944,8 @@@ error
  static int create_ust_session(struct ltt_session *session,
                struct lttng_domain *domain)
  {
-       int ret;
-       unsigned int uid;
        struct ltt_ust_session *lus = NULL;
+       int ret;
  
        switch (domain->type) {
        case LTTNG_DOMAIN_UST:
  
        DBG("Creating UST session");
  
-       uid = session->uid;
-       lus = trace_ust_create_session(session->path, uid, domain);
+       lus = trace_ust_create_session(session->path, session->id, domain);
        if (lus == NULL) {
                ret = LTTCOMM_UST_SESS_FAIL;
                goto error;
        }
  
-       ret = mkdir_recursive(lus->pathname, S_IRWXU | S_IRWXG,
-                       geteuid(), allowed_group());
+       ret = mkdir_recursive_run_as(lus->pathname, S_IRWXU | S_IRWXG,
+                       session->uid, session->gid);
        if (ret < 0) {
                if (ret != -EEXIST) {
                        ERR("Trace directory creation error");
                ERR("Unknown UST domain on create session %d", domain->type);
                goto error;
        }
+       lus->uid = session->uid;
+       lus->gid = session->gid;
        session->ust_session = lus;
  
        return LTTCOMM_OK;
@@@ -2005,19 -1950,55 +2013,55 @@@ static int create_kernel_session(struc
                session->kernel_session->consumer_fd = kconsumer_data.cmd_sock;
        }
  
-       ret = mkdir_recursive(session->kernel_session->trace_path,
-                       S_IRWXU | S_IRWXG, geteuid(), allowed_group());
+       ret = mkdir_recursive_run_as(session->kernel_session->trace_path,
+                       S_IRWXU | S_IRWXG, session->uid, session->gid);
        if (ret < 0) {
                if (ret != -EEXIST) {
                        ERR("Trace directory creation error");
                        goto error;
                }
        }
+       session->kernel_session->uid = session->uid;
+       session->kernel_session->gid = session->gid;
  
  error:
        return ret;
  }
  
+ /*
+  * Check if the UID or GID match the session. Root user has access to
+  * all sessions.
+  */
+ static int session_access_ok(struct ltt_session *session,
+        uid_t uid, gid_t gid)
+ {
+       if (uid != session->uid && gid != session->gid
+                       && uid != 0) {
+               return 0;
+       } else {
+               return 1;
+       }
+ }
+ static unsigned int lttng_sessions_count(uid_t uid, gid_t gid)
+ {
+       unsigned int i = 0;
+       struct ltt_session *session;
+       DBG("Counting number of available session for UID %d GID %d",
+               uid, gid);
+       cds_list_for_each_entry(session, &session_list_ptr->head, list) {
+               /*
+                * Only list the sessions the user can control.
+                */
+               if (!session_access_ok(session, uid, gid)) {
+                       continue;
+               }
+               i++;
+       }
+       return i;
+ }
  /*
   * Using the session list, filled a lttng_session array to send back to the
   * client for session listing.
   * The session list lock MUST be acquired before calling this function. Use
   * session_lock_list() and session_unlock_list().
   */
- static void list_lttng_sessions(struct lttng_session *sessions)
+ static void list_lttng_sessions(struct lttng_session *sessions,
+               uid_t uid, gid_t gid)
  {
-       int i = 0;
+       unsigned int i = 0;
        struct ltt_session *session;
  
-       DBG("Getting all available session");
+       DBG("Getting all available session for UID %d GID %d",
+               uid, gid);
        /*
         * Iterate over session list and append data after the control struct in
         * the buffer.
         */
        cds_list_for_each_entry(session, &session_list_ptr->head, list) {
+               /*
+                * Only list the sessions the user can control.
+                */
+               if (!session_access_ok(session, uid, gid)) {
+                       continue;
+               }
                strncpy(sessions[i].path, session->path, PATH_MAX);
                sessions[i].path[PATH_MAX - 1] = '\0';
                strncpy(sessions[i].name, session->name, NAME_MAX);
@@@ -2071,11 -2060,11 +2123,11 @@@ static void list_lttng_channels(int dom
                break;
        case LTTNG_DOMAIN_UST:
        {
-               struct cds_lfht_iter iter;
+               struct lttng_ht_iter iter;
                struct ltt_ust_channel *uchan;
  
-               cds_lfht_for_each_entry(session->ust_session->domain_global.channels,
-                               &iter, uchan, node) {
+               cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
+                               &iter.iter, uchan, node.node) {
                        strncpy(channels[i].name, uchan->name, LTTNG_SYMBOL_NAME_LEN);
                        channels[i].attr.overwrite = uchan->attr.overwrite;
                        channels[i].attr.subbuf_size = uchan->attr.subbuf_size;
@@@ -2108,8 -2097,8 +2160,8 @@@ static int list_lttng_ust_global_events
  {
        int i = 0, ret = 0;
        unsigned int nb_event = 0;
-       struct cds_lfht_iter iter;
-       struct cds_lfht_node *node;
+       struct lttng_ht_iter iter;
+       struct lttng_ht_node_str *node;
        struct ltt_ust_channel *uchan;
        struct ltt_ust_event *uevent;
        struct lttng_event *tmp;
  
        rcu_read_lock();
  
-       node = hashtable_lookup(ust_global->channels, (void *) channel_name,
-                       strlen(channel_name), &iter);
+       lttng_ht_lookup(ust_global->channels, (void *)channel_name, &iter);
+       node = lttng_ht_iter_get_node_str(&iter);
        if (node == NULL) {
                ret = -LTTCOMM_UST_CHAN_NOT_FOUND;
                goto error;
        }
  
-       uchan = caa_container_of(node, struct ltt_ust_channel, node);
+       uchan = caa_container_of(&node->node, struct ltt_ust_channel, node.node);
  
-       nb_event += hashtable_get_count(uchan->events);
+       nb_event += lttng_ht_get_count(uchan->events);
  
        if (nb_event == 0) {
                ret = nb_event;
                goto error;
        }
  
-       cds_lfht_for_each_entry(uchan->events, &iter, uevent, node) {
+       cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.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;
@@@ -2268,7 -2257,7 +2320,7 @@@ static int cmd_disable_channel(struct l
        case LTTNG_DOMAIN_UST:
        {
                struct ltt_ust_channel *uchan;
-               struct cds_lfht *chan_ht;
+               struct lttng_ht *chan_ht;
  
                chan_ht = usess->domain_global.channels;
  
@@@ -2308,7 -2297,7 +2360,7 @@@ static int cmd_enable_channel(struct lt
  {
        int ret;
        struct ltt_ust_session *usess = session->ust_session;
-       struct cds_lfht *chan_ht;
+       struct lttng_ht *chan_ht;
  
        DBG("Enabling channel %s for session %s", attr->name, session->name);
  
@@@ -2631,7 -2620,6 +2683,6 @@@ static int cmd_enable_event(struct ltt_
                }
  
                /* At this point, the session and channel exist on the tracer */
                ret = event_ust_enable_tracepoint(usess, domain, uchan, event);
                if (ret != LTTCOMM_OK) {
                        goto error;
@@@ -2835,8 -2823,11 +2886,11 @@@ static int cmd_start_trace(struct ltt_s
        ksession = session->kernel_session;
        usess = session->ust_session;
  
-       if (session->enabled)
-               return LTTCOMM_UST_START_FAIL;
+       if (session->enabled) {
+               ret = LTTCOMM_UST_START_FAIL;
+               goto error;
+       }
        session->enabled = 1;
  
        /* Kernel tracing */
@@@ -2924,8 -2915,11 +2978,11 @@@ static int cmd_stop_trace(struct ltt_se
        ksession = session->kernel_session;
        usess = session->ust_session;
  
-       if (!session->enabled)
-               return LTTCOMM_UST_START_FAIL;
+       if (!session->enabled) {
+               ret = LTTCOMM_UST_START_FAIL;
+               goto error;
+       }
        session->enabled = 0;
  
        /* Kernel tracer */
@@@ -2973,11 -2967,11 +3030,11 @@@ error
  /*
   * Command LTTNG_CREATE_SESSION processed by the client thread.
   */
- static int cmd_create_session(char *name, char *path)
+ static int cmd_create_session(char *name, char *path, struct ucred *creds)
  {
        int ret;
  
-       ret = session_create(name, path);
+       ret = session_create(name, path, creds->uid, creds->gid);
        if (ret != LTTCOMM_OK) {
                goto error;
        }
@@@ -3057,7 -3051,7 +3114,7 @@@ static int cmd_register_consumer(struc
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
                /* Can't register a consumer if there is already one */
-               if (session->kernel_session->consumer_fd != 0) {
+               if (session->kernel_session->consumer_fds_sent != 0) {
                        ret = LTTCOMM_KERN_CONSUMER_FAIL;
                        goto error;
                }
@@@ -3141,7 -3135,7 +3198,7 @@@ static ssize_t cmd_list_channels(int do
                break;
        case LTTNG_DOMAIN_UST:
                if (session->ust_session != NULL) {
-                       nb_chan = hashtable_get_count(
+                       nb_chan = lttng_ht_get_count(
                                        session->ust_session->domain_global.channels);
                }
                DBG3("Number of UST global channels %zd", nb_chan);
@@@ -3219,6 -3213,11 +3276,11 @@@ static int process_client_msg(struct co
  
        DBG("Processing client command %d", cmd_ctx->lsm->cmd_type);
  
+       if (opt_no_kernel && cmd_ctx->lsm->domain.type == LTTNG_DOMAIN_KERNEL) {
+               ret = LTTCOMM_KERN_NA;
+               goto error;
+       }
        /*
         * Check for command that don't needs to allocate a returned payload. We do
         * this here so we don't have to make the call for no payload at each
                break;
        }
  
+       /*
+        * Check that the UID or GID match that of the tracing session.
+        * The root user can interact with all sessions.
+        */
+       if (need_tracing_session) {
+               if (!session_access_ok(cmd_ctx->session,
+                               cmd_ctx->creds.uid, cmd_ctx->creds.gid)) {
+                       ret = LTTCOMM_EPERM;
+                       goto error;
+               }
+       }
        /* Process by command type */
        switch (cmd_ctx->lsm->cmd_type) {
        case LTTNG_ADD_CONTEXT:
        }
        case LTTNG_CREATE_SESSION:
        {
 +              tracepoint(create_session_start);
                ret = cmd_create_session(cmd_ctx->lsm->session.name,
-                               cmd_ctx->lsm->session.path);
+                               cmd_ctx->lsm->session.path, &cmd_ctx->creds);
 +              tracepoint(create_session_end);
                break;
        }
        case LTTNG_DESTROY_SESSION:
        {
 +              tracepoint(destroy_session_start);
                ret = cmd_destroy_session(cmd_ctx->session,
                                cmd_ctx->lsm->session.name);
 +              tracepoint(destroy_session_end);
                break;
        }
        case LTTNG_LIST_DOMAINS:
        }
        case LTTNG_LIST_SESSIONS:
        {
-               session_lock_list();
+               unsigned int nr_sessions;
  
-               if (session_list_ptr->count == 0) {
+               session_lock_list();
+               nr_sessions = lttng_sessions_count(cmd_ctx->creds.uid, cmd_ctx->creds.gid);
+               if (nr_sessions == 0) {
                        ret = LTTCOMM_NO_SESSION;
                        session_unlock_list();
                        goto error;
                }
-               ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_session) *
-                               session_list_ptr->count);
+               ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_session) * nr_sessions);
                if (ret < 0) {
                        session_unlock_list();
                        goto setup_error;
                }
  
                /* Filled the session array */
-               list_lttng_sessions((struct lttng_session *)(cmd_ctx->llm->payload));
+               list_lttng_sessions((struct lttng_session *)(cmd_ctx->llm->payload),
+                       cmd_ctx->creds.uid, cmd_ctx->creds.gid);
  
                session_unlock_list();
  
@@@ -3615,8 -3623,6 +3690,8 @@@ static void *thread_manage_clients(voi
        struct command_ctx *cmd_ctx = NULL;
        struct lttng_poll_event events;
  
 +      tracepoint(sessiond_th_cli_start);
 +
        DBG("[thread] Manage client started");
  
        rcu_register_thread();
        while (1) {
                DBG("Accepting client command ...");
  
 +              tracepoint(sessiond_th_cli_poll);
 +
                nb_fd = LTTNG_POLL_GETNB(&events);
  
                /* Inifinite blocking call, waiting for transmission */
                        goto error;
                }
  
+               /* Set socket option for credentials retrieval */
+               ret = lttcomm_setsockopt_creds_unix_sock(sock);
+               if (ret < 0) {
+                       goto error;
+               }
                /* Allocate context command to process the client request */
                cmd_ctx = zmalloc(sizeof(struct command_ctx));
                if (cmd_ctx == NULL) {
                 * the client.
                 */
                DBG("Receiving data from client ...");
-               ret = lttcomm_recv_unix_sock(sock, cmd_ctx->lsm,
-                               sizeof(struct lttcomm_session_msg));
+               ret = lttcomm_recv_creds_unix_sock(sock, cmd_ctx->lsm,
+                               sizeof(struct lttcomm_session_msg), &cmd_ctx->creds);
                if (ret <= 0) {
                        DBG("Nothing recv() from client... continuing");
                        close(sock);
                        ERR("Failed to send data back to client");
                }
  
-               clean_command_ctx(&cmd_ctx);
                /* End of transmission */
                close(sock);
+               clean_command_ctx(&cmd_ctx);
        }
  
  error:
@@@ -3796,6 -3806,7 +3877,7 @@@ static void usage(void
        fprintf(stderr, "  -q, --quiet                        No output at all.\n");
        fprintf(stderr, "  -v, --verbose                      Verbose mode. Activate DBG() macro.\n");
        fprintf(stderr, "      --verbose-consumer             Verbose mode for consumer. Activate DBG() macro.\n");
+       fprintf(stderr, "      --no-kernel                    Disable kernel tracer\n");
  }
  
  /*
@@@ -3826,12 -3837,13 +3908,13 @@@ static int parse_args(int argc, char **
                { "quiet", 0, 0, 'q' },
                { "verbose", 0, 0, 'v' },
                { "verbose-consumer", 0, 0, 'Z' },
+               { "no-kernel", 0, 0, 'N' },
                { NULL, 0, 0, 0 }
        };
  
        while (1) {
                int option_index = 0;
-               c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:C:E:D:F:Z:u:t",
+               c = getopt_long(argc, argv, "dhqvVSN" "a:c:g:s:C:E:D:F:Z:u:t",
                                long_options, &option_index);
                if (c == -1) {
                        break;
                case 'G':
                        snprintf(ustconsumer32_data.cmd_unix_sock_path, PATH_MAX, "%s", optarg);
                        break;
+               case 'N':
+                       opt_no_kernel = 1;
+                       break;
                case 'q':
                        opt_quiet = 1;
                        break;
@@@ -3990,27 -4005,22 +4076,22 @@@ static int check_existing_daemon(void
   * Race window between mkdir and chown is OK because we are going from more
   * permissive (root.root) to les permissive (root.tracing).
   */
- static int set_permissions(void)
+ static int set_permissions(char *rundir)
  {
        int ret;
        gid_t gid;
  
        gid = allowed_group();
        if (gid < 0) {
-               if (is_root) {
-                       WARN("No tracing group detected");
-                       ret = 0;
-               } else {
-                       ERR("Missing tracing group. Aborting execution.");
-                       ret = -1;
-               }
+               WARN("No tracing group detected");
+               ret = 0;
                goto end;
        }
  
        /* Set lttng run dir */
-       ret = chown(LTTNG_RUNDIR, 0, gid);
+       ret = chown(rundir, 0, gid);
        if (ret < 0) {
-               ERR("Unable to set group on " LTTNG_RUNDIR);
+               ERR("Unable to set group on %s", rundir);
                perror("chown");
        }
  
@@@ -4237,7 -4247,6 +4318,7 @@@ int main(int argc, char **argv
        void *status;
        const char *home_path;
  
 +      tracepoint(sessiond_boot_start);
        rcu_register_thread();
  
        /* Create thread quit pipe */
                }
  
                /* Setup kernel tracer */
-               init_kernel_tracer();
+               if (!opt_no_kernel) {
+                       init_kernel_tracer();
+               }
  
                /* Set ulimit for open files */
                set_ulimit();
        }
  
        /* Set credentials to socket */
-       if (is_root && ((ret = set_permissions()) < 0)) {
+       if (is_root && ((ret = set_permissions(rundir)) < 0)) {
                goto exit;
        }
  
                goto exit_kernel;
        }
  
 +      tracepoint(sessiond_boot_end);
 +
        ret = pthread_join(kernel_thread, &status);
        if (ret != 0) {
                perror("pthread_join");
This page took 0.049365 seconds and 4 git commands to generate.