From: takeshi.iwanari Date: Fri, 24 Jun 2022 13:17:39 +0000 (+0900) Subject: Fix: Use negative value for error code of lttng_ust_ctl_duplicate_ust_object_data X-Git-Tag: v2.12.6~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2a2febe2ad7dae85101a679033b2d9b4b5926440;p=lttng-ust.git Fix: Use negative value for error code of lttng_ust_ctl_duplicate_ust_object_data [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 --- diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 39860ebf..2dbac411 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -915,7 +915,7 @@ int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data **dest, 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 { @@ -951,7 +951,7 @@ int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data **dest, 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 { @@ -963,7 +963,7 @@ int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data **dest, 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 {