From: Jérémie Galarneau Date: Tue, 7 Mar 2023 19:38:32 +0000 (-0500) Subject: Fix: consumerd: type confusion in lttng_consumer_send_error X-Git-Tag: v2.13.13~3 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a73d94960e33d71f20cb99ea648cd24d064aabee;p=lttng-tools.git Fix: consumerd: type confusion in lttng_consumer_send_error lttng_consumer_send_error sends an lttcomm_return_code to the session daemon. However, the size of lttcomm_sessiond_command was used. This was probably missed since the function accepts an integer instead of a proper enum type. The size accepted by the function is changed to use lttcomm_return_code and the size of a fixed-size type is used to send the error code to the session daemon. Signed-off-by: Jérémie Galarneau Change-Id: Ib6a04969dd82857e3b8ac2ca2545cfb098b2d04f --- diff --git a/src/bin/lttng-sessiond/manage-consumer.c b/src/bin/lttng-sessiond/manage-consumer.c index 093944c8e..8f0dde185 100644 --- a/src/bin/lttng-sessiond/manage-consumer.c +++ b/src/bin/lttng-sessiond/manage-consumer.c @@ -161,9 +161,13 @@ static void *thread_consumer_management(void *data) DBG2("Receiving code from consumer err_sock"); - /* Getting status code from kconsumerd */ - ret = lttcomm_recv_unix_sock(sock, &code, - sizeof(enum lttcomm_return_code)); + /* Getting status code from consumerd */ + { + int32_t comm_code = 0; + + ret = lttcomm_recv_unix_sock(sock, &comm_code, sizeof(comm_code)); + code = (typeof(code)) comm_code; + } if (ret <= 0) { mark_thread_intialization_as_failed(notifiers); goto error; @@ -308,9 +312,14 @@ static void *thread_consumer_management(void *data) goto error; } health_code_update(); - /* Wait for any kconsumerd error */ - ret = lttcomm_recv_unix_sock(sock, &code, - sizeof(enum lttcomm_return_code)); + /* Wait for any consumerd error */ + { + int32_t comm_code = 0; + + ret = lttcomm_recv_unix_sock( + sock, &comm_code, sizeof(comm_code)); + code = (typeof(code)) comm_code; + } if (ret <= 0) { ERR("consumer closed the command socket"); goto error; diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index a2df6c958..f5c532714 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -1269,11 +1269,14 @@ void lttng_consumer_set_command_sock_path( * Send return code to the session daemon. * If the socket is not defined, we return 0, it is not a fatal error */ -int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx, int cmd) +int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx, + enum lttcomm_return_code error_code) { if (ctx->consumer_error_socket > 0) { - return lttcomm_send_unix_sock(ctx->consumer_error_socket, &cmd, - sizeof(enum lttcomm_sessiond_command)); + const int32_t comm_code = (int32_t) error_code; + + return lttcomm_send_unix_sock( + ctx->consumer_error_socket, &comm_code, sizeof(comm_code)); } return 0; diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index 53c39e6eb..645569296 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -918,7 +918,8 @@ void lttng_consumer_set_command_sock_path( * Returns the return code of sendmsg : the number of bytes transmitted or -1 * on error. */ -int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx, int cmd); +int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx, + enum lttcomm_return_code error_code); /* * Called from signal handler to ensure a clean exit.