Fix: compare write() return value to size
authorDavid Goulet <dgoulet@efficios.com>
Wed, 19 Dec 2012 23:30:37 +0000 (18:30 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 19 Dec 2012 23:33:41 +0000 (18:33 -0500)
Now also check if the ret value of a write() operation is not equal to
the given size.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/main.c
src/common/consumer.c

index 0446d9cb04dcddce51d919ca6d0e27160ed25bdc..a73b4852d574be48f25f2184e2ae793ac46e85d8 100644 (file)
@@ -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;
index 184ac6be62de3c5667d06c126eb373aa3ce1d1d6..237a2cf8d75a3f3ee8dc1a68c7c63dfccc1526b2 100644 (file)
@@ -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) {
                                                /*
index e0a756a5697c40c7cbbd1ff0887a5c01f61464e3..1e710ab3d9b80fefbbfe2aad58fd050e50d03444 100644 (file)
@@ -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
This page took 0.031659 seconds and 4 git commands to generate.