Refactor: Move set session path to own function
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 25 Oct 2019 22:12:01 +0000 (18:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 5 Nov 2019 19:51:06 +0000 (14:51 -0500)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/cmd.c

index 1dec61ea17b6ba7f74e122e37a7df99afa2e07c6..be493fd8a5527f7795446592016c44f47eaa6d09 100644 (file)
@@ -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 */
This page took 0.031097 seconds and 4 git commands to generate.