Fix: lttng UST and kernel consumer: fix ret vs errno mixup
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 24 Feb 2012 19:41:49 +0000 (14:41 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 24 Feb 2012 19:41:49 +0000 (14:41 -0500)
- 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 <mathieu.desnoyers@efficios.com>
src/common/kernel-consumer/kernel-consumer.c
src/common/ust-consumer/ust-consumer.c

index f32f47b3eeb1f6faf6b615700529dea5e990c7e5..c1ba1405ea478931a9cd3dee4ed57399ec2c5cd7 100644 (file)
@@ -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;
                }
index e81f05041249a164ce09151e9907c0602b41d6be..113682384ae44d829d03af00b1378d25687a4a39 100644 (file)
@@ -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;
This page took 0.028014 seconds and 4 git commands to generate.