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)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 27 Feb 2012 18:55:43 +0000 (13:55 -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>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/kernel-consumer/kernel-consumer.c
src/common/ust-consumer/ust-consumer.c

index 3489ab6ed866970eec6915701ffef029d27d6c36..bb95529530161b4a45152609a67f8f018eeca6bd 100644 (file)
@@ -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;
                }
index 5f5e9582574011577297bf36123a64958a752793..27601463c22ccb3652d41776234d49cc0e2161a9 100644 (file)
@@ -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;
This page took 0.028678 seconds and 4 git commands to generate.