Add the relayd create session command
[lttng-tools.git] / src / common / relayd / relayd.c
index 9cc682713ca7368b6d0b21255bbf84c4740a39b2..56ca98223a383bd6d9a36b288decea7c677505ac 100644 (file)
@@ -99,6 +99,54 @@ error:
        return ret;
 }
 
+/*
+ * Send a RELAYD_CREATE_SESSION command to the relayd with the given socket and
+ * set session_id of the relayd if we have a successful reply from the relayd.
+ *
+ * On success, return 0 else a negative value being a lttng_error_code returned
+ * from the relayd.
+ */
+int relayd_create_session(struct lttcomm_sock *sock, uint64_t *session_id)
+{
+       int ret;
+       struct lttcomm_relayd_status_session reply;
+
+       assert(sock);
+       assert(session_id);
+
+       DBG("Relayd create session");
+
+       /* Send command */
+       ret = send_command(sock, RELAYD_CREATE_SESSION, NULL, 0, 0);
+       if (ret < 0) {
+               goto error;
+       }
+
+       /* Recevie response */
+       ret = recv_reply(sock, (void *) &reply, sizeof(reply));
+       if (ret < 0) {
+               goto error;
+       }
+
+       reply.session_id = be64toh(reply.session_id);
+       reply.ret_code = be32toh(reply.ret_code);
+
+       /* Return session id or negative ret code. */
+       if (reply.ret_code != LTTNG_OK) {
+               ret = -reply.ret_code;
+               ERR("Relayd create session replied error %d", ret);
+               goto error;
+       } else {
+               ret = 0;
+               *session_id = reply.session_id;
+       }
+
+       DBG("Relayd session created with id %" PRIu64, reply.session_id);
+
+error:
+       return ret;
+}
+
 /*
  * Add stream on the relayd and assign stream handle to the stream_id argument.
  *
This page took 0.024248 seconds and 4 git commands to generate.