Fix: add missing rcu read side lock
[lttng-tools.git] / src / bin / lttng-sessiond / trace-kernel.c
index c1104fac2cc903f53f9d387d8981778cbbc3b780..f38cf3d8d0a6f96a48250cafd58b96a8f53feb36 100644 (file)
@@ -85,14 +85,13 @@ error:
  */
 struct ltt_kernel_session *trace_kernel_create_session(char *path)
 {
-       int ret;
-       struct ltt_kernel_session *lks;
+       struct ltt_kernel_session *lks = NULL;
 
        /* Allocate a new ltt kernel session */
        lks = zmalloc(sizeof(struct ltt_kernel_session));
        if (lks == NULL) {
                PERROR("create kernel session zmalloc");
-               goto error;
+               goto alloc_error;
        }
 
        /* Init data structure */
@@ -101,10 +100,8 @@ struct ltt_kernel_session *trace_kernel_create_session(char *path)
        lks->channel_count = 0;
        lks->stream_count_global = 0;
        lks->metadata = NULL;
-       lks->consumer_fd = -1;
        CDS_INIT_LIST_HEAD(&lks->channel_list.head);
 
-       /* Create default consumer output object */
        lks->consumer = consumer_create_output(CONSUMER_DST_LOCAL);
        if (lks->consumer == NULL) {
                goto error;
@@ -118,23 +115,31 @@ struct ltt_kernel_session *trace_kernel_create_session(char *path)
         */
        lks->tmp_consumer = NULL;
 
-       /* Use the default consumer output which is the tracing session path. */
-       ret = snprintf(lks->consumer->dst.trace_path, PATH_MAX, "%s/kernel", path);
-       if (ret < 0) {
-               PERROR("snprintf consumer trace path");
-               goto error;
-       }
+       if (path && strlen(path) > 0) {
+               int ret;
 
-       /* Set session path */
-       ret = asprintf(&lks->trace_path, "%s/kernel", path);
-       if (ret < 0) {
-               PERROR("asprintf kernel traces path");
-               goto error;
+               /* Use the default consumer output which is the tracing session path. */
+               ret = snprintf(lks->consumer->dst.trace_path, PATH_MAX,
+                               "%s" DEFAULT_KERNEL_TRACE_DIR, path);
+               if (ret < 0) {
+                       PERROR("snprintf consumer trace path");
+                       goto error;
+               }
+
+               /* Set session path */
+               ret = asprintf(&lks->trace_path, "%s" DEFAULT_KERNEL_TRACE_DIR, path);
+               if (ret < 0) {
+                       PERROR("asprintf kernel traces path");
+                       goto error;
+               }
        }
 
        return lks;
 
 error:
+       free(lks);
+
+alloc_error:
        return NULL;
 }
 
@@ -239,7 +244,6 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev)
        lke->fd = -1;
        lke->event = attr;
        lke->enabled = 1;
-       lke->ctx = NULL;
 
        return lke;
 
@@ -254,7 +258,7 @@ error:
  *
  * Return pointer to structure or NULL.
  */
-struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path)
+struct ltt_kernel_metadata *trace_kernel_create_metadata(void)
 {
        struct ltt_kernel_metadata *lkm;
        struct lttng_channel *chan;
@@ -268,7 +272,7 @@ struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path)
 
        /* Set default attributes */
        chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
-       chan->attr.subbuf_size = DEFAULT_METADATA_SUBBUF_SIZE;
+       chan->attr.subbuf_size = default_get_metadata_subbuf_size();
        chan->attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM;
        chan->attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
        chan->attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
@@ -327,11 +331,11 @@ error:
  */
 void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream)
 {
-       int ret;
-
        DBG("[trace] Closing stream fd %d", stream->fd);
        /* Close kernel fd */
        if (stream->fd >= 0) {
+               int ret;
+
                ret = close(stream->fd);
                if (ret) {
                        PERROR("close");
@@ -348,9 +352,9 @@ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream)
  */
 void trace_kernel_destroy_event(struct ltt_kernel_event *event)
 {
-       int ret;
-
        if (event->fd >= 0) {
+               int ret;
+
                DBG("[trace] Closing event fd %d", event->fd);
                /* Close kernel fd */
                ret = close(event->fd);
@@ -365,7 +369,6 @@ void trace_kernel_destroy_event(struct ltt_kernel_event *event)
        cds_list_del(&event->list);
 
        free(event->event);
-       free(event->ctx);
        free(event);
 }
 
@@ -410,11 +413,11 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel)
  */
 void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata)
 {
-       int ret;
-
        DBG("[trace] Closing metadata fd %d", metadata->fd);
        /* Close kernel fd */
        if (metadata->fd >= 0) {
+               int ret;
+
                ret = close(metadata->fd);
                if (ret) {
                        PERROR("close");
This page took 0.024884 seconds and 4 git commands to generate.