From 6bf73bf53464ad309fcf7f02a4dc397d280b81f8 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 24 Feb 2012 14:41:49 -0500 Subject: [PATCH] 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 Signed-off-by: David Goulet --- src/common/kernel-consumer/kernel-consumer.c | 21 ++++++++++---------- src/common/ust-consumer/ust-consumer.c | 10 +++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 3489ab6ed..bb9552953 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -57,7 +57,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; } @@ -67,7 +67,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; } @@ -107,7 +107,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; } @@ -116,7 +116,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; } @@ -164,7 +164,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."); } @@ -186,7 +186,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"); } @@ -319,7 +319,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, @@ -336,7 +335,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; } @@ -355,7 +354,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; } @@ -376,7 +375,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) { @@ -414,7 +413,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 5f5e95825..27601463c 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -57,7 +57,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; } @@ -66,7 +66,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; } @@ -108,7 +108,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."); } @@ -130,7 +130,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"); } @@ -346,7 +346,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; -- 2.34.1