From: Jérémie Galarneau Date: Thu, 2 Jun 2016 10:13:48 +0000 (-0400) Subject: Clean-up: harmonize kernctl API error checking X-Git-Tag: v2.9.0-rc1~141 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=32af2c95c9494c282804964aed17bb2d57887505;p=lttng-tools.git Clean-up: harmonize kernctl API error checking Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index dee065460..ae8349c89 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -16,7 +16,6 @@ */ #define _LGPL_SOURCE -#include #include #include #include @@ -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: diff --git a/src/bin/lttng-sessiond/syscall.c b/src/bin/lttng-sessiond/syscall.c index b5525640a..6ee38bd0f 100644 --- a/src/bin/lttng-sessiond/syscall.c +++ b/src/bin/lttng-sessiond/syscall.c @@ -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; } diff --git a/src/common/consumer/consumer-timer.c b/src/common/consumer/consumer-timer.c index 931f7471f..b0a434284 100644 --- a/src/common/consumer/consumer-timer.c +++ b/src/common/consumer/consumer-timer.c @@ -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; diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index 5c14dd1d8..a184afd03 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -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; } diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 68dcc0230..65dcce40b 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -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;