From: Mathieu Desnoyers Date: Thu, 17 Dec 2020 18:51:14 +0000 (-0500) Subject: Fix: UST comm protocol: event notifier command is too large X-Git-Tag: v2.13.0-rc1~401 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8406222c45d29b23064d688e33be84894a51baac;p=lttng-ust.git Fix: UST comm protocol: event notifier command is too large 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 Reviewed-by: Francis Deslauriers Change-Id: Ief172eaddd113ec9092dd57bad3d73fd4c29fd51 --- diff --git a/include/ust-comm.h b/include/ust-comm.h index 49a55d21..c5900368 100644 --- a/include/ust-comm.h +++ b/include/ust-comm.h @@ -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; diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 7d2c05a9..07267aed 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -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; diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index bb22a8a9..59f14050 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -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)