Move stream file rotation functions to utils
[lttng-tools.git] / src / bin / lttng-relayd / main.c
index 4f9d74274943fdc433ed31c6ab60b6b05e4d5258..5f6f9cfd8ed78a613972c5b3ed9b999c63c90ecc 100644 (file)
@@ -734,6 +734,10 @@ char *create_output_path_noauto(char *path_name)
        char *full_path;
 
        full_path = utils_expand_path(opt_output_path);
+       if (!full_path) {
+               goto exit;
+       }
+
        ret = asprintf(&traces_path, "%s/%s", full_path, path_name);
        if (ret < 0) {
                PERROR("asprintf trace dir name");
@@ -941,6 +945,7 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
        ret = asprintf(&path, "%s/%s", root_path, stream_info.channel_name);
        if (ret < 0) {
                PERROR("asprintf stream path");
+               path = NULL;
                goto end;
        }
 
@@ -963,13 +968,17 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
 end:
        free(path);
        free(root_path);
+
+       reply.handle = htobe64(stream->stream_handle);
        /* send the session id to the client or a negative return code on error */
        if (ret < 0) {
                reply.ret_code = htobe32(LTTNG_ERR_UNK);
+               /* stream was not properly added to the ht, so free it */
+               free(stream);
        } else {
                reply.ret_code = htobe32(LTTNG_OK);
        }
-       reply.handle = htobe64(stream->stream_handle);
+
        send_ret = cmd->sock->ops->sendmsg(cmd->sock, &reply,
                        sizeof(struct lttcomm_relayd_status_stream), 0);
        if (send_ret < 0) {
@@ -1231,7 +1240,7 @@ end:
  */
 static
 int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
-               struct relay_command *cmd)
+               struct relay_command *cmd, struct lttng_ht *streams_ht)
 {
        int ret;
        struct lttcomm_relayd_version reply, msg;
@@ -1253,19 +1262,22 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
                goto end;
        }
 
-       /*
-        * For now, we just ignore the received version but after 2.1 stable
-        * release, a check must be done to see if we either adapt to the other
-        * side version (which MUST be lower than us) or keep the latest data
-        * structure considering that the other side will adapt.
-        */
-
        ret = sscanf(VERSION, "%10u.%10u", &reply.major, &reply.minor);
        if (ret < 2) {
                ERR("Error in scanning version");
                ret = -1;
                goto end;
        }
+
+       /* Major versions must be the same */
+       if (reply.major != be32toh(msg.major)) {
+               DBG("Incompatible major versions (%u vs %u), deleting session",
+                               reply.major, be32toh(msg.major));
+               relay_delete_session(cmd, streams_ht);
+               ret = 0;
+               goto end;
+       }
+
        reply.major = htobe32(reply.major);
        reply.minor = htobe32(reply.minor);
        ret = cmd->sock->ops->sendmsg(cmd->sock, &reply,
@@ -1273,8 +1285,19 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
        if (ret < 0) {
                ERR("Relay sending version");
        }
-       DBG("Version check done (%u.%u)", be32toh(reply.major),
-                       be32toh(reply.minor));
+
+#if 0
+       cmd->session->major = reply.major;
+       /* We adapt to the lowest compatible version */
+       if (reply.minor <= be32toh(msg.minor)) {
+               cmd->session->minor = reply.minor;
+       } else {
+               cmd->session->minor = be32toh(msg.minor);
+       }
+
+       DBG("Version check done using protocol %u.%u", cmd->session->major,
+                       cmd->session->minor);
+#endif
 
 end:
        return ret;
@@ -1584,7 +1607,7 @@ int relay_process_control(struct lttcomm_relayd_hdr *recv_hdr,
                ret = relay_recv_metadata(recv_hdr, cmd, streams_ht);
                break;
        case RELAYD_VERSION:
-               ret = relay_send_version(recv_hdr, cmd);
+               ret = relay_send_version(recv_hdr, cmd, streams_ht);
                break;
        case RELAYD_CLOSE_STREAM:
                ret = relay_close_stream(recv_hdr, cmd, streams_ht);
This page took 0.023791 seconds and 4 git commands to generate.