variable LTTNG_HOME. This is useful when the user running the commands has
a non-writeable home directory.
+The session name MUST NOT contain the character '/'.
+
.B OPTIONS:
.TP
LTTNG_ERR_UST_STREAM_FAIL = 70, /* UST create stream failed */
LTTNG_ERR_SNAPSHOT_NODATA = 71, /* No data in snapshot. */
LTTNG_ERR_NO_CHANNEL = 72, /* No channel found in the session. */
- /* 73 */
+ LTTNG_ERR_SESSION_INVALID_CHAR = 73, /* Invalid characters found in session name. */
LTTNG_ERR_UST_LIST_FAIL = 74, /* UST listing events failed */
LTTNG_ERR_UST_EVENT_EXIST = 75, /* UST event exist */
LTTNG_ERR_UST_EVENT_NOT_FOUND = 76, /* UST event not found */
.next_uuid = 0,
};
+/* These characters are forbidden in a session name. Used by validate_name. */
+static const char *forbidden_name_chars = "/";
+
+/*
+ * Validate the session name for forbidden characters.
+ *
+ * Return 0 on success else -1 meaning a forbidden char. has been found.
+ */
+static int validate_name(const char *name)
+{
+ int ret;
+ char *tok, *tmp_name;
+
+ assert(name);
+
+ tmp_name = strdup(name);
+ if (!tmp_name) {
+ /* ENOMEM here. */
+ ret = -1;
+ goto error;
+ }
+
+ tok = strpbrk(tmp_name, forbidden_name_chars);
+ if (tok) {
+ DBG("Session name %s contains a forbidden character", name);
+ /* Forbidden character has been found. */
+ ret = -1;
+ goto error;
+ }
+ ret = 0;
+
+error:
+ free(tmp_name);
+ return ret;
+}
+
/*
* Add a ltt_session structure to the global list.
*
goto error;
}
+ ret = validate_name(name);
+ if (ret < 0) {
+ ret = LTTNG_ERR_SESSION_INVALID_CHAR;
+ goto error;
+ }
+
ret = gethostname(new_session->hostname, sizeof(new_session->hostname));
if (ret < 0) {
if (errno == ENAMETOOLONG) {
[ ERROR_INDEX(LTTNG_ERR_CHAN_EXIST) ] = "Channel already exists",
[ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_NODATA) ] = "No data available in snapshot",
[ ERROR_INDEX(LTTNG_ERR_NO_CHANNEL) ] = "No channel found in the session",
+ [ ERROR_INDEX(LTTNG_ERR_SESSION_INVALID_CHAR) ] = "Invalid character found in session name",
/* Last element */
[ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"