goto end;
}
+ /* Receive fds, if any. */
+ if (cmd_ctx->lsm.fd_count > 0) {
+ ret = lttcomm_recv_payload_fds_unix_sock(
+ sock, cmd_ctx->lsm.fd_count, &trigger_payload);
+ if (ret > 0 && ret != cmd_ctx->lsm.fd_count * sizeof(int)) {
+ ret = LTTNG_ERR_INVALID_PROTOCOL;
+ goto end;
+ } else if (ret <= 0) {
+ ret = LTTNG_ERR_FATAL;
+ goto end;
+ }
+ }
+
+ /* Deserialize trigger. */
{
struct lttng_payload_view view =
lttng_payload_view_from_payload(
goto end;
}
+ /* Receive fds, if any. */
+ if (cmd_ctx->lsm.fd_count > 0) {
+ ret = lttcomm_recv_payload_fds_unix_sock(
+ sock, cmd_ctx->lsm.fd_count, &trigger_payload);
+ if (ret > 0 && ret != cmd_ctx->lsm.fd_count * sizeof(int)) {
+ ret = LTTNG_ERR_INVALID_PROTOCOL;
+ goto end;
+ } else if (ret <= 0) {
+ ret = LTTNG_ERR_FATAL;
+ goto end;
+ }
+ }
+
{
struct lttng_payload_view view =
lttng_payload_view_from_payload(
int lttng_register_trigger(struct lttng_trigger *trigger)
{
int ret;
- struct lttcomm_session_msg lsm;
- struct lttng_payload payload;
+ struct lttcomm_session_msg lsm = {
+ .cmd_type = LTTNG_REGISTER_TRIGGER,
+ };
+ struct lttcomm_session_msg *message_lsm;
+ struct lttng_payload message;
+ struct lttng_payload reply;
+
+ lttng_payload_init(&message);
+ lttng_payload_init(&reply);
- lttng_payload_init(&payload);
if (!trigger) {
ret = -LTTNG_ERR_INVALID;
goto end;
goto end;
}
- ret = lttng_trigger_serialize(trigger, &payload);
+ lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
+
+ /*
+ * This is needed to populate the trigger object size for the command
+ * header.
+ */
+ message_lsm = (struct lttcomm_session_msg *) message.buffer.data;
+
+ ret = lttng_trigger_serialize(trigger, &message);
if (ret < 0) {
ret = -LTTNG_ERR_UNK;
goto end;
}
- memset(&lsm, 0, sizeof(lsm));
- lsm.cmd_type = LTTNG_REGISTER_TRIGGER;
- lsm.u.trigger.length = (uint32_t) payload.buffer.size;
- ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(
- &lsm, payload.buffer.data, payload.buffer.size, NULL);
+ message_lsm->u.trigger.length = (uint32_t) message.buffer.size - sizeof(lsm);
+
+ {
+ struct lttng_payload_view message_view =
+ lttng_payload_view_from_payload(
+ &message, 0, -1);
+
+ message_lsm->fd_count = lttng_payload_view_get_fd_handle_count(
+ &message_view);
+ ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
+ if (ret < 0) {
+ goto end;
+ }
+ }
+
+ ret = 0;
end:
- lttng_payload_reset(&payload);
+ lttng_payload_reset(&message);
+ lttng_payload_reset(&reply);
return ret;
}
{
int ret;
struct lttcomm_session_msg lsm;
- struct lttng_payload payload;
+ struct lttcomm_session_msg *message_lsm;
+ struct lttng_payload message;
+ struct lttng_payload reply;
+
+ lttng_payload_init(&message);
+ lttng_payload_init(&reply);
- lttng_payload_init(&payload);
if (!trigger) {
ret = -LTTNG_ERR_INVALID;
goto end;
goto end;
}
- ret = lttng_trigger_serialize(trigger, &payload);
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
+
+ lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
+
+ /*
+ * This is needed to populate the trigger object size for the command
+ * header and number of fds sent.
+ */
+ message_lsm = (struct lttcomm_session_msg *) message.buffer.data;
+
+ ret = lttng_trigger_serialize(trigger, &message);
if (ret < 0) {
ret = -LTTNG_ERR_UNK;
goto end;
}
- memset(&lsm, 0, sizeof(lsm));
- lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
- lsm.u.trigger.length = (uint32_t) payload.buffer.size;
- ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(
- &lsm, payload.buffer.data, payload.buffer.size, NULL);
+ message_lsm->u.trigger.length = (uint32_t) message.buffer.size - sizeof(lsm);
+
+ {
+ struct lttng_payload_view message_view =
+ lttng_payload_view_from_payload(
+ &message, 0, -1);
+
+ /*
+ * Update the message header with the number of fd that will be
+ * sent.
+ */
+ message_lsm->fd_count = lttng_payload_view_get_fd_handle_count(
+ &message_view);
+
+ ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
+ if (ret < 0) {
+ goto end;
+ }
+ }
+
+ ret = 0;
end:
- lttng_payload_reset(&payload);
+ lttng_payload_reset(&message);
+ lttng_payload_reset(&reply);
return ret;
}