- pthread_mutex_lock(&handle->cmd_queue.lock);
- ret = lttng_read(handle->cmd_queue.event_fd, &counter, sizeof(counter));
- if (ret != sizeof(counter)) {
- ret = -1;
- goto error_unlock;
+ uint64_t counter;
+ const auto read_ret = lttng_read(handle->cmd_queue.event_fd, &counter, sizeof(counter));
+ if (read_ret != sizeof(counter)) {
+ if (read_ret < 0) {
+ LTTNG_THROW_POSIX("Failed to read counter value from event_fd", errno);
+ } else {
+ LTTNG_THROW_ERROR(lttng::format(
+ "Failed to read counter value from event_fd because of a truncated read: ret={}, expected read size={}",
+ read_ret,
+ sizeof(counter)));
+ }