lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
To: lttng-dev@lists.lttng.org
Cc: jgalar@efficios.com
Subject: [PATCH lttng-tools 2/5] Refactor: Move set session path to own function
Date: Fri, 25 Oct 2019 18:12:01 -0400	[thread overview]
Message-ID: <20191025221204.29696-2-jonathan.rajotte-julien__16019.0169861139$1572041608$gmane$org@efficios.com> (raw)
In-Reply-To: <20191025221204.29696-1-jonathan.rajotte-julien@efficios.com>

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
---

Feel free to squash this into the previous commit.

---
 src/bin/lttng-sessiond/cmd.c | 64 +++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 20 deletions(-)

diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c
index 1dec61ea1..3ee390698 100644
--- a/src/bin/lttng-sessiond/cmd.c
+++ b/src/bin/lttng-sessiond/cmd.c
@@ -2739,6 +2739,42 @@ error:
 	return ret;
 }
 
+/*
+ * Set the base_path of the session only if subdir of a control uris is set.
+ * Return LTTNG_OK on success, otherwise LTTNG_ERR_*.
+ */
+static int set_session_base_path_from_uris(struct ltt_session *session,
+		size_t nb_uri,
+		struct lttng_uri *uris)
+{
+	int ret;
+	for (int i = 0; i < nb_uri; i++) {
+		if (uris[i].stype != LTTNG_STREAM_CONTROL ||
+				uris[i].subdir[0] == '\0') {
+			/* Not interested in these URIs */
+			continue;
+		}
+
+		if (session->base_path != NULL) {
+			free(session->base_path);
+			session->base_path = NULL;
+		}
+
+		/* Set session base_path */
+		session->base_path = strdup(uris[i].subdir);
+		if (!session->base_path) {
+			PERROR("Copying base path: %s", uris[i].subdir);
+			ret = LTTNG_ERR_NOMEM;
+			goto error;
+		}
+		DBG2("Setting base path for session %" PRIu64 ": %s",
+				session->id, session->base_path);
+	}
+	ret = LTTNG_OK;
+error:
+	return ret;
+}
+
 /*
  * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
  */
@@ -2759,26 +2795,14 @@ int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri,
 		goto error;
 	}
 
-	for (i = 0; i < nb_uri; i++) {
-		if (uris[i].stype != LTTNG_STREAM_CONTROL ||
-				uris[i].subdir[0] == '\0') {
-			/* Not interested in these URIs */
-			continue;
-		}
-
-		if (session->base_path != NULL) {
-			free(session->base_path);
-			session->base_path = NULL;
-		}
-
-		/* Set session base_path */
-		session->base_path = strdup(uris[i].subdir);
-		if (!session->base_path) {
-			PERROR("Copying base path: %s", uris[i].subdir);
-			goto error;
-		}
-		DBG2("Setting base path for session %" PRIu64 ": %s",
-				session->id, session->base_path);
+	/*
+	 * 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 */
-- 
2.17.1

       reply	other threads:[~2019-10-25 22:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191025221204.29696-1-jonathan.rajotte-julien@efficios.com>
2019-10-25 22:12 ` Jonathan Rajotte [this message]
2019-10-25 22:12 ` [PATCH lttng-tools 3/5] Cleanup: remove unused internal lttng_session_descriptor_get_base_path Jonathan Rajotte
2019-10-25 22:12 ` [PATCH lttng-tools 4/5] Tests: base path: lttng load for session configuration Jonathan Rajotte
2019-10-25 22:12 ` [PATCH lttng-tools 5/5] Tests: fix shellcheck warning Jonathan Rajotte
2019-11-06 18:17 ` [PATCH lttng-tools 1/5] Fix: move set base_path of session to URI configuration Jérémie Galarneau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20191025221204.29696-2-jonathan.rajotte-julien__16019.0169861139$1572041608$gmane$org@efficios.com' \
    --to=jonathan.rajotte-julien@efficios.com \
    --cc=jgalar@efficios.com \
    --cc=lttng-dev@lists.lttng.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).