Fix: UST comm protocol: event notifier command is too large
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 17 Dec 2020 18:51:14 +0000 (13:51 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 17 Dec 2020 19:48:12 +0000 (14:48 -0500)
The event notifier command is larger than the current largest command,
and we don't want to break the protocol between UST and tools
needlessly.

Therefore, pass the struct lttng_ust_event_notifier _after_ struct
ustcomm_ust_msg.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ief172eaddd113ec9092dd57bad3d73fd4c29fd51

include/ust-comm.h
liblttng-ust-ctl/ustctl.c
liblttng-ust/lttng-ust-comm.c

index 49a55d2109e31b6ceca45a8fc09002b2f0e45220..c59003687e64601c565d86f738d82e0962a3ba45 100644 (file)
@@ -88,7 +88,6 @@ struct ustcomm_ust_msg {
        uint32_t cmd;
        char padding[USTCOMM_MSG_PADDING1];
        union {
-               struct lttng_ust_event_notifier event_notifier;
                struct lttng_ust_channel channel;
                struct lttng_ust_stream stream;
                struct lttng_ust_event event;
@@ -111,6 +110,15 @@ struct ustcomm_ust_msg {
                struct lttng_ust_counter counter;
                struct lttng_ust_counter_global counter_global;
                struct lttng_ust_counter_cpu counter_cpu;
+               /*
+                * For LTTNG_UST_EVENT_NOTIFIER_CREATE, a struct
+                * lttng_ust_event_notifier implicitly follows struct
+                * ustcomm_ust_msg.
+                */
+               struct {
+                       /* Length of struct lttng_ust_event_notifier */
+                       uint32_t len;
+               } event_notifier;
                char padding[USTCOMM_MSG_PADDING2];
        } u;
 } LTTNG_PACKED;
index 7d2c05a9a9edb7002bbc28aae4daa9f3767945aa..07267aed122ff469591b3062f628d5ecbfbbe89a 100644 (file)
@@ -562,6 +562,7 @@ int ustctl_create_event_notifier(int sock, struct lttng_ust_event_notifier *even
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
        struct lttng_ust_object_data *event_notifier_data;
+       ssize_t len;
        int ret;
 
        if (!event_notifier_group || !_event_notifier_data)
@@ -576,19 +577,21 @@ int ustctl_create_event_notifier(int sock, struct lttng_ust_event_notifier *even
        memset(&lum, 0, sizeof(lum));
        lum.handle = event_notifier_group->handle;
        lum.cmd = LTTNG_UST_EVENT_NOTIFIER_CREATE;
+       lum.u.event_notifier.len = sizeof(*event_notifier);
 
-       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;
-       lum.u.event_notifier.error_counter_index = event_notifier->error_counter_index;
        ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret) {
                free(event_notifier_data);
                return ret;
        }
+       /* Send struct lttng_ust_event_notifier */
+       len = ustcomm_send_unix_sock(sock, event_notifier, sizeof(*event_notifier));
+       if (len != sizeof(*event_notifier)) {
+               if (len < 0)
+                       return len;
+               else
+                       return -EIO;
+       }
        event_notifier_data->handle = lur.ret_val;
        DBG("received event_notifier handle %u", event_notifier_data->handle);
        *_event_notifier_data = event_notifier_data;
index bb22a8a9d8af068de6b77145c5ca61fe228e9f90..59f14050f1b5dfdd4d53dc73d3730d9387a96142 100644 (file)
@@ -1216,6 +1216,48 @@ int handle_message(struct sock_info *sock_info,
                        ret = -ENOSYS;
                break;
        }
+       case LTTNG_UST_EVENT_NOTIFIER_CREATE:
+       {
+               /* Receive struct lttng_ust_event_notifier */
+               struct lttng_ust_event_notifier event_notifier;
+
+               if (sizeof(event_notifier) != lum->u.event_notifier.len) {
+                       DBG("incorrect event notifier data message size: %u", lum->u.event_notifier.len);
+                       ret = -EINVAL;
+                       goto error;
+               }
+               len = ustcomm_recv_unix_sock(sock, &event_notifier, sizeof(event_notifier));
+               switch (len) {
+               case 0: /* orderly shutdown */
+                       ret = 0;
+                       goto error;
+               default:
+                       if (len == sizeof(event_notifier)) {
+                               DBG("event notifier data received");
+                               break;
+                       } else if (len < 0) {
+                               DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
+                               if (len == -ECONNRESET) {
+                                       ERR("%s remote end closed connection", sock_info->name);
+                                       ret = len;
+                                       goto error;
+                               }
+                               ret = len;
+                               goto error;
+                       } else {
+                               DBG("incorrect event notifier data message size: %zd", len);
+                               ret = -EINVAL;
+                               goto error;
+                       }
+               }
+               if (ops->cmd)
+                       ret = ops->cmd(lum->handle, lum->cmd,
+                                       (unsigned long) &event_notifier,
+                                       &args, sock_info);
+               else
+                       ret = -ENOSYS;
+               break;
+       }
 
        default:
                if (ops->cmd)
This page took 0.027727 seconds and 5 git commands to generate.