From: Jonathan Rajotte Date: Mon, 1 Mar 2021 18:07:27 +0000 (-0500) Subject: Fix: lttng_event_notifier_group_error_counter_cmd does not respect caller convention X-Git-Tag: v2.13.0-rc1~364 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ba5b3d2bf3ecd8614e74efc1db2f5a626c5d9a92;p=lttng-ust.git Fix: lttng_event_notifier_group_error_counter_cmd does not respect caller convention The callers of lttng_event_notifier_group_error_counter_cmd (via callback) expects that, on success, the object for which the ownership was taken be set to -1 or NULL. In this case, the shm_fd filed was not set to -1. Resulting in the caller closing the fd and leading to errors on subsequent call. e.g: sample: lttng-ust-fd-tracker.c:300: int lttng_ust_add_fd_to_tracker(int): Assertion `!IS_FD_SET(fd, lttng_fd_set)' failed. Error: Error sending counter cpu data to UST tracer: status=APP_DEAD Error: Failed to setup event notifier error accounting for app ./test.sh: line 5: 2650455 Aborted (core dumped) ../lttng-ust/doc/examples/easy-ust/sample lttng-sessiond: ustctl.c:192: int ustctl_release_object(int, struct lttng_ust_object_data *): Assertion `0' failed. Change-Id: I79b242768cf7d27cd9a50c31b56423c8de08abd5 Signed-off-by: Jonathan Rajotte Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 62e1be74..8fd2e958 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -733,21 +733,32 @@ static long lttng_event_notifier_group_error_counter_cmd(int objd, unsigned int cmd, unsigned long arg, union ust_args *uargs, void *owner) { + int ret; struct lttng_counter *counter = objd_private(objd); switch (cmd) { case LTTNG_UST_COUNTER_GLOBAL: - return -EINVAL; /* Unimplemented. */ + ret = -EINVAL; /* Unimplemented. */ + break; case LTTNG_UST_COUNTER_CPU: { struct lttng_ust_counter_cpu *counter_cpu = (struct lttng_ust_counter_cpu *)arg; - return lttng_counter_set_cpu_shm(counter->counter, + + ret = lttng_counter_set_cpu_shm(counter->counter, counter_cpu->cpu_nr, uargs->counter_shm.shm_fd); + if (!ret) { + /* Take ownership of the shm_fd. */ + uargs->counter_shm.shm_fd = -1; + } + break; } default: - return -EINVAL; + ret = -EINVAL; + break; } + + return ret; } LTTNG_HIDDEN