From d720c2d1aacce6072d7161575f6ed3275067a0ef Mon Sep 17 00:00:00 2001 From: "takeshi.iwanari" Date: Fri, 24 Jun 2022 22:17:39 +0900 Subject: [PATCH] Fix: Use negative value for error code of lttng_ust_ctl_duplicate_ust_object_data MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit [As is] - `lttng_ust_ctl_duplicate_ust_object_data` function is called by the following functions: - `event_notifier_error_accounting_register_app` (lttng-tools) - `duplicate_stream_object` (lttng-tools) - `duplicate_channel_object` (lttng-tools) - `lttng_ust_ctl_duplicate_ust_object_data` function returns positive value (= errno = 24 = EMFILE) when system call `dup` returns error - However, `duplicate_stream_object` and `duplicate_channel_object` functions expect negative value as error code - As a result, these functions cannot handle error and segmentation fault occurs when using `stream->handle` [Proposal] - Currently, `lttng_ust_ctl_duplicate_ust_object_data` function returns either positive or negative value when error happens - It looks convention is using negative value for error code (e.g. `-ENOMEM` ) - So, I propose to change `errno` to `-errno` Signed-off-by: takeshi.iwanari Signed-off-by: Mathieu Desnoyers Change-Id: Iccb01930413ecd5a8c58ad267e9c4eca53694dc7 --- src/lib/lttng-ust-ctl/ustctl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/lttng-ust-ctl/ustctl.c b/src/lib/lttng-ust-ctl/ustctl.c index 795022a1..23612fd6 100644 --- a/src/lib/lttng-ust-ctl/ustctl.c +++ b/src/lib/lttng-ust-ctl/ustctl.c @@ -1257,7 +1257,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.channel.wakeup_fd = dup(src->u.channel.wakeup_fd); if (obj->u.channel.wakeup_fd < 0) { - ret = errno; + ret = -errno; goto chan_error_wakeup_fd; } } else { @@ -1293,7 +1293,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.stream.wakeup_fd = dup(src->u.stream.wakeup_fd); if (obj->u.stream.wakeup_fd < 0) { - ret = errno; + ret = -errno; goto stream_error_wakeup_fd; } } else { @@ -1305,7 +1305,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.stream.shm_fd = dup(src->u.stream.shm_fd); if (obj->u.stream.shm_fd < 0) { - ret = errno; + ret = -errno; goto stream_error_shm_fd; } } else { @@ -1344,7 +1344,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.counter_global.shm_fd = dup(src->u.counter_global.shm_fd); if (obj->u.counter_global.shm_fd < 0) { - ret = errno; + ret = -errno; goto error_type; } } @@ -1358,7 +1358,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.counter_cpu.shm_fd = dup(src->u.counter_cpu.shm_fd); if (obj->u.counter_cpu.shm_fd < 0) { - ret = errno; + ret = -errno; goto error_type; } } -- 2.34.1