Prepare for '-Wunused-parameter'
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.cpp
index 7539302428f668ff2af59ff26b0c99118d7e1efe..0da8f6ad100eef2217254382c9c7e1651aa339eb 100644 (file)
@@ -911,13 +911,15 @@ int lttng_stop_tracing_no_wait(const char *session_name)
  * Returns the size of the returned payload data or a negative error code.
  */
 int lttng_add_context(struct lttng_handle *handle,
-               struct lttng_event_context *ctx, const char *event_name,
+               struct lttng_event_context *ctx,
+               const char *event_name __attribute__((unused)),
                const char *channel_name)
 {
        int ret;
-       size_t len = 0;
-       char *buf = NULL;
-       struct lttcomm_session_msg lsm;
+       struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_ADD_CONTEXT };
+       struct lttng_payload payload;
+
+       lttng_payload_init(&payload);
 
        /* Safety check. Both are mandatory. */
        if (handle == NULL || ctx == NULL) {
@@ -925,8 +927,11 @@ int lttng_add_context(struct lttng_handle *handle,
                goto end;
        }
 
-       memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_ADD_CONTEXT;
+       ret = lttng_dynamic_buffer_set_size(&payload.buffer, sizeof(lsm));
+       if (ret) {
+               ret = -LTTNG_ERR_NOMEM;
+               goto end;
+       }
 
        /* If no channel name, send empty string. */
        ret = lttng_strncpy(lsm.u.context.channel_name, channel_name ?: "",
@@ -944,55 +949,33 @@ int lttng_add_context(struct lttng_handle *handle,
                goto end;
        }
 
-       if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
-               size_t provider_len, ctx_len;
-               const char *provider_name = ctx->u.app_ctx.provider_name;
-               const char *ctx_name = ctx->u.app_ctx.ctx_name;
+       ret = lttng_event_context_serialize(ctx, &payload);
+       if (ret) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
 
-               if (!provider_name || !ctx_name) {
-                       ret = -LTTNG_ERR_INVALID;
-                       goto end;
-               }
+       lsm.u.context.length = payload.buffer.size - sizeof(lsm);
 
-               provider_len = strlen(provider_name);
-               if (provider_len == 0) {
-                       ret = -LTTNG_ERR_INVALID;
-                       goto end;
-               }
-               lsm.u.context.provider_name_len = provider_len;
+       /* Update message header. */
+       memcpy(payload.buffer.data, &lsm, sizeof(lsm));
 
-               ctx_len = strlen(ctx_name);
-               if (ctx_len == 0) {
-                       ret = -LTTNG_ERR_INVALID;
-                       goto end;
-               }
-               lsm.u.context.context_name_len = ctx_len;
-
-               len = provider_len + ctx_len;
-               buf = (char *) zmalloc(len);
-               if (!buf) {
-                       ret = -LTTNG_ERR_NOMEM;
+       {
+               struct lttng_payload reply;
+               struct lttng_payload_view payload_view =
+                               lttng_payload_view_from_payload(&payload, 0,
+                               -1);
+
+               lttng_payload_init(&reply);
+               ret = lttng_ctl_ask_sessiond_payload(&payload_view, &reply);
+               lttng_payload_reset(&reply);
+               if (ret) {
                        goto end;
                }
-
-               memcpy(buf, provider_name, provider_len);
-               memcpy(buf + provider_len, ctx_name, ctx_len);
        }
-       memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
 
-       if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
-               /*
-                * Don't leak application addresses to the sessiond.
-                * This is only necessary when ctx is for an app ctx otherwise
-                * the values inside the union (type & config) are overwritten.
-                */
-               lsm.u.context.ctx.u.app_ctx.provider_name = NULL;
-               lsm.u.context.ctx.u.app_ctx.ctx_name = NULL;
-       }
-
-       ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buf, len, NULL);
 end:
-       free(buf);
+       lttng_payload_reset(&payload);
        return ret;
 }
 
