From: David Goulet Date: Wed, 6 Jul 2011 17:47:37 +0000 (-0400) Subject: Change configuration file and trace output dir X-Git-Tag: v2.0-pre1~54 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=58a97671d5fa65f93126798ded9e5306e3555186;p=lttng-tools.git Change configuration file and trace output dir The configuration file containing the session name information is now at the HOME location and named ".lttngrc". The trace output directory is now at the HOME location and named "lttng-traces" containing the traces of each sessions identified by the top level directory called "session_name-date-time". Also fix the metadata's path that was pointing to the old default path in /tmp/lttng. Signed-off-by: David Goulet --- diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h index 83838dcb7..b5b799fc6 100644 --- a/include/lttng/lttng.h +++ b/include/lttng/lttng.h @@ -33,6 +33,9 @@ /* 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. */ diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index 168bce1f3..ea3c8b283 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -325,13 +325,13 @@ error: * 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; } diff --git a/ltt-sessiond/kernel-ctl.h b/ltt-sessiond/kernel-ctl.h index 7a908edf5..d7ddd886b 100644 --- a/ltt-sessiond/kernel-ctl.h +++ b/ltt-sessiond/kernel-ctl.h @@ -42,7 +42,7 @@ int kernel_disable_channel(struct ltt_kernel_channel *chan); 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); diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 75215b3f2..a35849381 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -1225,7 +1225,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx) 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; diff --git a/ltt-sessiond/trace.c b/ltt-sessiond/trace.c index f59c96f3f..b7bb95c6d 100644 --- a/ltt-sessiond/trace.c +++ b/ltt-sessiond/trace.c @@ -217,7 +217,7 @@ 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; @@ -242,7 +242,7 @@ struct ltt_kernel_metadata *trace_create_kernel_metadata(void) 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; diff --git a/ltt-sessiond/trace.h b/ltt-sessiond/trace.h index 43b67eae2..aa3c7c7c0 100644 --- a/ltt-sessiond/trace.h +++ b/ltt-sessiond/trace.h @@ -118,7 +118,7 @@ struct ltt_kernel_channel *get_kernel_channel_by_name( 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); /* diff --git a/lttng/commands/create.c b/lttng/commands/create.c index e76316d21..4a64d8a76 100644 --- a/lttng/commands/create.c +++ b/lttng/commands/create.c @@ -52,7 +52,7 @@ static void usage(FILE *ofp) 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"); } @@ -66,7 +66,7 @@ static int create_session() { 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; @@ -83,41 +83,36 @@ static int create_session() /* 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; @@ -126,8 +121,8 @@ error: free(alloc_path); } - if (path) { - free(path); + if (traces_path) { + free(traces_path); } return ret; } diff --git a/lttng/commands/destroy.c b/lttng/commands/destroy.c index f08a99fd7..3fd3eb024 100644 --- a/lttng/commands/destroy.c +++ b/lttng/commands/destroy.c @@ -81,7 +81,7 @@ static int destroy_session() goto free_name; } - path = get_config_file_path(); + path = config_get_default_path(); if (path == NULL) { ret = CMD_FATAL; goto free_name; diff --git a/lttng/commands/set_session.c b/lttng/commands/set_session.c index f89545fd4..147b976c7 100644 --- a/lttng/commands/set_session.c +++ b/lttng/commands/set_session.c @@ -59,25 +59,11 @@ static void usage(FILE *ofp) 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; } diff --git a/lttng/conf.c b/lttng/conf.c index ac1c17296..adc887486 100644 --- a/lttng/conf.c +++ b/lttng/conf.c @@ -29,11 +29,11 @@ #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; @@ -56,7 +56,7 @@ static FILE *open_config(char *path, const char *mode) 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; } @@ -97,32 +97,6 @@ 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 * @@ -148,12 +122,11 @@ error: /* * 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"); } /* @@ -166,7 +139,10 @@ void config_destroy(char *path) 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) { @@ -241,38 +217,19 @@ error: 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; } @@ -282,6 +239,11 @@ int config_init(char *path) goto error; } + ret = config_add_session_name(path, session_name); + if (ret < 0) { + goto error; + } + DBG("Init config session in %s", path); error: diff --git a/lttng/conf.h b/lttng/conf.h index b221d5a92..0ccb2d430 100644 --- a/lttng/conf.h +++ b/lttng/conf.h @@ -19,16 +19,15 @@ #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 */ diff --git a/lttng/utils.c b/lttng/utils.c index 109532a4f..2cb77568e 100644 --- a/lttng/utils.c +++ b/lttng/utils.c @@ -22,33 +22,6 @@ #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 * @@ -60,7 +33,7 @@ char *get_session_name(void) 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; } @@ -68,11 +41,9 @@ char *get_session_name(void) /* 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; }