Fix: return error if sendmsg fails on relayd
[lttng-tools.git] / src / bin / lttng-relayd / main.c
index 0446d9cb04dcddce51d919ca6d0e27160ed25bdc..6d800f50b3c0db40de5997ead9625fee8cf8938c 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;
                        }
@@ -958,6 +958,7 @@ error:
        send_ret = cmd->sock->ops->sendmsg(cmd->sock, &reply, sizeof(reply), 0);
        if (send_ret < 0) {
                ERR("Relayd sending session id");
+               ret = send_ret;
        }
 
        return ret;
@@ -983,7 +984,6 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
                goto end_no_session;
        }
 
-       /* FIXME : use data_size for something ? */
        ret = cmd->sock->ops->recvmsg(cmd->sock, &stream_info,
                        sizeof(struct lttcomm_relayd_add_stream), 0);
        if (ret < sizeof(struct lttcomm_relayd_add_stream)) {
@@ -1055,6 +1055,7 @@ end:
                        sizeof(struct lttcomm_relayd_status_stream), 0);
        if (send_ret < 0) {
                ERR("Relay sending stream id");
+               ret = send_ret;
        }
        rcu_read_unlock();
 
@@ -1144,6 +1145,7 @@ end_unlock:
                        sizeof(struct lttcomm_relayd_generic_reply), 0);
        if (send_ret < 0) {
                ERR("Relay sending stream id");
+               ret = send_ret;
        }
 
 end_no_session:
@@ -1244,7 +1246,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 +1324,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 +1806,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;
This page took 0.02432 seconds and 4 git commands to generate.