Improve trace output path and config path
authorDavid Goulet <david.goulet@polymtl.ca>
Thu, 30 Jun 2011 19:39:59 +0000 (15:39 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 30 Jun 2011 19:39:59 +0000 (15:39 -0400)
Now, the default config directory is placed in the home directory and
the trace output directory is set inside that config directory with name
being the session name with date and time.

Add get home functio to utils.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
ltt-sessiond/kernel-ctl.c
ltt-sessiond/kernel-ctl.h
ltt-sessiond/main.c
ltt-sessiond/session.c
ltt-sessiond/trace.c
ltt-sessiond/trace.h
ltt-sessiond/utils.c
ltt-sessiond/utils.h
lttng/commands/create.c
lttng/conf.c

index 02b01414a4f76296cb4a9b97a2fd7661dbe9aab7..168bce1f3d3eb9ea89566da7cb65995fe8bb9c20 100644 (file)
@@ -141,13 +141,13 @@ error:
  *  Create a kernel channel, register it to the kernel tracer and add it to the
  *  kernel session.
  */
-int kernel_create_channel(struct ltt_kernel_session *session, struct lttng_channel *chan)
+int kernel_create_channel(struct ltt_kernel_session *session, struct lttng_channel *chan, char *path)
 {
        int ret;
        struct ltt_kernel_channel *lkc;
 
        /* Allocate kernel channel */
-       lkc = trace_create_kernel_channel(chan);
+       lkc = trace_create_kernel_channel(chan, path);
        if (lkc == NULL) {
                goto error;
        }
index cb9ed043c3046aaf067ed3a85d03411875708ce5..7a908edf50b07265728435e8b25ec693264938d5 100644 (file)
@@ -35,7 +35,8 @@ int kernel_add_channel_context(struct ltt_kernel_channel *chan,
 int kernel_add_event_context(struct ltt_kernel_event *event,
                struct lttng_kernel_context *ctx);
 int kernel_create_session(struct ltt_session *session, int tracer_fd);
-int kernel_create_channel(struct ltt_kernel_session *session, struct lttng_channel *chan);
+int kernel_create_channel(struct ltt_kernel_session *session,
+               struct lttng_channel *chan, char *path);
 int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel);
 int kernel_disable_channel(struct ltt_kernel_channel *chan);
 int kernel_disable_event(struct ltt_kernel_event *event);
index b0848eb45bb2fdb8cb4df223cf9b2e794e1a0a4b..75215b3f23039bb16caa3d5e45af5c854f3689db 100644 (file)
@@ -751,7 +751,7 @@ static int create_kernel_session(struct ltt_session *session)
 
        DBG("Creating default kernel channel %s", DEFAULT_CHANNEL_NAME);
 
-       ret = kernel_create_channel(session->kernel_session, chan);
+       ret = kernel_create_channel(session->kernel_session, chan, session->path);
        if (ret < 0) {
                ret = LTTCOMM_KERN_CHAN_FAIL;
                goto error;
@@ -943,7 +943,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                DBG("Creating kernel channel");
 
                ret = kernel_create_channel(cmd_ctx->session->kernel_session,
-                               &cmd_ctx->lsm->u.channel.chan);
+                               &cmd_ctx->lsm->u.channel.chan, cmd_ctx->session->path);
                if (ret < 0) {
                        ret = LTTCOMM_KERN_CHAN_FAIL;
                        goto error;
@@ -1754,25 +1754,6 @@ static int check_existing_daemon()
        return ret;
 }
 
-/*
- *  get_home_dir
- *
- *  Return pointer to home directory path using
- *  the env variable HOME.
- *
- *  Default : /tmp
- */
-static const char *get_home_dir(void)
-{
-       const char *home_path;
-
-       if ((home_path = (const char *) getenv("HOME")) == NULL) {
-               home_path = default_home_dir;
-       }
-
-       return home_path;
-}
-
 /*
  *  set_permissions
  *
@@ -1988,6 +1969,7 @@ int main(int argc, char **argv)
 {
        int ret = 0;
        void *status;
+       const char *home_path;
 
        /* Parse arguments */
        progname = argv[0];
@@ -2035,15 +2017,22 @@ int main(int argc, char **argv)
                /* Set ulimit for open files */
                set_ulimit();
        } else {
+               home_path = get_home_dir();
+               if (home_path == NULL) {
+                       ERR("Can't get HOME directory for sockets creation.\n \
+                                Please specify --socket PATH.");
+                       goto error;
+               }
+
                if (strlen(apps_unix_sock_path) == 0) {
                        snprintf(apps_unix_sock_path, PATH_MAX,
-                                       DEFAULT_HOME_APPS_UNIX_SOCK, get_home_dir());
+                                       DEFAULT_HOME_APPS_UNIX_SOCK, home_path);
                }
 
                /* Set the cli tool unix socket path */
                if (strlen(client_unix_sock_path) == 0) {
                        snprintf(client_unix_sock_path, PATH_MAX,
-                                       DEFAULT_HOME_CLIENT_UNIX_SOCK, get_home_dir());
+                                       DEFAULT_HOME_CLIENT_UNIX_SOCK, home_path);
                }
        }
 
index a4101d2ee8fed3076364b8283504345669c78681..be820ee552dace6d6c5df188b8d8dee9e2c63681 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <urcu/list.h>
 
 #include "lttngerr.h"
