From: David Goulet Date: Thu, 30 Jun 2011 19:39:59 +0000 (-0400) Subject: Improve trace output path and config path X-Git-Tag: v2.0-pre1~59 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=b082db07f0c522527fc95fc97f3e99eb0579c0cc Improve trace output path and config path 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 --- diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index 02b01414a..168bce1f3 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -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; } diff --git a/ltt-sessiond/kernel-ctl.h b/ltt-sessiond/kernel-ctl.h index cb9ed043c..7a908edf5 100644 --- a/ltt-sessiond/kernel-ctl.h +++ b/ltt-sessiond/kernel-ctl.h @@ -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); diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index b0848eb45..75215b3f2 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -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); } } diff --git a/ltt-sessiond/session.c b/ltt-sessiond/session.c index a4101d2ee..be820ee55 100644 --- a/ltt-sessiond/session.c +++ b/ltt-sessiond/session.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #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: diff --git a/ltt-sessiond/trace.c b/ltt-sessiond/trace.c index 297d04f29..f59c96f3f 100644 --- a/ltt-sessiond/trace.c +++ b/ltt-sessiond/trace.c @@ -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; diff --git a/ltt-sessiond/trace.h b/ltt-sessiond/trace.h index 2c2f62ae0..43b67eae2 100644 --- a/ltt-sessiond/trace.h +++ b/ltt-sessiond/trace.h @@ -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); diff --git a/ltt-sessiond/utils.c b/ltt-sessiond/utils.c index 936d3e1b8..d099c0803 100644 --- a/ltt-sessiond/utils.c +++ b/ltt-sessiond/utils.c @@ -28,6 +28,22 @@ #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; diff --git a/ltt-sessiond/utils.h b/ltt-sessiond/utils.h index 564017df6..c0f5a4f9d 100644 --- a/ltt-sessiond/utils.h +++ b/ltt-sessiond/utils.h @@ -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 */ diff --git a/lttng/commands/create.c b/lttng/commands/create.c index 941f72355..e76316d21 100644 --- a/lttng/commands/create.c +++ b/lttng/commands/create.c @@ -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; diff --git a/lttng/conf.c b/lttng/conf.c index 9e3a626ba..1cf0907ad 100644 --- a/lttng/conf.c +++ b/lttng/conf.c @@ -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")); } /*