trigger: implement listing of registered trigger
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
index 784597e20ef3188373dc898fe9a45976381ccbbf..91d6109e5383b77f8013d67aad18b374d4e131ba 100644 (file)
@@ -211,6 +211,8 @@ static int recv_data_sessiond(void *buf, size_t len)
 {
        int ret;
 
+       assert(len > 0);
+
        if (!connected) {
                ret = -LTTNG_ERR_NO_SESSIOND;
                goto end;
@@ -219,6 +221,8 @@ static int recv_data_sessiond(void *buf, size_t len)
        ret = lttcomm_recv_unix_sock(sessiond_socket, buf, len);
        if (ret < 0) {
                ret = -LTTNG_ERR_FATAL;
+       } else if (ret == 0) {
+               ret = -LTTNG_ERR_NO_SESSIOND;
        }
 
 end:
@@ -2243,7 +2247,7 @@ int lttng_list_events(struct lttng_handle *handle,
 
        cmd_header_view = lttng_buffer_view_from_dynamic_buffer(
                &payload.buffer, 0, sizeof(*cmd_header));
-       if (!cmd_header_view.data) {
+       if (!lttng_buffer_view_is_valid(&cmd_header_view)) {
                ret = -LTTNG_ERR_INVALID_PROTOCOL;
                goto end;
        }
@@ -2310,6 +2314,11 @@ int lttng_list_events(struct lttng_handle *handle,
                                                                payload_view.buffer.data,
                                                ext_comm->userspace_probe_location_len);
 
+                               if (!lttng_payload_view_is_valid(&probe_location_view)) {
+                                       ret = -LTTNG_ERR_PROBE_LOCATION_INVAL;
+                                       goto end;
+                               }
+
                                /*
                                 * Create a temporary userspace probe location
                                 * to determine the size needed by a "flattened"
@@ -2449,6 +2458,11 @@ int lttng_list_events(struct lttng_handle *handle,
                                                                payload_copy_view.buffer.data,
                                                ext_comm->userspace_probe_location_len);
 
+                               if (!lttng_payload_view_is_valid(&probe_location_view)) {
+                                       ret = -LTTNG_ERR_PROBE_LOCATION_INVAL;
+                                       goto free_dynamic_buffer;
+                               }
+
                                ret = lttng_userspace_probe_location_create_from_payload(
                                                &probe_location_view,
                                                &probe_location);
@@ -3159,6 +3173,52 @@ end:
        return ret;
 }
 
+/*
+ * Ask the session daemon for all registered triggers for the current user.
+ *
+ * Allocates and return an lttng_triggers set.
+ * On error, returns a suitable lttng_error_code.
+ */
+enum lttng_error_code lttng_list_triggers(struct lttng_triggers **triggers)
+{
+       int ret;
+       enum lttng_error_code ret_code = LTTNG_OK;
+       struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_LIST_TRIGGERS };
+       struct lttng_triggers *local_triggers = NULL;
+       struct lttng_payload reply;
+       struct lttng_payload_view lsm_view =
+                       lttng_payload_view_init_from_buffer(
+                               (const char *) &lsm, 0, sizeof(lsm));
+
+       lttng_payload_init(&reply);
+
+       ret = lttng_ctl_ask_sessiond_payload(&lsm_view, &reply);
+       if (ret < 0) {
+               ret_code = (enum lttng_error_code) -ret;
+               goto end;
+       }
+
+       {
+               struct lttng_payload_view reply_view =
+                               lttng_payload_view_from_payload(
+                                               &reply, 0, reply.buffer.size);
+
+               ret = lttng_triggers_create_from_payload(
+                               &reply_view, &local_triggers);
+               if (ret < 0) {
+                       ret_code = LTTNG_ERR_FATAL;
+                       goto end;
+               }
+       }
+
+       *triggers = local_triggers;
+       local_triggers = NULL;
+end:
+       lttng_payload_reset(&reply);
+       lttng_triggers_destroy(local_triggers);
+       return ret_code;
+}
+
 /*
  * lib constructor.
  */
This page took 0.024193 seconds and 4 git commands to generate.