@@ -1733,23 +1716,74 @@ end:
 int lttng_list_tracepoint_fields(struct lttng_handle *handle,
                struct lttng_event_field **fields)
 {
+       enum lttng_error_code ret_code;
        int ret;
        struct lttcomm_session_msg lsm;
+       const struct lttcomm_list_command_header *cmd_header = NULL;
+       unsigned int nb_event_fields = 0;
+       struct lttng_payload reply;
 
        if (handle == NULL) {
-               return -LTTNG_ERR_INVALID;
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
        }
 
+       lttng_payload_init(&reply);
+
        memset(&lsm, 0, sizeof(lsm));
        lsm.cmd_type = LTTNG_LIST_TRACEPOINT_FIELDS;
        COPY_DOMAIN_PACKED(lsm.domain, handle->domain);
 
-       ret = lttng_ctl_ask_sessiond(&lsm, (void **) fields);
-       if (ret < 0) {
-               return ret;
+       {
+               lttng_payload_view message_view =
+                               lttng_payload_view_init_from_buffer(
+                                       (const char *) &lsm, 0,
+                                       sizeof(lsm));
+
+               ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
+               if (ret < 0) {
+                       goto end;
+               }
        }
 
-       return ret / sizeof(struct lttng_event_field);
+       {
+               const lttng_buffer_view cmd_header_view =
+                               lttng_buffer_view_from_dynamic_buffer(
+                                       &reply.buffer, 0, sizeof(*cmd_header));
+
+               if (!lttng_buffer_view_is_valid(&cmd_header_view)) {
+                       ret = -LTTNG_ERR_INVALID_PROTOCOL;
+                       goto end;
+               }
+
+               cmd_header = (struct lttcomm_list_command_header *)
+                               cmd_header_view.data;
+       }
+
+       if (cmd_header->count > INT_MAX) {
+               ret = -LTTNG_ERR_OVERFLOW;
+               goto end;
+       }
+
+       nb_event_fields = cmd_header->count;
+
+       {
+               lttng_payload_view reply_view =
+                               lttng_payload_view_from_payload(&reply,
+                               sizeof(*cmd_header), -1);
+
+               ret_code = lttng_event_fields_create_and_flatten_from_payload(
+                               &reply_view, nb_event_fields, fields);
+               if (ret_code != LTTNG_OK) {
+                       ret = -ret_code;
+                       goto end;
+               }
+       }
+
+       ret = nb_event_fields;
+
+end:
+       return ret;
 }
 
 /*
@@ -2383,14 +2417,14 @@ int lttng_list_events(struct lttng_handle *handle,
                                (const char *) &lsm, 0, sizeof(lsm));
        unsigned int nb_events = 0;
 
+       lttng_payload_init(&reply);
+
        /* Safety check. An handle and channel name are mandatory. */
        if (handle == NULL || channel_name == NULL) {
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
 
-       lttng_payload_init(&reply);
-
        /* Initialize command parameters. */
        lsm.cmd_type = LTTNG_LIST_EVENTS;
        ret = lttng_strncpy(lsm.session.name, handle->session_name,
@@ -2487,8 +2521,8 @@ end:
        return ret;
 }
 
-int lttng_calibrate(struct lttng_handle *handle,
-               struct lttng_calibrate *calibrate)
+int lttng_calibrate(struct lttng_handle *handle __attribute__((unused)),
+               struct lttng_calibrate *calibrate __attribute__((unused)))
 {
        /*
         * This command was removed in LTTng 2.9.
@@ -2794,7 +2828,7 @@ error:
  */
 extern "C"
 LTTNG_EXPORT int lttng_enable_consumer(struct lttng_handle *handle);
-int lttng_enable_consumer(struct lttng_handle *handle)
+int lttng_enable_consumer(struct lttng_handle *handle __attribute__((unused)))
 {
        return -ENOSYS;
 }
@@ -2804,7 +2838,7 @@ int lttng_enable_consumer(struct lttng_handle *handle)
  */
 extern "C"
 LTTNG_EXPORT int lttng_disable_consumer(struct lttng_handle *handle);
-int lttng_disable_consumer(struct lttng_handle *handle)
+int lttng_disable_consumer(struct lttng_handle *handle __attribute__((unused)))
 {
        return -ENOSYS;
 }
@@ -2815,8 +2849,9 @@ int lttng_disable_consumer(struct lttng_handle *handle)
 extern "C"
 LTTNG_EXPORT int _lttng_create_session_ext(const char *name, const char *url,
                const char *datetime);
-int _lttng_create_session_ext(const char *name, const char *url,
-               const char *datetime)
+int _lttng_create_session_ext(const char *name __attribute__((unused)),
+               const char *url __attribute__((unused)),
+               const char *datetime __attribute__((unused)))
 {
        return -ENOSYS;
 }
This page took 0.026021 seconds and 4 git commands to generate.