SoW-2019-0007-2: Dynamic Snapshot: Triggers send partial event payload with notifications
[deliverable/lttng-ust.git] / liblttng-ust-ctl / ustctl.c
index c2b761a1b7cccba3fea0fd0dfad2cc074036b45e..0ed72c4dc7683704bf219ad7dcf42cdc63fca1df 100644 (file)
  */
 
 #define _GNU_SOURCE
+#include <byteswap.h>
+#include <stdint.h>
 #include <string.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
 #include <lttng/ust-config.h>
 #include <lttng/ust-ctl.h>
 #include <lttng/ust-abi.h>
 #include <lttng/ust-events.h>
-#include <sys/mman.h>
-#include <byteswap.h>
-
 #include <usterr-signal-safe.h>
 #include <ust-comm.h>
 #include <helper.h>
@@ -130,6 +132,8 @@ int ustctl_release_object(int sock, struct lttng_ust_object_data *data)
                break;
        case LTTNG_UST_OBJECT_TYPE_EVENT:
        case LTTNG_UST_OBJECT_TYPE_CONTEXT:
+       case LTTNG_UST_OBJECT_TYPE_TRIGGER_GROUP:
+       case LTTNG_UST_OBJECT_TYPE_TRIGGER:
                break;
        default:
                assert(0);
@@ -326,6 +330,37 @@ int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode,
        return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
 }
 
+int ustctl_set_capture(int sock, struct lttng_ust_capture_bytecode *bytecode,
+               struct lttng_ust_object_data *obj_data)
+{
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
+       int ret;
+
+       if (!obj_data)
+               return -EINVAL;
+
+       memset(&lum, 0, sizeof(lum));
+       lum.handle = obj_data->handle;
+       lum.cmd = LTTNG_UST_CAPTURE;
+       lum.u.capture.data_size = bytecode->len;
+       lum.u.capture.reloc_offset = bytecode->reloc_offset;
+       lum.u.capture.seqnum = bytecode->seqnum;
+
+       ret = ustcomm_send_app_msg(sock, &lum);
+       if (ret)
+               return ret;
+       /* send var len bytecode */
+       ret = ustcomm_send_unix_sock(sock, bytecode->data,
+                               bytecode->len);
+       if (ret < 0) {
+               return ret;
+       }
+       if (ret != bytecode->len)
+               return -EINVAL;
+       return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+}
+
 int ustctl_set_exclusion(int sock, struct lttng_ust_event_exclusion *exclusion,
                struct lttng_ust_object_data *obj_data)
 {
@@ -416,6 +451,97 @@ int ustctl_stop_session(int sock, int handle)
        return ustctl_disable(sock, &obj);
 }
 
+int ustctl_create_trigger_group(int sock, int pipe_fd,
+               struct lttng_ust_object_data **_trigger_group_data)
+{
+       struct lttng_ust_object_data *trigger_group_data;
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
+       ssize_t len;
+       int ret;
+
+       if (!_trigger_group_data)
+               return -EINVAL;
+
+       trigger_group_data = zmalloc(sizeof(*trigger_group_data));
+       if (!trigger_group_data)
+               return -ENOMEM;
+
+       trigger_group_data->type = LTTNG_UST_OBJECT_TYPE_TRIGGER_GROUP;
+
+       memset(&lum, 0, sizeof(lum));
+       lum.handle = LTTNG_UST_ROOT_HANDLE;
+       lum.cmd = LTTNG_UST_TRIGGER_GROUP_CREATE;
+
+       ret = ustcomm_send_app_msg(sock, &lum);
+       if (ret)
+               goto error;
+
+       /* Send trigger notification pipe. */
+       len = ustcomm_send_fds_unix_sock(sock, &pipe_fd, 1);
+       if (len <= 0) {
+               ret = len;
+               goto error;
+       }
+
+       ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+       if (ret)
+               goto error;
+
+       trigger_group_data->handle = lur.ret_val;
+       DBG("received trigger group handle %d", trigger_group_data->handle);
+
+       *_trigger_group_data = trigger_group_data;
+
+       ret = 0;
+       goto end;
+error:
+       free(trigger_group_data);
+
+end:
+       return ret;
+}
+
+int ustctl_create_trigger(int sock, struct lttng_ust_trigger *trigger,
+               struct lttng_ust_object_data *trigger_group,
+               struct lttng_ust_object_data **_trigger_data)
+{
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
+       struct lttng_ust_object_data *trigger_data;
+       int ret;
+
+       if (!trigger_group || !_trigger_data)
+               return -EINVAL;
+
+       trigger_data = zmalloc(sizeof(*trigger_data));
+       if (!trigger_data)
+               return -ENOMEM;
+
+       trigger_data->type = LTTNG_UST_OBJECT_TYPE_TRIGGER;
+
+       memset(&lum, 0, sizeof(lum));
+       lum.handle = trigger_group->handle;
+       lum.cmd = LTTNG_UST_TRIGGER_CREATE;
+
+       strncpy(lum.u.trigger.name, trigger->name,
+               LTTNG_UST_SYM_NAME_LEN);
+       lum.u.trigger.instrumentation = trigger->instrumentation;
+       lum.u.trigger.loglevel_type = trigger->loglevel_type;
+       lum.u.trigger.loglevel = trigger->loglevel;
+       lum.u.trigger.id = trigger->id;
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
+       if (ret) {
+               free(trigger_data);
+               return ret;
+       }
+       trigger_data->handle = lur.ret_val;
+       DBG("received event handle %u", trigger_data->handle);
+       *_trigger_data = trigger_data;
+
+       return ret;
+}
+
 int ustctl_tracepoint_list(int sock)
 {
        struct ustcomm_ust_msg lum;
@@ -1852,7 +1978,8 @@ int ustctl_recv_reg_msg(int sock,
        *uint64_t_alignment = reg_msg.uint64_t_alignment;
        *long_alignment = reg_msg.long_alignment;
        memcpy(name, reg_msg.name, LTTNG_UST_ABI_PROCNAME_LEN);
-       if (reg_msg.major != LTTNG_UST_ABI_MAJOR_VERSION) {
+       if (reg_msg.major < LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE ||
+                       reg_msg.major > LTTNG_UST_ABI_MAJOR_VERSION) {
                return -LTTNG_UST_ERR_UNSUP_MAJOR;
        }
 
This page took 0.025315 seconds and 5 git commands to generate.