Clean-up: harmonize kernctl API error checking
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 2 Jun 2016 10:13:48 +0000 (06:13 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 2 Jun 2016 22:10:47 +0000 (18:10 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/syscall.c
src/common/consumer/consumer-timer.c
src/common/consumer/consumer.c
src/common/kernel-consumer/kernel-consumer.c

index dee065460b1e661f8dca9f32a9070f3b876b24bc..ae8349c897ded12d90bfc2d018ba1994e1822f63 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #define _LGPL_SOURCE
-#include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -49,7 +48,7 @@ int kernel_add_channel_context(struct ltt_kernel_channel *chan,
        DBG("Adding context to channel %s", chan->channel->name);
        ret = kernctl_add_context(chan->fd, &ctx->ctx);
        if (ret < 0) {
-               switch (errno) {
+               switch (-ret) {
                case ENOSYS:
                        /* Exists but not available for this kernel */
                        ret = LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE;
@@ -203,7 +202,7 @@ int kernel_create_event(struct lttng_event *ev,
 
        ret = kernctl_create_event(channel->fd, event->event);
        if (ret < 0) {
-               switch (errno) {
+               switch (-ret) {
                case EEXIST:
                        break;
                case ENOSYS:
@@ -215,7 +214,6 @@ int kernel_create_event(struct lttng_event *ev,
                default:
                        PERROR("create event ioctl");
                }
-               ret = -errno;
                goto free_event;
        }
 
@@ -236,7 +234,7 @@ int kernel_create_event(struct lttng_event *ev,
 
        ret = kernctl_enable(event->fd);
        if (ret < 0) {
-               switch (errno) {
+               switch (-ret) {
                case EEXIST:
                        ret = LTTNG_ERR_KERN_EVENT_EXIST;
                        break;
@@ -283,7 +281,6 @@ int kernel_disable_channel(struct ltt_kernel_channel *chan)
        ret = kernctl_disable(chan->fd);
        if (ret < 0) {
                PERROR("disable chan ioctl");
-               ret = errno;
                goto error;
        }
 
@@ -306,7 +303,7 @@ int kernel_enable_channel(struct ltt_kernel_channel *chan)
        assert(chan);
 
        ret = kernctl_enable(chan->fd);
-       if (ret < 0 && errno != EEXIST) {
+       if (ret < 0 && ret != -EEXIST) {
                PERROR("Enable kernel chan");
                goto error;
        }
@@ -331,7 +328,7 @@ int kernel_enable_event(struct ltt_kernel_event *event)
 
        ret = kernctl_enable(event->fd);
        if (ret < 0) {
-               switch (errno) {
+               switch (-ret) {
                case EEXIST:
                        ret = LTTNG_ERR_KERN_EVENT_EXIST;
                        break;
@@ -362,7 +359,7 @@ int kernel_disable_event(struct ltt_kernel_event *event)
 
        ret = kernctl_disable(event->fd);
        if (ret < 0) {
-               switch (errno) {
+               switch (-ret) {
                case EEXIST:
                        ret = LTTNG_ERR_KERN_EVENT_EXIST;
                        break;
@@ -393,7 +390,7 @@ int kernel_track_pid(struct ltt_kernel_session *session, int pid)
        if (!ret) {
                return LTTNG_OK;
        }
-       switch (errno) {
+       switch (-ret) {
        case EINVAL:
                return LTTNG_ERR_INVALID;
        case ENOMEM:
@@ -415,7 +412,7 @@ int kernel_untrack_pid(struct ltt_kernel_session *session, int pid)
        if (!ret) {
                return LTTNG_OK;
        }
-       switch (errno) {
+       switch (-ret) {
        case EINVAL:
                return LTTNG_ERR_INVALID;
        case ENOMEM:
index b5525640a393afb35836a2d3d21c1e55b0e36118..6ee38bd0fa27a3f51c5541f8601a890d130b8aed 100644 (file)
@@ -51,7 +51,7 @@ int syscall_init_table(void)
 
        fd = kernctl_syscall_list(kernel_tracer_fd);
        if (fd < 0) {
-               ret = -errno;
+               ret = fd;
                PERROR("kernelctl syscall list");
                goto error_ioctl;
        }
index 931f7471fc6fe974982ff1cb687750ff68f80a7c..b0a434284a87d888f631b3fc8f0d435fc4c1d888 100644 (file)
@@ -148,7 +148,7 @@ int consumer_flush_kernel_index(struct lttng_consumer_stream *stream)
        }
        ret = kernctl_snapshot(stream->wait_fd);
        if (ret < 0) {
-               if (errno != EAGAIN && errno != ENODATA) {
+               if (ret != -EAGAIN && ret != -ENODATA) {
                        PERROR("live timer kernel snapshot");
                        ret = -1;
                        goto end;
index 5c14dd1d80be07eeda87fae696cbde7a450de8ec..a184afd03d24a32406a5b145fce4690ff598feb0 100644 (file)
@@ -1530,7 +1530,6 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
                mmap_base = stream->mmap_base;
                ret = kernctl_get_mmap_read_offset(stream->wait_fd, &mmap_offset);
                if (ret < 0) {
-                       ret = -errno;
                        PERROR("tracer ctl get_mmap_read_offset");
                        goto end;
                }
index 68dcc02309a452c756838c6947ecdf0e6a76957b..65dcce40b34f2b07e892c7f7a1298b9709bbd180 100644 (file)
@@ -62,7 +62,6 @@ int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream *stream)
        ret = kernctl_snapshot(infd);
        if (ret != 0) {
                PERROR("Getting sub-buffer snapshot.");
-               ret = -errno;
        }
 
        return ret;
@@ -82,7 +81,6 @@ int lttng_kconsumer_get_produced_snapshot(struct lttng_consumer_stream *stream,
        ret = kernctl_snapshot_get_produced(infd, pos);
        if (ret != 0) {
                PERROR("kernctl_snapshot_get_produced");
-               ret = -errno;
        }
 
        return ret;
@@ -102,7 +100,6 @@ int lttng_kconsumer_get_consumed_snapshot(struct lttng_consumer_stream *stream,
        ret = kernctl_snapshot_get_consumed(infd, pos);
        if (ret != 0) {
                PERROR("kernctl_snapshot_get_consumed");
-               ret = -errno;
        }
 
        return ret;
@@ -190,7 +187,6 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
                ret = kernctl_buffer_flush(stream->wait_fd);
                if (ret < 0) {
                        ERR("Failed to flush kernel stream");
-                       ret = -errno;
                        goto end_unlock;
                }
 
@@ -217,7 +213,6 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
                                        &stream->max_sb_size);
                        if (ret < 0) {
                                ERR("Getting kernel max_sb_size");
-                               ret = -errno;
                                goto end_unlock;
                        }
                }
@@ -237,9 +232,8 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
 
                        ret = kernctl_get_subbuf(stream->wait_fd, &consumed_pos);
                        if (ret < 0) {
-                               if (errno != EAGAIN) {
+                               if (ret != -EAGAIN) {
                                        PERROR("kernctl_get_subbuf snapshot");
-                                       ret = -errno;
                                        goto end_unlock;
                                }
                                DBG("Kernel consumer get subbuf failed. Skipping it.");
@@ -259,14 +253,12 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
                        ret = kernctl_get_subbuf_size(stream->wait_fd, &len);
                        if (ret < 0) {
                                ERR("Snapshot kernctl_get_subbuf_size");
-                               ret = -errno;
                                goto error_put_subbuf;
                        }
 
                        ret = kernctl_get_padded_subbuf_size(stream->wait_fd, &padded_len);
                        if (ret < 0) {
                                ERR("Snapshot kernctl_get_padded_subbuf_size");
-                               ret = -errno;
                                goto error_put_subbuf;
                        }
 
@@ -292,7 +284,6 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
                        ret = kernctl_put_subbuf(stream->wait_fd);
                        if (ret < 0) {
                                ERR("Snapshot kernctl_put_subbuf");
-                               ret = -errno;
                                goto end_unlock;
                        }
                        consumed_pos += stream->max_sb_size;
@@ -331,7 +322,6 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
 error_put_subbuf:
        ret = kernctl_put_subbuf(stream->wait_fd);
        if (ret < 0) {
-               ret = -errno;
                ERR("Snapshot kernctl_put_subbuf error path");
        }
 end_unlock:
@@ -1133,7 +1123,7 @@ int lttng_kconsumer_sync_metadata(struct lttng_consumer_stream *metadata)
 
        ret = kernctl_snapshot(metadata->wait_fd);
        if (ret < 0) {
-               if (errno != EAGAIN) {
+               if (ret != -EAGAIN) {
                        ERR("Sync metadata, taking kernel snapshot failed.");
                        goto end;
                }
@@ -1258,7 +1248,7 @@ 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;
+               ret = err;
                goto end;
        }
 
@@ -1268,16 +1258,16 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
                PERROR("Getting sub-buffer len failed.");
                err = kernctl_put_subbuf(infd);
                if (err != 0) {
-                       if (errno == EFAULT) {
+                       if (err == -EFAULT) {
                                PERROR("Error in unreserving sub buffer\n");
-                       } else if (errno == EIO) {
+                       } else if (err == -EIO) {
                                /* Should never happen with newer LTTng versions */
                                PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
                        }
-                       ret = -errno;
+                       ret = err;
                        goto end;
                }
-               ret = -errno;
+               ret = err;
                goto end;
        }
 
@@ -1286,13 +1276,13 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
                if (ret < 0) {
                        err = kernctl_put_subbuf(infd);
                        if (err != 0) {
-                               if (errno == EFAULT) {
+                               if (err == -EFAULT) {
                                        PERROR("Error in unreserving sub buffer\n");
-                               } else if (errno == EIO) {
+                               } else if (err == -EIO) {
                                        /* Should never happen with newer LTTng versions */
                                        PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
                                }
-                               ret = -errno;
+                               ret = err;
                                goto end;
                        }
                        goto end;
@@ -1343,16 +1333,16 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
                        PERROR("Getting sub-buffer len failed.");
                        err = kernctl_put_subbuf(infd);
                        if (err != 0) {
-                               if (errno == EFAULT) {
+                               if (err == -EFAULT) {
                                        PERROR("Error in unreserving sub buffer\n");
-                               } else if (errno == EIO) {
+                               } else if (err == -EIO) {
                                        /* Should never happen with newer LTTng versions */
                                        PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
                                }
-                               ret = -errno;
+                               ret = err;
                                goto end;
                        }
-                       ret = -errno;
+                       ret = err;
                        goto end;
                }
 
@@ -1389,13 +1379,13 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
 
        err = kernctl_put_next_subbuf(infd);
        if (err != 0) {
-               if (errno == EFAULT) {
+               if (err == -EFAULT) {
                        PERROR("Error in unreserving sub buffer\n");
-               } else if (errno == EIO) {
+               } else if (err == -EIO) {
                        /* Should never happen with newer LTTng versions */
                        PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
                }
-               ret = -errno;
+               ret = err;
                goto end;
        }
 
@@ -1477,7 +1467,6 @@ int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream)
                ret = kernctl_get_mmap_len(stream->wait_fd, &mmap_len);
                if (ret != 0) {
                        PERROR("kernctl_get_mmap_len");
-                       ret = -errno;
                        goto error_close_fd;
                }
                stream->mmap_len = (size_t) mmap_len;
This page took 0.032462 seconds and 4 git commands to generate.