@@ -171,9 +172,10 @@ int destroy_session(char *name)
 int create_session(char *name, char *path)
 {
        int ret;
+       char date_time[NAME_MAX];
        struct ltt_session *new_session;
-
-       DBG("Creating session %s at %s", name, path);
+       time_t rawtime;
+       struct tm *timeinfo;
 
        new_session = find_session_by_name(name);
        if (new_session != NULL) {
@@ -203,7 +205,15 @@ int create_session(char *name, char *path)
 
        /* Define session system path */
        if (path != NULL) {
-               if (asprintf(&new_session->path, "%s", path) < 0) {
+               if (strstr(name, "auto-") == NULL) {
+                       time(&rawtime);
+                       timeinfo = localtime(&rawtime);
+                       strftime(date_time, sizeof(date_time), "-%Y%m%d-%H%M%S", timeinfo);
+               } else {
+                       date_time[0] = '\0';
+               }
+
+               if (asprintf(&new_session->path, "%s/%s%s", path, name, date_time) < 0) {
                        ret = -ENOMEM;
                        goto error_asprintf;
                }
@@ -235,6 +245,8 @@ int create_session(char *name, char *path)
        /* Add new session to the global session list */
        add_session_list(new_session);
 
+       DBG("Tracing session %s created in %s", name, new_session->path);
+
        return 0;
 
 error:
index 297d04f29484087ad36c693f75f13c8db625d19b..f59c96f3f7c40f06596052dc415ee6051ae4a7b2 100644 (file)
@@ -119,7 +119,7 @@ error:
  *
  *  Return pointer to structure or NULL.
  */
-struct ltt_kernel_channel *trace_create_kernel_channel(struct lttng_channel *chan)
+struct ltt_kernel_channel *trace_create_kernel_channel(struct lttng_channel *chan, char *path)
 {
        int ret;
        struct ltt_kernel_channel *lkc;
@@ -144,7 +144,7 @@ struct ltt_kernel_channel *trace_create_kernel_channel(struct lttng_channel *cha
        CDS_INIT_LIST_HEAD(&lkc->events_list.head);
        CDS_INIT_LIST_HEAD(&lkc->stream_list.head);
        /* Set default trace output path */
-       ret = asprintf(&lkc->pathname, "%s", DEFAULT_TRACE_OUTPUT);
+       ret = asprintf(&lkc->pathname, "%s", path);
        if (ret < 0) {
                perror("asprintf kernel create channel");
                goto error;
index 2c2f62ae010d12fb85a30ecc8ac2aefef9b5e3ed..43b67eae25cf9d35f5157b8c93348206cdca6c9c 100644 (file)
@@ -116,7 +116,7 @@ struct ltt_kernel_channel *get_kernel_channel_by_name(
  * Create functions malloc() the data structure.
  */
 struct ltt_kernel_session *trace_create_kernel_session(void);
-struct ltt_kernel_channel *trace_create_kernel_channel(struct lttng_channel *chan);
+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_stream *trace_create_kernel_stream(void);
index 936d3e1b891034321e4f79c48b0ff2b14729d72e..d099c08031abf96221ac3028f3048fe4cd6ff266 100644 (file)
 
 #include "utils.h"
 
+/*
+ *  get_home_dir
+ *
+ *  Return pointer to home directory path using the env variable HOME.
+ *  No home, NULL is returned.
+ */
+const char *get_home_dir(void)
+{
+       return ((const char *) getenv("HOME"));
+}
+
+/*
+ *  mkdir_recursive
+ *
+ *  Create recursively directory using the FULL path.
+ */
 int mkdir_recursive(const char *path, mode_t mode)
 {
     int ret;
index 564017df6fe79250b10a23f9b946644f76ff91bf..c0f5a4f9d4fd0c1f21a7fc9d2fe2f2b35f83c2ca 100644 (file)
@@ -20,5 +20,6 @@
 #define _LTT_UTILS_H
 
 int mkdir_recursive(const char *path, mode_t mode);
+const char *get_home_dir(void);
 
 #endif /* _LTT_UTILS_H */
index 941f72355426e792987442134061d7569e52cbb3..e76316d219bfe66cb4eb71e0b0289426402249b9 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "cmd.h"
 #include "conf.h"
+#include "utils.h"
 
 static char *opt_output_path;
 static char *opt_session_name;
@@ -84,6 +85,8 @@ static int create_session()
        if (opt_output_path == NULL) {
                alloc_path = 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;
                }
@@ -114,7 +117,7 @@ static int create_session()
        }
 
        MSG("Session %s created.", session_name);
-       MSG("Working directory of created session is %s", path);
+       MSG("Working directory of created session is %s/%s", path, session_name);
 
        ret = CMD_SUCCESS;
 
index 9e3a626ba34d5112fa83d15e6ca24585a37b8dd9..1cf0907ad884bf204060e6bd6f8f7df79f7d0bb1 100644 (file)
@@ -148,19 +148,12 @@ error:
 /*
  *  config_get_default_path
  *
- *  Return the default path to config directory which is the current working
- *  directory. User must free() the returned allocated string.
+ *  Return the HOME directory path. The output is dup so the user MUST
+ *  free(3) the returned string.
  */
 char *config_get_default_path(void)
 {
-       char *alloc_path;
-
-       alloc_path = getcwd(NULL, 0);
-       if (alloc_path == NULL) {
-               perror("getcwd");
-       }
-
-       return alloc_path;
+       return strdup(getenv("HOME"));
 }
 
 /*
This page took 0.045226 seconds and 4 git commands to generate.