X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Frelayd%2Frelayd.c;h=56ca98223a383bd6d9a36b288decea7c677505ac;hp=9cc682713ca7368b6d0b21255bbf84c4740a39b2;hb=c5b6f4f08fe8d1abff74c7f6ad3630b7dcf0669d;hpb=f50f23d9f80ed9fae7fe5c49aee65e813e0031c8 diff --git a/src/common/relayd/relayd.c b/src/common/relayd/relayd.c index 9cc682713..56ca98223 100644 --- a/src/common/relayd/relayd.c +++ b/src/common/relayd/relayd.c @@ -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. *