fix: write EINTR handling
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 23 Jul 2012 15:13:40 +0000 (11:13 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 23 Jul 2012 15:13:40 +0000 (11:13 -0400)
Ensure that we always test for ret < 0 && errno == EINTR for each
write() call.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/utils.c
src/common/consumer.c
src/common/kernel-consumer/kernel-consumer.c
src/common/runas.c
src/common/ust-consumer/ust-consumer.c

index 5a12ba88847b01ef631639bf2a123fe63deb5cd4..0428d33cef82d7f3c18bcff03f2310433808f7bf 100644 (file)
@@ -246,7 +246,9 @@ int notify_thread_pipe(int wpipe)
 {
        int ret;
 
-       ret = write(wpipe, "!", 1);
+       do {
+               ret = write(wpipe, "!", 1);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
                PERROR("write poll pipe");
        }
@@ -627,8 +629,10 @@ void *relay_thread_dispatcher(void *data)
                         * call is blocking so we can be assured that the data will be read
                         * at some point in time or wait to the end of the world :)
                         */
-                       ret = write(relay_cmd_pipe[1], relay_cmd,
-                                       sizeof(struct relay_command));
+                       do {
+                               ret = write(relay_cmd_pipe[1], relay_cmd,
+                                               sizeof(struct relay_command));
+                       } while (ret < 0 && errno == EINTR);
                        free(relay_cmd);
                        if (ret < 0) {
                                PERROR("write cmd pipe");
@@ -1054,8 +1058,10 @@ int relay_recv_metadata(struct lttcomm_relayd_hdr *recv_hdr,
                goto end;
        }
 
-       ret = write(metadata_stream->fd, metadata_struct->payload,
-                       payload_size);
+       do {
+               ret = write(metadata_stream->fd, metadata_struct->payload,
+                               payload_size);
+       } while (ret < 0 && errno == EINTR);
        if (ret < (payload_size)) {
                ERR("Relay error writing metadata on file");
                ret = -1;
@@ -1189,7 +1195,9 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht)
                goto end;
        }
 
-       ret = write(stream->fd, data_buffer, data_size);
+       do {
+               ret = write(stream->fd, data_buffer, data_size);
+       } while (ret < 0 && errno == EINTR);
        if (ret < data_size) {
                ERR("Relay error writing data to file");
                ret = -1;
index 07f29adedcebc0570c81bc153fe07769991b4e69..d503665a4fdb1149d68b00b79fcab14ed948bd4d 100644 (file)
@@ -31,7 +31,9 @@ int notify_thread_pipe(int wpipe)
 {
        int ret;
 
-       ret = write(wpipe, "!", 1);
+       do {
+               ret = write(wpipe, "!", 1);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
                PERROR("write poll pipe");
        }
index 88e8d9d28017ed5fb0fccbee22fad316f1ed402c..974c65f550c94a6be3fb94c18227f86ad133076e 100644 (file)
@@ -875,7 +875,9 @@ void lttng_consumer_should_exit(struct lttng_consumer_local_data *ctx)
 {
        int ret;
        consumer_quit = 1;
-       ret = write(ctx->consumer_should_quit[1], "4", 1);
+       do {
+               ret = write(ctx->consumer_should_quit[1], "4", 1);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
                perror("write consumer quit");
        }
@@ -1522,7 +1524,7 @@ end:
         */
        do {
                ret = write(ctx->consumer_poll_pipe[1], "", 1);
-       } while (ret == -1UL && errno == EINTR);
+       } while (ret < 0 && errno == EINTR);
        rcu_unregister_thread();
        return NULL;
 }
index 8ed279f44e16db7e73a14d8947c9e87b143f6946..00bb7f7212cac7f0ccf4f4a6c91ef80dbb4b58ef 100644 (file)
@@ -101,12 +101,12 @@ ssize_t lttng_kconsumer_on_read_subbuffer_mmap(
                                do {
                                        ret = write(outfd, (void *) &metadata_id,
                                                        sizeof(stream->relayd_stream_id));
-                                       if (ret < 0) {
-                                               PERROR("write metadata stream id");
-                                               written = ret;
-                                               goto end;
-                                       }
-                               } while (errno == EINTR);
+                               } while (ret < 0 && errno == EINTR);
+                               if (ret < 0) {
+                                       PERROR("write metadata stream id");
+                                       written = ret;
+                                       goto end;
+                               }
                                DBG("Metadata stream id %zu written before data",
                                                stream->relayd_stream_id);
                                /*
@@ -120,18 +120,15 @@ ssize_t lttng_kconsumer_on_read_subbuffer_mmap(
        }
 
        while (len > 0) {
-               ret = write(outfd, stream->mmap_base + mmap_offset, len);
+               do {
+                       ret = write(outfd, stream->mmap_base + mmap_offset, len);
+               } while (ret < 0 && errno == EINTR);
                if (ret < 0) {
-                       if (errno == EINTR) {
-                               /* restart the interrupted system call */
-                               continue;
-                       } else {
-                               perror("Error in file write");
-                               if (written == 0) {
-                                       written = ret;
-                               }
-                               goto end;
+                       perror("Error in file write");
+                       if (written == 0) {
+                               written = ret;
                        }
+                       goto end;
                } else if (ret > len) {
                        perror("Error in file write");
                        written += ret;
@@ -200,17 +197,17 @@ ssize_t lttng_kconsumer_on_read_subbuffer_splice(
                 */
                pthread_mutex_lock(&relayd->ctrl_sock_mutex);
 
+               metadata_id = htobe64(stream->relayd_stream_id);
                do {
-                       metadata_id = htobe64(stream->relayd_stream_id);
                        ret = write(ctx->consumer_thread_pipe[1],
                                        (void *) &metadata_id,
                                        sizeof(stream->relayd_stream_id));
-                       if (ret < 0) {
-                               PERROR("write metadata stream id");
-                               written = ret;
-                               goto end;
-                       }
-               } while (errno == EINTR);
+               } while (ret < 0 && errno == EINTR);
+               if (ret < 0) {
+                       PERROR("write metadata stream id");
+                       written = ret;
+                       goto end;
+               }
                DBG("Metadata stream id %zu written before data",
                                stream->relayd_stream_id);
        }
@@ -581,7 +578,7 @@ end:
         */
        do {
                ret = write(ctx->consumer_poll_pipe[1], "", 1);
-       } while (ret == -1UL && errno == EINTR);
+       } while (ret < 0 && errno == EINTR);
 end_nosignal:
        return 0;
 }
