}
/*
- * 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 ||
/* 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 */