From: Mathieu Desnoyers Date: Fri, 24 Feb 2012 19:41:49 +0000 (-0500) Subject: Fix: lttng UST and kernel consumer: fix ret vs errno mixup X-Git-Tag: v2.0.0-rc3~24 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=87dc6a9c2c936cf4386043083412c695a914cb36;p=lttng-tools.git Fix: lttng UST and kernel consumer: fix ret vs errno mixup - errno should be set to -ret (not the opposite!) The main effect is that the perror errors were meaningless. - errno should always be compared with positive values. This was also causing consumerd error handling mistakes. Signed-off-by: Mathieu Desnoyers --- diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index f32f47b3e..c1ba1405e 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -58,7 +58,7 @@ int lttng_kconsumer_on_read_subbuffer_mmap( /* get the offset inside the fd to mmap */ ret = kernctl_get_mmap_read_offset(fd, &mmap_offset); if (ret != 0) { - ret = -errno; + errno = -ret; perror("kernctl_get_mmap_read_offset"); goto end; } @@ -68,7 +68,7 @@ int lttng_kconsumer_on_read_subbuffer_mmap( if (ret >= len) { len = 0; } else if (ret < 0) { - ret = -errno; + errno = -ret; perror("Error in file write"); goto end; } @@ -108,7 +108,7 @@ int lttng_kconsumer_on_read_subbuffer_splice( SPLICE_F_MOVE | SPLICE_F_MORE); DBG("splice chan to pipe ret %ld", ret); if (ret < 0) { - ret = errno; + errno = -ret; perror("Error in relay splice"); goto splice_error; } @@ -117,7 +117,7 @@ int lttng_kconsumer_on_read_subbuffer_splice( SPLICE_F_MOVE | SPLICE_F_MORE); DBG("splice pipe to file %ld", ret); if (ret < 0) { - ret = errno; + errno = -ret; perror("Error in file splice"); goto splice_error; } @@ -165,7 +165,7 @@ int lttng_kconsumer_take_snapshot(struct lttng_consumer_local_data *ctx, ret = kernctl_snapshot(infd); if (ret != 0) { - ret = errno; + errno = -ret; perror("Getting sub-buffer snapshot."); } @@ -187,7 +187,7 @@ int lttng_kconsumer_get_produced_snapshot( ret = kernctl_snapshot_get_produced(infd, pos); if (ret != 0) { - ret = errno; + errno = -ret; perror("kernctl_snapshot_get_produced"); } @@ -320,7 +320,6 @@ int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, /* Get the next subbuffer */ err = kernctl_get_next_subbuf(infd); if (err != 0) { - ret = errno; /* * This is a debug message even for single-threaded consumer, * because poll() have more relaxed criterions than get subbuf, @@ -337,7 +336,7 @@ int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, /* read the whole subbuffer */ err = kernctl_get_padded_subbuf_size(infd, &len); if (err != 0) { - ret = errno; + errno = -ret; perror("Getting sub-buffer len failed."); goto end; } @@ -356,7 +355,7 @@ int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, /* read the used subbuffer size */ err = kernctl_get_padded_subbuf_size(infd, &len); if (err != 0) { - ret = errno; + errno = -ret; perror("Getting sub-buffer len failed."); goto end; } @@ -377,7 +376,7 @@ int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, err = kernctl_put_next_subbuf(infd); if (err != 0) { - ret = errno; + errno = -ret; if (errno == EFAULT) { perror("Error in unreserving sub buffer\n"); } else if (errno == EIO) { @@ -415,7 +414,7 @@ int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream) ret = kernctl_get_mmap_len(stream->wait_fd, &mmap_len); if (ret != 0) { - ret = errno; + errno = -ret; perror("kernctl_get_mmap_len"); goto error_close_fd; } diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index e81f05041..113682384 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -58,7 +58,7 @@ int lttng_ustconsumer_on_read_subbuffer_mmap( ret = ustctl_get_mmap_read_offset(stream->chan->handle, stream->buf, &mmap_offset); if (ret != 0) { - ret = -errno; + errno = -ret; perror("ustctl_get_mmap_read_offset"); goto end; } @@ -67,7 +67,7 @@ int lttng_ustconsumer_on_read_subbuffer_mmap( if (ret >= len) { len = 0; } else if (ret < 0) { - ret = -errno; + errno = -ret; perror("Error in file write"); goto end; } @@ -109,7 +109,7 @@ int lttng_ustconsumer_take_snapshot(struct lttng_consumer_local_data *ctx, ret = ustctl_snapshot(stream->chan->handle, stream->buf); if (ret != 0) { - ret = errno; + errno = -ret; perror("Getting sub-buffer snapshot."); } @@ -131,7 +131,7 @@ int lttng_ustconsumer_get_produced_snapshot( ret = ustctl_snapshot_get_produced(stream->chan->handle, stream->buf, pos); if (ret != 0) { - ret = errno; + errno = -ret; perror("kernctl_snapshot_get_produced"); } @@ -347,7 +347,7 @@ int lttng_ustconsumer_read_subbuffer(struct lttng_consumer_stream *stream, if (!stream->hangup_flush_done) { do { readlen = read(stream->wait_fd, &dummy, 1); - } while (readlen == -1 && errno == -EINTR); + } while (readlen == -1 && errno == EINTR); if (readlen == -1) { ret = readlen; goto end;