From: Mathieu Desnoyers Date: Fri, 2 Mar 2012 18:10:11 +0000 (-0500) Subject: Fix: test all close return values in sessiond X-Git-Tag: v2.0.0-rc2~10 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=799e2c4f4ecb595fcb52c3e6affd3b4ec7b5b24e;p=lttng-tools.git Fix: test all close return values in sessiond Signed-off-by: Mathieu Desnoyers --- diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 0922c3d49..fea51b761 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -491,7 +491,10 @@ int kernel_open_channel_stream(struct ltt_kernel_channel *channel) while ((ret = kernctl_create_stream(channel->fd)) >= 0) { lks = trace_kernel_create_stream(); if (lks == NULL) { - close(ret); + ret = close(ret); + if (ret) { + PERROR("close"); + } goto error; } @@ -555,7 +558,7 @@ error: */ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events) { - int fd, pos; + int fd, pos, ret; char *event; size_t nbmem, count = 0; ssize_t size; @@ -603,11 +606,17 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events) *events = elist; DBG("Kernel list events done (%zu events)", count); end: - fclose(fp); /* closes both fp and fd */ + ret = fclose(fp); /* closes both fp and fd */ + if (ret) { + PERROR("fclose"); + } return count; error_fp: - close(fd); + ret = close(fd); + if (ret) { + PERROR("close"); + } error: return -1; } @@ -669,8 +678,10 @@ int init_kernel_workarounds(void) /* Ignore error, we don't really care */ } } - fclose(fp); + ret = fclose(fp); + if (ret) { + PERROR("fclose"); + } end_boot_id: - return 0; } diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 0116e84a0..8fb92f12a 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -306,9 +306,14 @@ error: */ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) { + int ret; + DBG("[trace] Closing stream fd %d", stream->fd); /* Close kernel fd */ - close(stream->fd); + ret = close(stream->fd); + if (ret) { + PERROR("close"); + } /* Remove from stream list */ cds_list_del(&stream->list); @@ -321,10 +326,15 @@ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) */ void trace_kernel_destroy_event(struct ltt_kernel_event *event) { + int ret; + if (event->fd >= 0) { DBG("[trace] Closing event fd %d", event->fd); /* Close kernel fd */ - close(event->fd); + ret = close(event->fd); + if (ret) { + PERROR("close"); + } } else { DBG("[trace] Tearing down event (no associated fd)"); } @@ -344,10 +354,14 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) { struct ltt_kernel_stream *stream, *stmp; struct ltt_kernel_event *event, *etmp; + int ret; DBG("[trace] Closing channel fd %d", channel->fd); /* Close kernel fd */ - close(channel->fd); + ret = close(channel->fd); + if (ret) { + PERROR("close"); + } /* For each stream in the channel list */ cds_list_for_each_entry_safe(stream, stmp, &channel->stream_list.head, list) { @@ -373,9 +387,14 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) */ void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata) { + int ret; + DBG("[trace] Closing metadata fd %d", metadata->fd); /* Close kernel fd */ - close(metadata->fd); + ret = close(metadata->fd); + if (ret) { + PERROR("close"); + } free(metadata->conf); free(metadata->pathname); @@ -388,14 +407,21 @@ void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata) void trace_kernel_destroy_session(struct ltt_kernel_session *session) { struct ltt_kernel_channel *channel, *ctmp; + int ret; DBG("[trace] Closing session fd %d", session->fd); /* Close kernel fds */ - close(session->fd); + ret = close(session->fd); + if (ret) { + PERROR("close"); + } if (session->metadata_stream_fd != 0) { DBG("[trace] Closing metadata stream fd %d", session->metadata_stream_fd); - close(session->metadata_stream_fd); + ret = close(session->metadata_stream_fd); + if (ret) { + PERROR("close"); + } } if (session->metadata != NULL) { diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 030358241..6e1dd60fd 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -198,7 +198,10 @@ void delete_ust_app(struct ust_app *app) * closing this socket, otherwise an application could re-use the socket ID * and race with the teardown, using the same hash table entry. */ - close(sock); + ret = close(sock); + if (ret) { + PERROR("close"); + } DBG2("UST app pid %d deleted", app->key.pid); free(app); @@ -1268,20 +1271,27 @@ error: int ust_app_register(struct ust_register_msg *msg, int sock) { struct ust_app *lta; + int ret; if ((msg->bits_per_long == 64 && ust_consumerd64_fd == -EINVAL) || (msg->bits_per_long == 32 && ust_consumerd32_fd == -EINVAL)) { ERR("Registration failed: application \"%s\" (pid: %d) has " "%d-bit long, but no consumerd for this long size is available.\n", msg->name, msg->pid, msg->bits_per_long); - close(sock); + ret = close(sock); + if (ret) { + PERROR("close"); + } return -EINVAL; } if (msg->major != LTTNG_UST_COMM_MAJOR) { ERR("Registration failed: application \"%s\" (pid: %d) has " "communication protocol version %u.%u, but sessiond supports 2.x.\n", msg->name, msg->pid, msg->major, msg->minor); - close(sock); + ret = close(sock); + if (ret) { + PERROR("close"); + } return -EINVAL; } lta = zmalloc(sizeof(struct ust_app));