Implement event notifier
[deliverable/lttng-ust.git] / liblttng-ust-ctl / ustctl.c
index 39c8baa4b4fea4b586a9323290b6287acd4e86f4..744f66ba6dc9824c00329540d41c88294644bb2c 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#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 <lttng/ust-endian.h>
 #include <usterr-signal-safe.h>
 #include <ust-comm.h>
 #include <helper.h>
@@ -110,8 +110,10 @@ int ustctl_release_object(int sock, struct lttng_ust_object_data *data)
                                ret = -errno;
                                return ret;
                        }
+                       data->u.channel.wakeup_fd = -1;
                }
                free(data->u.channel.data);
+               data->u.channel.data = NULL;
                break;
        case LTTNG_UST_OBJECT_TYPE_STREAM:
                if (data->u.stream.shm_fd >= 0) {
@@ -120,6 +122,7 @@ int ustctl_release_object(int sock, struct lttng_ust_object_data *data)
                                ret = -errno;
                                return ret;
                        }
+                       data->u.stream.shm_fd = -1;
                }
                if (data->u.stream.wakeup_fd >= 0) {
                        ret = close(data->u.stream.wakeup_fd);
@@ -127,10 +130,13 @@ int ustctl_release_object(int sock, struct lttng_ust_object_data *data)
                                ret = -errno;
                                return ret;
                        }
+                       data->u.stream.wakeup_fd = -1;
                }
                break;
        case LTTNG_UST_OBJECT_TYPE_EVENT:
        case LTTNG_UST_OBJECT_TYPE_CONTEXT:
+       case LTTNG_UST_OBJECT_TYPE_EVENT_NOTIFIER_GROUP:
+       case LTTNG_UST_OBJECT_TYPE_EVENT_NOTIFIER:
                break;
        default:
                assert(0);
@@ -417,6 +423,97 @@ int ustctl_stop_session(int sock, int handle)
        return ustctl_disable(sock, &obj);
 }
 
+int ustctl_create_event_notifier_group(int sock, int pipe_fd,
+               struct lttng_ust_object_data **_event_notifier_group_data)
+{
+       struct lttng_ust_object_data *event_notifier_group_data;
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
+       ssize_t len;
+       int ret;
+
+       if (!_event_notifier_group_data)
+               return -EINVAL;
+
+       event_notifier_group_data = zmalloc(sizeof(*event_notifier_group_data));
+       if (!event_notifier_group_data)
+               return -ENOMEM;
+
+       event_notifier_group_data->type = LTTNG_UST_OBJECT_TYPE_EVENT_NOTIFIER_GROUP;
+
+       memset(&lum, 0, sizeof(lum));
+       lum.handle = LTTNG_UST_ROOT_HANDLE;
+       lum.cmd = LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE;
+
+       ret = ustcomm_send_app_msg(sock, &lum);
+       if (ret)
+               goto error;
+
+       /* Send event_notifier 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;
+
+       event_notifier_group_data->handle = lur.ret_val;
+       DBG("received event_notifier group handle %d", event_notifier_group_data->handle);
+
+       *_event_notifier_group_data = event_notifier_group_data;
+
+       ret = 0;
+       goto end;
+error:
+       free(event_notifier_group_data);
+
+end:
+       return ret;
+}
+
+int ustctl_create_event_notifier(int sock, struct lttng_ust_event_notifier *event_notifier,
+               struct lttng_ust_object_data *event_notifier_group,
+               struct lttng_ust_object_data **_event_notifier_data)
+{
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
+       struct lttng_ust_object_data *event_notifier_data;
+       int ret;
+
+       if (!event_notifier_group || !_event_notifier_data)
+               return -EINVAL;
+
+       event_notifier_data = zmalloc(sizeof(*event_notifier_data));
+       if (!event_notifier_data)
+               return -ENOMEM;
+
+       event_notifier_data->type = LTTNG_UST_OBJECT_TYPE_EVENT_NOTIFIER;
+
+       memset(&lum, 0, sizeof(lum));
+       lum.handle = event_notifier_group->handle;
+       lum.cmd = LTTNG_UST_EVENT_NOTIFIER_CREATE;
+
+       strncpy(lum.u.event_notifier.event.name, event_notifier->event.name,
+               LTTNG_UST_SYM_NAME_LEN);
+       lum.u.event_notifier.event.instrumentation = event_notifier->event.instrumentation;
+       lum.u.event_notifier.event.loglevel_type = event_notifier->event.loglevel_type;
+       lum.u.event_notifier.event.loglevel = event_notifier->event.loglevel;
+       lum.u.event_notifier.event.token = event_notifier->event.token;
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
+       if (ret) {
+               free(event_notifier_data);
+               return ret;
+       }
+       event_notifier_data->handle = lur.ret_val;
+       DBG("received event_notifier handle %u", event_notifier_data->handle);
+       *_event_notifier_data = event_notifier_data;
+
+       return ret;
+}
+
 int ustctl_tracepoint_list(int sock)
 {
        struct ustcomm_ust_msg lum;
@@ -1452,7 +1549,7 @@ int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream,
        chan = consumer_chan->chan->chan;
        *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
                consumer_chan->chan->handle);
-       *len = PAGE_ALIGN(*len);
+       *len = LTTNG_UST_PAGE_ALIGN(*len);
        return 0;
 }
 
@@ -1853,7 +1950,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.030344 seconds and 5 git commands to generate.