Change configuration file and trace output dir
authorDavid Goulet <david.goulet@polymtl.ca>
Wed, 6 Jul 2011 17:47:37 +0000 (13:47 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Wed, 6 Jul 2011 17:55:43 +0000 (13:55 -0400)
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 <david.goulet@polymtl.ca>
12 files changed:
include/lttng/lttng.h
ltt-sessiond/kernel-ctl.c
ltt-sessiond/kernel-ctl.h
ltt-sessiond/main.c
ltt-sessiond/trace.c
ltt-sessiond/trace.h
lttng/commands/create.c
lttng/commands/destroy.c
lttng/commands/set_session.c
lttng/conf.c
lttng/conf.h
lttng/utils.c

index 83838dcb7d0a5fc884dd87276b8e786fd69cccb4..b5b799fc60c32e965f72b027e52d6c248a1f1723 100644 (file)
@@ -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.
  */
index 168bce1f3d3eb9ea89566da7cb65995fe8bb9c20..ea3c8b2835f0e0c3b8fa3ab91df78914a35553a7 100644 (file)
@@ -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;
        }
index 7a908edf50b07265728435e8b25ec693264938d5..d7ddd886b0fa240dd9b6cdca3058cb68bd88abe9 100644 (file)
@@ -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);
index 75215b3f23039bb16caa3d5e45af5c854f3689db..a3584938134f3cdfb25d865c2d80a67aabacc550 100644 (file)
@@ -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;
index f59c96f3f7c40f06596052dc415ee6051ae4a7b2..b7bb95c6d1ac963803fbe2daf91516b08ecb3b8e 100644 (file)
@@ -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;
index 43b67eae25cf9d35f5157b8c93348206cdca6c9c..aa3c7c7c05514c6addae4fa5db1e89f3d146613d 100644 (file)
@@ -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);
 
 /*
index e76316d219bfe66cb4eb71e0b0289426402249b9..4a64d8a76f87bec5f0aea945602765d7b16d90b1 100644 (file)
@@ -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;
 }
index f08a99fd76e73a9ca0fe9daad29153da223f9295..3fd3eb0247e288aef4782263f6233d68dcc03b98 100644 (file)
@@ -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;
index f89545fd46e258831b67cec91643f92837381265..147b976c7f0b733567a8c6a3e11d5ea6634b9990 100644 (file)
@@ -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;
        }
 
index ac1c172964ca263029e0906e02c12e2fa1182bd7..adc8874866c7a3e7cb739107f9eca75b4ed7ac87 100644 (file)
 #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:
index b221d5a9227035ea68781ff3aa37b7d379f50c1c..0ccb2d430863cd0531ba6d819bec2f7628a22fa9 100644 (file)
 #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 */
index 109532a4f60da1d94cf11ec5b907fc49ea68d2ca..2cb77568e339433062408f8c69a8f3fac072fd98 100644 (file)
 
 #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;
 }
This page took 0.034276 seconds and 4 git commands to generate.