Fix: audit all close/fclose and check returned code
authorDavid Goulet <dgoulet@efficios.com>
Mon, 3 Dec 2012 21:57:57 +0000 (16:57 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 3 Dec 2012 21:57:57 +0000 (16:57 -0500)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/cmd.c
src/bin/lttng/conf.c
src/common/consumer.c

index c099061ccf7339f03741fc3cda59fb5ae60901a6..a00fb3c48ab258459de880d3a4720ef9dfd9b0ed 100644 (file)
@@ -894,7 +894,10 @@ void relay_delete_session(struct relay_command *cmd, struct lttng_ht *streams_ht
                        stream = caa_container_of(node,
                                        struct relay_stream, stream_n);
                        if (stream->session == cmd->session) {
-                               close(stream->fd);
+                               ret = close(stream->fd);
+                               if (ret < 0) {
+                                       PERROR("close stream fd on delete session");
+                               }
                                ret = lttng_ht_del(streams_ht, &iter);
                                assert(!ret);
                                call_rcu(&stream->rcu_node,
@@ -1055,7 +1058,10 @@ int relay_close_stream(struct lttcomm_relayd_hdr *recv_hdr,
        if (close_stream_check(stream)) {
                int delret;
 
-               close(stream->fd);
+               delret = close(stream->fd);
+               if (delret < 0) {
+                       PERROR("close stream");
+               }
                delret = lttng_ht_del(streams_ht, &iter);
                assert(!delret);
                call_rcu(&stream->rcu_node,
@@ -1533,9 +1539,13 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht)
 
        /* Check if we need to close the FD */
        if (close_stream_check(stream)) {
+               int cret;
                struct lttng_ht_iter iter;
 
-               close(stream->fd);
+               cret = close(stream->fd);
+               if (cret < 0) {
+                       PERROR("close stream process data");
+               }
                iter.iter.node = &stream->stream_n.node;
                ret = lttng_ht_del(streams_ht, &iter);
                assert(!ret);
index b78af9e771022c08e55fd61c8fa098ea0340460f..2110e31e9508683f7332088c20e147bf84e3c921 100644 (file)
@@ -1880,8 +1880,11 @@ int cmd_register_consumer(struct ltt_session *session, int domain,
 
                socket = consumer_allocate_socket(sock);
                if (socket == NULL) {
+                       ret = close(sock);
+                       if (ret < 0) {
+                               PERROR("close register consumer");
+                       }
                        ret = LTTNG_ERR_FATAL;
-                       close(sock);
                        goto error;
                }
 
index 7d537d1f6d654ab5dce83fa65adf333ed14e4bf4..995407d03d4d4ba6863ee991c6da927df06e8db8 100644 (file)
@@ -116,7 +116,9 @@ static int write_config(char *file_path, size_t size, char *data)
        if (len != 1) {
                ret = -1;
        }
-       fclose(fp);
+       if (fclose(fp)) {
+               PERROR("close write_config");
+       }
 end:
        return ret;
 }
@@ -221,13 +223,19 @@ char *config_read_session_name(char *path)
        }
 
 error_close:
-       fclose(fp);
+       ret = fclose(fp);
+       if (ret < 0) {
+               PERROR("close config read session name");
+       }
 
 error:
        return NULL;
 
 found:
-       fclose(fp);
+       ret = fclose(fp);
+       if (ret < 0) {
+               PERROR("close config read session name found");
+       }
        return session_name;
 
 }
index 24b1f1d9f04bea22eb79c77ebebc2b836bbcebca..dbec177b7328468b278d0205598e04c574609b53 100644 (file)
@@ -2051,7 +2051,10 @@ restart:
                                         * since their might be data to consume.
                                         */
                                        lttng_poll_del(&events, ctx->consumer_metadata_pipe[0]);
-                                       close(ctx->consumer_metadata_pipe[0]);
+                                       ret = close(ctx->consumer_metadata_pipe[0]);
+                                       if (ret < 0) {
+                                               PERROR("close metadata pipe");
+                                       }
                                        continue;
                                } else if (revents & LPOLLIN) {
                                        do {
@@ -2415,7 +2418,10 @@ end:
         * only tracked fd in the poll set. The thread will take care of closing
         * the read side.
         */
-       close(ctx->consumer_metadata_pipe[1]);
+       ret = close(ctx->consumer_metadata_pipe[1]);
+       if (ret < 0) {
+               PERROR("close data pipe");
+       }
 
        if (data_ht) {
                destroy_data_stream_ht(data_ht);
@@ -2635,7 +2641,10 @@ int consumer_add_relayd_socket(int net_seq_idx, int sock_type,
                }
 
                /* Close the created socket fd which is useless */
-               close(relayd->control_sock.fd);
+               ret = close(relayd->control_sock.fd);
+               if (ret < 0) {
+                       PERROR("close relayd control socket");
+               }
 
                /* Assign new file descriptor */
                relayd->control_sock.fd = fd;
@@ -2649,7 +2658,10 @@ int consumer_add_relayd_socket(int net_seq_idx, int sock_type,
                }
 
                /* Close the created socket fd which is useless */
-               close(relayd->data_sock.fd);
+               ret = close(relayd->data_sock.fd);
+               if (ret < 0) {
+                       PERROR("close relayd control socket");
+               }
 
                /* Assign new file descriptor */
                relayd->data_sock.fd = fd;
This page took 0.032799 seconds and 4 git commands to generate.