From: David Goulet Date: Wed, 19 Dec 2012 23:30:37 +0000 (-0500) Subject: Fix: compare write() return value to size X-Git-Tag: v2.1.0~10 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4cec016f4a1cb76ec3d917c2d261c4081910a65a;p=lttng-tools.git Fix: compare write() return value to size Now also check if the ret value of a write() operation is not equal to the given size. Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 0446d9cb0..a73b4852d 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -254,7 +254,7 @@ int notify_thread_pipe(int wpipe) do { ret = write(wpipe, "!", 1); } while (ret < 0 && errno == EINTR); - if (ret < 0) { + if (ret < 0 || ret != 1) { PERROR("write poll pipe"); } @@ -669,7 +669,7 @@ void *relay_thread_dispatcher(void *data) sizeof(struct relay_command)); } while (ret < 0 && errno == EINTR); free(relay_cmd); - if (ret < 0) { + if (ret < 0 || ret != sizeof(struct relay_command)) { PERROR("write cmd pipe"); goto error; } @@ -1244,7 +1244,7 @@ static int write_padding_to_file(int fd, uint32_t size) do { ret = write(fd, zeros, size); } while (ret < 0 && errno == EINTR); - if (ret < 0) { + if (ret < 0 || ret != size) { PERROR("write padding to file"); } @@ -1322,7 +1322,7 @@ int relay_recv_metadata(struct lttcomm_relayd_hdr *recv_hdr, ret = write(metadata_stream->fd, metadata_struct->payload, payload_size); } while (ret < 0 && errno == EINTR); - if (ret < payload_size) { + if (ret < 0 || ret != payload_size) { ERR("Relay error writing metadata on file"); ret = -1; goto end_unlock; @@ -1804,7 +1804,7 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht) do { ret = write(stream->fd, data_buffer, data_size); } while (ret < 0 && errno == EINTR); - if (ret < data_size) { + if (ret < 0 || ret != data_size) { ERR("Relay error writing data to file"); ret = -1; goto end_unlock; diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 184ac6be6..237a2cf8d 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -1330,7 +1330,7 @@ static void *thread_dispatch_ust_registration(void *data) ret = write(apps_cmd_pipe[1], ust_cmd, sizeof(struct ust_command)); } while (ret < 0 && errno == EINTR); - if (ret < 0) { + if (ret < 0 || ret != sizeof(struct ust_command)) { PERROR("write apps cmd pipe"); if (errno == EBADF) { /* diff --git a/src/common/consumer.c b/src/common/consumer.c index e0a756a56..1e710ab3d 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -1106,7 +1106,7 @@ void lttng_consumer_should_exit(struct lttng_consumer_local_data *ctx) do { ret = write(ctx->consumer_should_quit[1], "4", 1); } while (ret < 0 && errno == EINTR); - if (ret < 0) { + if (ret < 0 || ret != 1) { PERROR("write consumer quit"); } @@ -1324,7 +1324,7 @@ static int write_relayd_metadata_id(int fd, do { ret = write(fd, (void *) &hdr, sizeof(hdr)); } while (ret < 0 && errno == EINTR); - if (ret < 0) { + if (ret < 0 || ret != sizeof(hdr)) { /* * This error means that the fd's end is closed so ignore the perror * not to clubber the error output since this can happen in a normal