From: Jonathan Rajotte Date: Fri, 25 Oct 2019 22:12:01 +0000 (-0400) Subject: Refactor: Move set session path to own function X-Git-Tag: v2.12.0-rc1~260 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=433f5ba9ca8e445c979b49703ac195f77a94c684;p=lttng-tools.git Refactor: Move set session path to own function Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 1dec61ea1..be493fd8a 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -2740,24 +2740,15 @@ error: } /* - * Command LTTNG_SET_CONSUMER_URI processed by the client thread. + * Set the base_path of the session only if subdir of a control uris is set. + * Return LTTNG_OK on success, otherwise LTTNG_ERR_*. */ -int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri, +static int set_session_base_path_from_uris(struct ltt_session *session, + size_t nb_uri, struct lttng_uri *uris) { - int ret, i; - struct ltt_kernel_session *ksess = session->kernel_session; - struct ltt_ust_session *usess = session->ust_session; - - assert(session); - assert(uris); - assert(nb_uri > 0); - - /* Can't set consumer URI if the session is active. */ - if (session->active) { - ret = LTTNG_ERR_TRACE_ALREADY_STARTED; - goto error; - } + int ret; + size_t i; for (i = 0; i < nb_uri; i++) { if (uris[i].stype != LTTNG_STREAM_CONTROL || @@ -2774,11 +2765,47 @@ int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri, /* Set session base_path */ session->base_path = strdup(uris[i].subdir); if (!session->base_path) { - PERROR("Copying base path: %s", uris[i].subdir); + PERROR("Failed to copy base path \"%s\" to session \"%s\"", + uris[i].subdir, session->name); + ret = LTTNG_ERR_NOMEM; goto error; } - DBG2("Setting base path for session %" PRIu64 ": %s", - session->id, session->base_path); + DBG2("Setting base path \"%s\" for session \"%s\"", + session->base_path, session->name); + } + ret = LTTNG_OK; +error: + return ret; +} + +/* + * Command LTTNG_SET_CONSUMER_URI processed by the client thread. + */ +int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri, + struct lttng_uri *uris) +{ + int ret, i; + struct ltt_kernel_session *ksess = session->kernel_session; + struct ltt_ust_session *usess = session->ust_session; + + assert(session); + assert(uris); + assert(nb_uri > 0); + + /* Can't set consumer URI if the session is active. */ + if (session->active) { + ret = LTTNG_ERR_TRACE_ALREADY_STARTED; + goto error; + } + + /* + * Set the session base path if any. This is done inside + * cmd_set_consumer_uri to preserve backward compatibility of the + * previous session creation api vs the session descriptor api. + */ + ret = set_session_base_path_from_uris(session, nb_uri, uris); + if (ret != LTTNG_OK) { + goto error; } /* Set the "global" consumer URIs */