summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
8ce37aa)
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>
* Create a kernel channel, register it to the kernel tracer and add it to the
* kernel session.
*/
* 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 */
{
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;
}
if (lkc == NULL) {
goto error;
}
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_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);
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);
DBG("Creating default kernel channel %s", DEFAULT_CHANNEL_NAME);
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;
if (ret < 0) {
ret = LTTCOMM_KERN_CHAN_FAIL;
goto error;
DBG("Creating kernel channel");
ret = kernel_create_channel(cmd_ctx->session->kernel_session,
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;
if (ret < 0) {
ret = LTTCOMM_KERN_CHAN_FAIL;
goto error;
-/*
- * 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;
-}
-
{
int ret = 0;
void *status;
{
int ret = 0;
void *status;
/* Parse arguments */
progname = argv[0];
/* Parse arguments */
progname = argv[0];
/* Set ulimit for open files */
set_ulimit();
} else {
/* 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,
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,
}
/* 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);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <urcu/list.h>
#include "lttngerr.h"
#include <urcu/list.h>
#include "lttngerr.h"
int create_session(char *name, char *path)
{
int ret;
int create_session(char *name, char *path)
{
int ret;
+ char date_time[NAME_MAX];
struct ltt_session *new_session;
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) {
new_session = find_session_by_name(name);
if (new_session != NULL) {
/* Define session system path */
if (path != NULL) {
/* 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;
}
ret = -ENOMEM;
goto error_asprintf;
}
/* Add new session to the global session list */
add_session_list(new_session);
/* 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 pointer to structure or NULL.
*/
*
* 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;
{
int ret;
struct ltt_kernel_channel *lkc;
CDS_INIT_LIST_HEAD(&lkc->events_list.head);
CDS_INIT_LIST_HEAD(&lkc->stream_list.head);
/* Set default trace output path */
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;
if (ret < 0) {
perror("asprintf kernel create channel");
goto error;
* Create functions malloc() the data structure.
*/
struct ltt_kernel_session *trace_create_kernel_session(void);
* 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);
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);
+/*
+ * 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;
int mkdir_recursive(const char *path, mode_t mode)
{
int ret;
#define _LTT_UTILS_H
int mkdir_recursive(const char *path, mode_t mode);
#define _LTT_UTILS_H
int mkdir_recursive(const char *path, mode_t mode);
+const char *get_home_dir(void);
#endif /* _LTT_UTILS_H */
#endif /* _LTT_UTILS_H */
#include "cmd.h"
#include "conf.h"
#include "cmd.h"
#include "conf.h"
static char *opt_output_path;
static char *opt_session_name;
static char *opt_output_path;
static char *opt_session_name;
if (opt_output_path == NULL) {
alloc_path = config_get_default_path();
if (alloc_path == NULL) {
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;
}
ret = CMD_FATAL;
goto error;
}
}
MSG("Session %s created.", session_name);
}
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);
/*
* config_get_default_path
*
/*
* 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 *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"));