X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fsession.c;h=de059aae203e2df17054f9bd1d415279e0bd23bf;hp=28e75f1dc1804c3f3e3740bca3a7a4e3e9fd9548;hb=590f0324d6dfd382f79229a7934fa8b5b661641f;hpb=62bad3bf0aaade7f80ba4e536e1b9e734ec2e051 diff --git a/src/bin/lttng-relayd/session.c b/src/bin/lttng-relayd/session.c index 28e75f1dc..de059aae2 100644 --- a/src/bin/lttng-relayd/session.c +++ b/src/bin/lttng-relayd/session.c @@ -19,14 +19,15 @@ #define _LGPL_SOURCE #include +#include #include #include -#include "lttng-relayd.h" #include "ctf-trace.h" +#include "lttng-relayd.h" #include "session.h" -#include "stream.h" #include "sessiond-trace-chunks.h" +#include "stream.h" /* Global session id used in the session creation. */ static uint64_t last_relay_session_id; @@ -38,8 +39,20 @@ static int session_set_anonymous_chunk(struct relay_session *session) struct lttng_trace_chunk *chunk = NULL; enum lttng_trace_chunk_status status; struct lttng_directory_handle output_directory; + const char *base_path = opt_output_path; + + if (base_path == NULL) { + /* No output path defined */ + base_path = utils_get_home_dir(); + if (base_path == NULL) { + ERR("Home path not found.\n \ + Please specify an output path using -o, --output PATH"); + ret = -1; + goto end; + } + } - ret = lttng_directory_handle_init(&output_directory, opt_output_path); + ret = lttng_directory_handle_init(&output_directory, base_path); if (ret) { goto end; } @@ -74,7 +87,7 @@ end: * Return allocated session or else NULL. */ struct relay_session *session_create(const char *session_name, - const char *hostname, + const char *hostname, const char *base_path, uint32_t live_timer, bool snapshot, const lttng_uuid sessiond_uuid, @@ -85,7 +98,23 @@ struct relay_session *session_create(const char *session_name, uint32_t minor) { int ret; - struct relay_session *session; + struct relay_session *session = NULL; + + if (session_name && strstr(session_name, ".")) { + ERR("Illegal character in session name: \"%s\"", + session_name); + goto error; + } + if (base_path && strstr(base_path, "../")) { + ERR("Invalid session base path walks up the path hierarchy: \"%s\"", + base_path); + goto error; + } + if (hostname && strstr(hostname, ".")) { + ERR("Invalid character in hostname: \"%s\"", + hostname); + goto error; + } session = zmalloc(sizeof(*session)); if (!session) { @@ -102,6 +131,12 @@ struct relay_session *session_create(const char *session_name, WARN("Hostname exceeds maximal allowed length"); goto error; } + if (lttng_strncpy(session->base_path, base_path, + sizeof(session->base_path))) { + WARN("Base path exceeds maximal allowed length"); + goto error; + } + session->ctf_traces_ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); if (!session->ctf_traces_ht) { goto error;