From: Mathieu Desnoyers Date: Mon, 5 Aug 2013 17:46:58 +0000 (-0400) Subject: Fix: kernel ctl error codes are based on errno X-Git-Tag: v2.2.4~25 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=da3d1b707e026be8fd7f4f133e729890c7dc3653;p=lttng-tools.git Fix: kernel ctl error codes are based on errno ioctl returns -1, and error codes are based on -errno. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- diff --git a/src/common/consumer.c b/src/common/consumer.c index 912988977..e77453210 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -1367,6 +1367,7 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap( if (stream->net_seq_idx != (uint64_t) -1ULL) { relayd = consumer_find_relayd(stream->net_seq_idx); if (relayd == NULL) { + ret = -EPIPE; goto end; } } @@ -1376,28 +1377,31 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap( case LTTNG_CONSUMER_KERNEL: mmap_base = stream->mmap_base; ret = kernctl_get_mmap_read_offset(stream->wait_fd, &mmap_offset); + if (ret != 0) { + PERROR("tracer ctl get_mmap_read_offset"); + written = -errno; + goto end; + } break; case LTTNG_CONSUMER32_UST: case LTTNG_CONSUMER64_UST: mmap_base = lttng_ustctl_get_mmap_base(stream); if (!mmap_base) { ERR("read mmap get mmap base for stream %s", stream->name); - written = -1; + written = -EPERM; goto end; } ret = lttng_ustctl_get_mmap_read_offset(stream, &mmap_offset); - + if (ret != 0) { + PERROR("tracer ctl get_mmap_read_offset"); + written = ret; + goto end; + } break; default: ERR("Unknown consumer_data type"); assert(0); } - if (ret != 0) { - errno = -ret; - PERROR("tracer ctl get_mmap_read_offset"); - written = ret; - goto end; - } /* Handle stream on the relayd if the output is on the network */ if (relayd) { @@ -1478,7 +1482,7 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap( */ DBG("Error in file write mmap"); if (written == 0) { - written = ret; + written = -errno; } /* Socket operation failed. We consider the relayd dead */ if (errno == EPIPE || errno == EINVAL) { @@ -1566,6 +1570,7 @@ ssize_t lttng_consumer_on_read_subbuffer_splice( if (stream->net_seq_idx != (uint64_t) -1ULL) { relayd = consumer_find_relayd(stream->net_seq_idx); if (relayd == NULL) { + ret = -EPIPE; goto end; } } diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 1a44ce152..ea6237959 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -56,8 +56,8 @@ int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream *stream) ret = kernctl_snapshot(infd); if (ret != 0) { - errno = -ret; perror("Getting sub-buffer snapshot."); + ret = -errno; } return ret; @@ -76,8 +76,8 @@ int lttng_kconsumer_get_produced_snapshot(struct lttng_consumer_stream *stream, ret = kernctl_snapshot_get_produced(infd, pos); if (ret != 0) { - errno = -ret; perror("kernctl_snapshot_get_produced"); + ret = -errno; } return ret; @@ -452,7 +452,6 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, /* Get the next subbuffer */ err = kernctl_get_next_subbuf(infd); if (err != 0) { - ret = err; /* * This is a debug message even for single-threaded consumer, * because poll() have more relaxed criterions than get subbuf, @@ -461,15 +460,15 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, */ DBG("Reserving sub buffer failed (everything is normal, " "it is due to concurrency)"); + ret = -errno; goto end; } /* Get the full subbuffer size including padding */ err = kernctl_get_padded_subbuf_size(infd, &len); if (err != 0) { - errno = -err; perror("Getting sub-buffer len failed."); - ret = err; + ret = -errno; goto end; } @@ -504,9 +503,8 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, /* Get subbuffer size without padding */ err = kernctl_get_subbuf_size(infd, &subbuf_size); if (err != 0) { - errno = -err; perror("Getting sub-buffer len failed."); - ret = err; + ret = -errno; goto end; } @@ -536,20 +534,18 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, break; default: ERR("Unknown output method"); - ret = -1; + ret = -EPERM; } err = kernctl_put_next_subbuf(infd); if (err != 0) { - errno = -err; if (errno == EFAULT) { perror("Error in unreserving sub buffer\n"); } else if (errno == EIO) { /* Should never happen with newer LTTng versions */ perror("Reader has been pushed by the writer, last sub-buffer corrupted."); } - - ret = -err; + ret = -errno; goto end; } @@ -581,8 +577,8 @@ int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream) ret = kernctl_get_mmap_len(stream->wait_fd, &mmap_len); if (ret != 0) { - errno = -ret; PERROR("kernctl_get_mmap_len"); + ret = -errno; goto error_close_fd; } stream->mmap_len = (size_t) mmap_len;