Fix: test all close return values in sessiond
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 2 Mar 2012 18:10:11 +0000 (13:10 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 2 Mar 2012 18:10:11 +0000 (13:10 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/trace-kernel.c
src/bin/lttng-sessiond/ust-app.c

index 0922c3d490918f3a177a48cecd1b5b94772aa8cb..fea51b761c8ea2f0b224f2dfd2dc8589a9c8ad8b 100644 (file)
@@ -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;
 }
index 0116e84a0fcf05f02606140619e181f09a2b5d1b..8fb92f12ab13c08386108c0feddcc3769a1aee95 100644 (file)
@@ -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) {
index 030358241f663548265493bd2459c00977be0013..6e1dd60fd6b060a1437589a6594b30c0e69deefe 100644 (file)
@@ -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));
This page took 0.039064 seconds and 4 git commands to generate.