/* Environment variable to set session daemon binary path. */
#define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
+/* Default trace output directory name */
+#define LTTNG_DEFAULT_TRACE_DIR_NAME "lttng-traces"
+
/*
* Event symbol length.
*/
* Create kernel metadata, open from the kernel tracer and add it to the
* kernel session.
*/
-int kernel_open_metadata(struct ltt_kernel_session *session)
+int kernel_open_metadata(struct ltt_kernel_session *session, char *path)
{
int ret;
struct ltt_kernel_metadata *lkm;
/* Allocate kernel metadata */
- lkm = trace_create_kernel_metadata();
+ lkm = trace_create_kernel_metadata(path);
if (lkm == NULL) {
goto error;
}
int kernel_disable_event(struct ltt_kernel_event *event);
int kernel_enable_event(struct ltt_kernel_event *event);
int kernel_enable_channel(struct ltt_kernel_channel *chan);
-int kernel_open_metadata(struct ltt_kernel_session *session);
+int kernel_open_metadata(struct ltt_kernel_session *session, char *path);
int kernel_open_metadata_stream(struct ltt_kernel_session *session);
int kernel_open_channel_stream(struct ltt_kernel_channel *channel);
int kernel_flush_buffer(struct ltt_kernel_channel *channel);
if (cmd_ctx->session->kernel_session != NULL) {
if (cmd_ctx->session->kernel_session->metadata == NULL) {
DBG("Open kernel metadata");
- ret = kernel_open_metadata(cmd_ctx->session->kernel_session);
+ ret = kernel_open_metadata(cmd_ctx->session->kernel_session,
+ cmd_ctx->session->path);
if (ret < 0) {
ret = LTTCOMM_KERN_META_FAIL;
goto error;
*
* Return pointer to structure or NULL.
*/
-struct ltt_kernel_metadata *trace_create_kernel_metadata(void)
+struct ltt_kernel_metadata *trace_create_kernel_metadata(char *path)
{
int ret;
struct ltt_kernel_metadata *lkm;
lkm->fd = 0;
lkm->conf = chan;
/* Set default metadata path */
- ret = asprintf(&lkm->pathname, "%s/metadata", DEFAULT_TRACE_OUTPUT);
+ ret = asprintf(&lkm->pathname, "%s/metadata", path);
if (ret < 0) {
perror("asprintf kernel metadata");
goto error;
struct ltt_kernel_session *trace_create_kernel_session(void);
struct ltt_kernel_channel *trace_create_kernel_channel(struct lttng_channel *chan, char *path);
struct ltt_kernel_event *trace_create_kernel_event(struct lttng_event *ev);
-struct ltt_kernel_metadata *trace_create_kernel_metadata(void);
+struct ltt_kernel_metadata *trace_create_kernel_metadata(char *path);
struct ltt_kernel_stream *trace_create_kernel_stream(void);
/*
fprintf(ofp, "usage: lttng create [options] [NAME]\n");
fprintf(ofp, "\n");
fprintf(ofp, " -h, --help Show this help\n");
- fprintf(ofp, " -o, --output PATH Specify output path\n");
+ fprintf(ofp, " -o, --output PATH Specify output path for traces\n");
fprintf(ofp, "\n");
}
{
int ret;
char name[NAME_MAX];
- char *session_name, *path = NULL, *alloc_path;
+ char *session_name, *traces_path = NULL, *alloc_path = NULL;
time_t rawtime;
struct tm *timeinfo;
/* Auto output path */
if (opt_output_path == NULL) {
- alloc_path = config_get_default_path();
+ alloc_path = strdup(config_get_default_path());
if (alloc_path == NULL) {
ERR("Home path not found.\n \
Please specify an output path using -o, --output PATH");
ret = CMD_FATAL;
goto error;
}
- } else {
- alloc_path = opt_output_path;
- }
-
- path = config_generate_dir_path(alloc_path);
- if (path == NULL) {
- ret = CMD_FATAL;
- goto error;
- }
- /* Init lttng session config */
- ret = config_init(path);
- if (ret < 0) {
- goto error;
+ ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME, alloc_path);
+ if (ret < 0) {
+ perror("asprintf trace dir name");
+ goto error;
+ }
+ } else {
+ traces_path = opt_output_path;
}
- ret = config_add_session_name(path, session_name);
+ ret = lttng_create_session(session_name, traces_path);
if (ret < 0) {
goto error;
}
- ret = lttng_create_session(session_name, path);
+ /* Init lttng session config */
+ ret = config_init(session_name);
if (ret < 0) {
goto error;
}
MSG("Session %s created.", session_name);
- MSG("Working directory of created session is %s/%s", path, session_name);
+ MSG("Traces will be written in %s ", traces_path);
ret = CMD_SUCCESS;
free(alloc_path);
}
- if (path) {
- free(path);
+ if (traces_path) {
+ free(traces_path);
}
return ret;
}
goto free_name;
}
- path = get_config_file_path();
+ path = config_get_default_path();
if (path == NULL) {
ret = CMD_FATAL;
goto free_name;
static int set_session(void)
{
int ret = CMD_SUCCESS;
- char *path, *alloc_path;
+ char *path;
- alloc_path = config_get_default_path();
- if (alloc_path == NULL) {
- ERR("Unable to find config directory");
- ret = CMD_ERROR;
- goto error;
- }
-
- path = config_generate_dir_path(alloc_path);
+ path = config_get_default_path();
if (path == NULL) {
- ret = CMD_FATAL;
- goto error;
- }
-
- ret = config_init(path);
- if (ret < 0) {
- ERR("Init config directory and file failed");
- ret = CMD_ERROR;
+ ret = -1;
goto error;
}
#include "lttngerr.h"
/*
- * get_config_file_path
+ * config_get_file_path
*
* Return the path with '/CONFIG_FILENAME' added to it.
*/
-static char *get_config_file_path(char *path)
+char *config_get_file_path(char *path)
{
int ret;
char *file_path;
FILE *fp = NULL;
char *file_path;
- file_path = get_config_file_path(path);
+ file_path = config_get_file_path(path);
if (file_path == NULL) {
goto error;
}
return ret;
}
-/*
- * create_config_dir
- *
- * Create the empty config dir.
- */
-static int create_config_dir(char *path)
-{
- int ret;
-
- /* Create session directory .lttng */
- ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP);
- if (ret < 0) {
- if (errno != EEXIST) {
- perror("mkdir config");
- ERR("Couldn't init config directory at %s", path);
- ret = -errno;
- goto error;
- } else {
- ret = 0;
- }
- }
-
-error:
- return ret;
-}
-
/*
* write_config
*
/*
* config_get_default_path
*
- * Return the HOME directory path. The output is dup so the user MUST
- * free(3) the returned string.
+ * Return the HOME directory path. Caller MUST NOT free(3) the return pointer.
*/
char *config_get_default_path(void)
{
- return strdup(getenv("HOME"));
+ return getenv("HOME");
}
/*
int ret;
char *config_path;
- config_path = get_config_file_path(path);
+ config_path = config_get_file_path(path);
+ if (config_path == NULL) {
+ return;
+ }
ret = remove(config_path);
if (ret < 0) {
return ret;
}
-/*
- * config_generate_dir_path
- *
- * Return allocated path string to path/CONFIG_DIRNAME.
- */
-char *config_generate_dir_path(char *path)
-{
- int ret;
- char *new_path;
-
- ret = asprintf(&new_path, "%s/%s", path, CONFIG_DIRNAME);
- if (ret < 0) {
- perror("config path problem");
- goto error;
- }
-
-error:
- return new_path;
-}
-
/*
* config_init
*
* Init configuration directory and file.
*/
-int config_init(char *path)
+int config_init(char *session_name)
{
int ret;
+ char *path;
- /* Create config directory (.lttng) */
- ret = create_config_dir(path);
- if (ret < 0) {
+ path = config_get_default_path();
+ if (path == NULL) {
+ ret = -1;
goto error;
}
goto error;
}
+ ret = config_add_session_name(path, session_name);
+ if (ret < 0) {
+ goto error;
+ }
+
DBG("Init config session in %s", path);
error:
#ifndef _LTTNG_CONFIG_H
#define _LTTNG_CONFIG_H
-#define CONFIG_FILENAME "config"
-#define CONFIG_DIRNAME ".lttng"
+#define CONFIG_FILENAME ".lttngrc"
void config_destroy(char *path);
int config_init(char *path);
int config_add_session_name(char *path, char *name);
+char *config_get_default_path(void);
/* Must free() the return pointer */
-char *config_generate_dir_path(char *path);
char *config_read_session_name(char *path);
-char *config_get_default_path(void);
+char *config_get_file_path(char *path);
#endif /* _LTTNG_CONFIG_H */
#include "conf.h"
-/*
- * get_config_file_path
- *
- * Return absolute path to the configuration file.
- */
-char *get_config_file_path(void)
-{
- char *alloc_path, *path = NULL;
-
- /* Get path to config directory */
- alloc_path = config_get_default_path();
- if (alloc_path == NULL) {
- goto error;
- }
-
- /* Get path to config file */
- path = config_generate_dir_path(alloc_path);
- if (path == NULL) {
- goto free_alloc_path;
- }
-
-free_alloc_path:
- free(alloc_path);
-error:
- return path;
-}
-
/*
* get_session_name
*
char *path, *session_name = NULL;
/* Get path to config file */
- path = get_config_file_path();
+ path = config_get_default_path();
if (path == NULL) {
goto error;
}
/* Get session name from config */
session_name = config_read_session_name(path);
if (session_name == NULL) {
- goto free_path;
+ goto error;
}
-free_path:
- free(path);
error:
return session_name;
}