From: David Goulet Date: Mon, 3 Dec 2012 21:57:57 +0000 (-0500) Subject: Fix: audit all close/fclose and check returned code X-Git-Tag: v2.1.0~82 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f66c074ce00abc984ec7cb57a4fa31b1d9cffd72;p=lttng-tools.git Fix: audit all close/fclose and check returned code Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index c099061cc..a00fb3c48 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -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); diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index b78af9e77..2110e31e9 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; } diff --git a/src/bin/lttng/conf.c b/src/bin/lttng/conf.c index 7d537d1f6..995407d03 100644 --- a/src/bin/lttng/conf.c +++ b/src/bin/lttng/conf.c @@ -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; } diff --git a/src/common/consumer.c b/src/common/consumer.c index 24b1f1d9f..dbec177b7 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -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;