-/*
- * Set consumer subdirectory using the session name and a generated datetime if
- * needed. This is appended to the current subdirectory.
- */
-int consumer_set_subdir(struct consumer_output *consumer,
- const char *session_name)
-{
- int ret = 0;
- unsigned int have_default_name = 0;
- char datetime[16], tmp_path[PATH_MAX];
- time_t rawtime;
- struct tm *timeinfo;
-
- assert(consumer);
- assert(session_name);
-
- memset(tmp_path, 0, sizeof(tmp_path));
-
- /* Flag if we have a default session. */
- if (strncmp(session_name, DEFAULT_SESSION_NAME "-",
- strlen(DEFAULT_SESSION_NAME) + 1) == 0) {
- have_default_name = 1;
- } else {
- /* Get date and time for session path */
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
- }
-
- if (have_default_name) {
- ret = snprintf(tmp_path, sizeof(tmp_path),
- "%s/%s", consumer->subdir, session_name);
- } else {
- ret = snprintf(tmp_path, sizeof(tmp_path),
- "%s/%s-%s/", consumer->subdir, session_name, datetime);
- }
- if (ret < 0) {
- PERROR("snprintf session name date");
- goto error;
- }
-
- if (lttng_strncpy(consumer->subdir, tmp_path,
- sizeof(consumer->subdir))) {
- ret = -EINVAL;
- goto error;
- }
- DBG2("Consumer subdir set to %s", consumer->subdir);
-
-error:
- return ret;
-}
-