Fix: liblttng-ctl comm: lttng_channel is not packed
[lttng-tools.git] / src / bin / lttng-sessiond / client.cpp
index 154fa4a3633f585af655a7697edbb68e128f787d..46f524896ed2dd82e1a1ced94cff9092b937a8c2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
@@ -29,6 +29,7 @@
 #include <pthread.h>
 #include <signal.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
@@ -416,8 +417,6 @@ error:
  * Copy consumer output from the tracing session to the domain session. The
  * function also applies the right modification on a per domain basis for the
  * trace files destination directory.
- *
- * Should *NOT* be called with RCU read-side lock held.
  */
 static int copy_session_consumer(int domain, struct ltt_session *session)
 {
@@ -481,8 +480,6 @@ error:
 
 /*
  * Create an UST session and add it to the session ust list.
- *
- * Should *NOT* be called with RCU read-side lock held.
  */
 static int create_ust_session(struct ltt_session *session,
                const struct lttng_domain *domain)
@@ -919,8 +916,6 @@ end:
  * "sock" is only used for special-case var. len data.
  * A command may assume the ownership of the socket, in which case its value
  * should be set to -1.
- *
- * Should *NOT* be called with RCU read-side lock held.
  */
 static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
                int *sock_error)
@@ -934,8 +929,6 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
                lttcomm_sessiond_command_str((lttcomm_sessiond_command) cmd_ctx->lsm.cmd_type),
                cmd_ctx->lsm.cmd_type);
 
-       LTTNG_ASSERT(!rcu_read_ongoing());
-
        *sock_error = 0;
 
        switch (cmd_ctx->lsm.cmd_type) {
@@ -1440,14 +1433,8 @@ error_add_context:
        }
        case LTTNG_ENABLE_CHANNEL:
        {
-               cmd_ctx->lsm.u.channel.chan.attr.extended.ptr =
-                               (struct lttng_channel_extended *) &cmd_ctx->lsm.u.channel.extended;
-               lttng_domain domain = cmd_ctx->lsm.domain;
-               lttng_channel chan = cmd_ctx->lsm.u.channel.chan;
-               ret = cmd_enable_channel(cmd_ctx->session,
-                               &domain,
-                               &chan,
-                               the_kernel_poll_pipe[1]);
+               ret = cmd_enable_channel(
+                               cmd_ctx, *sock, the_kernel_poll_pipe[1]);
                break;
        }
        case LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE:
@@ -1970,25 +1957,30 @@ error_add_context:
        }
        case LTTNG_LIST_CHANNELS:
        {
-               ssize_t payload_size;
-               struct lttng_channel *channels = NULL;
+               enum lttng_error_code ret_code;
+               size_t original_payload_size;
+               size_t payload_size;
+               const size_t command_header_size = sizeof(struct lttcomm_list_command_header);
 
-               payload_size = cmd_list_channels(cmd_ctx->lsm.domain.type,
-                               cmd_ctx->session, &channels);
-               if (payload_size < 0) {
-                       /* Return value is a negative lttng_error_code. */
-                       ret = -payload_size;
-                       goto error;
+               ret = setup_empty_lttng_msg(cmd_ctx);
+               if (ret) {
+                       ret = LTTNG_ERR_NOMEM;
+                       goto setup_error;
                }
 
-               ret = setup_lttng_msg_no_cmd_header(cmd_ctx, channels,
-                       payload_size);
-               free(channels);
+               original_payload_size = cmd_ctx->reply_payload.buffer.size;
 
-               if (ret < 0) {
-                       goto setup_error;
+               ret_code = cmd_list_channels(cmd_ctx->lsm.domain.type,
+                               cmd_ctx->session, &cmd_ctx->reply_payload);
+               if (ret_code != LTTNG_OK) {
+                       ret = (int) ret_code;
+                       goto error;
                }
 
+               payload_size = cmd_ctx->reply_payload.buffer.size -
+                               command_header_size - original_payload_size;
+               update_lttng_msg(cmd_ctx, command_header_size, payload_size);
+
                ret = LTTNG_OK;
                break;
        }
This page took 0.025996 seconds and 4 git commands to generate.