index 3a89cc9ab8d1f73795ca2d9f963fd34423911cbb..43b154f10869de2e85a57bb7bcc03c7bb646bb72 100644 (file)
@@ -192,8 +192,10 @@ int child_run_as(void *_data)
        writeleft = sizeof(sendret);
        index = 0;
        do {
-               writelen = write(data->retval_pipe, &sendret.c[index],
-                               writeleft);
+               do {
+                       writelen = write(data->retval_pipe, &sendret.c[index],
+                                       writeleft);
+               } while (writelen < 0 && errno == EINTR);
                if (writelen < 0) {
                        PERROR("write");
                        return EXIT_FAILURE;
index f6add2c2c88327d05f1dd1ce90b49241df74c1f8..1cd39ef34b7e957bf9cfa95ac93e7fb40374fb9c 100644 (file)
@@ -91,12 +91,12 @@ ssize_t lttng_ustconsumer_on_read_subbuffer_mmap(
                                do {
                                        ret = write(outfd, (void *) &metadata_id,
                                                        sizeof(stream->relayd_stream_id));
-                                       if (ret < 0) {
-                                               PERROR("write metadata stream id");
-                                               written = ret;
-                                               goto end;
-                                       }
-                               } while (errno == EINTR);
+                               } while (ret < 0 && errno == EINTR);
+                               if (ret < 0) {
+                                       PERROR("write metadata stream id");
+                                       written = ret;
+                                       goto end;
+                               }
                                DBG("Metadata stream id %zu written before data",
                                                stream->relayd_stream_id);
                        }
@@ -105,18 +105,15 @@ ssize_t lttng_ustconsumer_on_read_subbuffer_mmap(
        }
 
        while (len > 0) {
-               ret = write(outfd, stream->mmap_base + mmap_offset, len);
+               do {
+                       ret = write(outfd, stream->mmap_base + mmap_offset, len);
+               } while (ret < 0 && errno == EINTR);
                if (ret < 0) {
-                       if (errno == EINTR) {
-                               /* restart the interrupted system call */
-                               continue;
-                       } else {
-                               PERROR("Error in file write");
-                               if (written == 0) {
-                                       written = ret;
-                               }
-                               goto end;
+                       PERROR("Error in file write");
+                       if (written == 0) {
+                               written = ret;
                        }
+                       goto end;
                } else if (ret > len) {
                        PERROR("ret %ld > len %lu", ret, len);
                        written += ret;
@@ -434,7 +431,7 @@ end:
         */
        do {
                ret = write(ctx->consumer_poll_pipe[1], "", 1);
-       } while (ret == -1UL && errno == EINTR);
+       } while (ret < 0 && errno == EINTR);
 end_nosignal:
        return 0;
 }
This page took 0.033097 seconds and 4 git commands to generate.