From: David Goulet Date: Fri, 12 Apr 2013 15:13:42 +0000 (-0400) Subject: Fix: remove unused path variables from session obj X-Git-Tag: v2.2.0-rc2~43 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=dec56f6cc894de41b312354d360b6a4c09fc199d;p=lttng-tools.git Fix: remove unused path variables from session obj Furthermore, this patch also removes useless '/' in the stream path which was creating duplicates in the trace file path. Fixes #496 Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c index bb5b3d1de..db653dcb4 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.c @@ -293,7 +293,7 @@ int channel_ust_create(struct ltt_ust_session *usess, } /* Create UST channel */ - uchan = trace_ust_create_channel(attr, usess->pathname); + uchan = trace_ust_create_channel(attr); if (uchan == NULL) { ret = LTTNG_ERR_FATAL; goto error; diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 7819002d0..4fcd6a4fe 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1667,7 +1667,6 @@ int cmd_create_session_uri(char *name, struct lttng_uri *uris, size_t nb_uri, lttng_sock_cred *creds) { int ret; - char *path = NULL; struct ltt_session *session; assert(name); @@ -1692,7 +1691,7 @@ int cmd_create_session_uri(char *name, struct lttng_uri *uris, } /* Create tracing session in the registry */ - ret = session_create(name, path, LTTNG_SOCK_GET_UID_CRED(creds), + ret = session_create(name, LTTNG_SOCK_GET_UID_CRED(creds), LTTNG_SOCK_GET_GID_CRED(creds)); if (ret != LTTNG_OK) { goto session_error; @@ -2066,9 +2065,9 @@ void cmd_list_lttng_sessions(struct lttng_session *sessions, uid_t uid, (ksess && ksess->consumer->type == CONSUMER_DST_NET) || (usess && usess->consumer->type == CONSUMER_DST_NET)) { ret = build_network_session_path(sessions[i].path, - sizeof(session[i].path), session); + sizeof(sessions[i].path), session); } else { - ret = snprintf(sessions[i].path, sizeof(session[i].path), "%s", + ret = snprintf(sessions[i].path, sizeof(sessions[i].path), "%s", session->consumer->dst.trace_path); } if (ret < 0) { diff --git a/src/bin/lttng-sessiond/kernel-consumer.c b/src/bin/lttng-sessiond/kernel-consumer.c index 05e30e49c..f30c11ccc 100644 --- a/src/bin/lttng-sessiond/kernel-consumer.c +++ b/src/bin/lttng-sessiond/kernel-consumer.c @@ -54,7 +54,7 @@ int kernel_consumer_add_channel(struct consumer_socket *sock, /* Get the right path name destination */ if (consumer->type == CONSUMER_DST_LOCAL) { /* Set application path to the destination path */ - ret = snprintf(tmp_path, sizeof(tmp_path), "%s/%s", + ret = snprintf(tmp_path, sizeof(tmp_path), "%s%s", consumer->dst.trace_path, consumer->subdir); if (ret < 0) { PERROR("snprintf metadata path"); @@ -136,7 +136,7 @@ int kernel_consumer_add_metadata(struct consumer_socket *sock, /* Get the right path name destination */ if (consumer->type == CONSUMER_DST_LOCAL) { /* Set application path to the destination path */ - ret = snprintf(tmp_path, sizeof(tmp_path), "%s/%s", + ret = snprintf(tmp_path, sizeof(tmp_path), "%s%s", consumer->dst.trace_path, consumer->subdir); if (ret < 0) { PERROR("snprintf metadata path"); diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 951941132..856d42310 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -81,7 +81,7 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd) assert(session); /* Allocate data structure */ - lks = trace_kernel_create_session(session->path); + lks = trace_kernel_create_session(); if (lks == NULL) { ret = -1; goto error; diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 15bb7255a..f6a051aa1 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2238,7 +2238,7 @@ static int create_ust_session(struct ltt_session *session, DBG("Creating UST session"); - lus = trace_ust_create_session(session->path, session->id); + lus = trace_ust_create_session(session->id); if (lus == NULL) { ret = LTTNG_ERR_UST_SESS_FAIL; goto error; diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index 076d2cbc4..17dc3544d 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -168,7 +168,7 @@ int session_destroy(struct ltt_session *session) /* * Create a brand new session and add it to the session list. */ -int session_create(char *name, char *path, uid_t uid, gid_t gid) +int session_create(char *name, uid_t uid, gid_t gid) { int ret; struct ltt_session *new_session; @@ -193,14 +193,6 @@ int session_create(char *name, char *path, uid_t uid, gid_t gid) goto error; } - /* Define session system path */ - if (path != NULL) { - if (snprintf(new_session->path, PATH_MAX, "%s", path) < 0) { - ret = LTTNG_ERR_FATAL; - goto error_asprintf; - } - } - /* Init kernel session */ new_session->kernel_session = NULL; new_session->ust_session = NULL; @@ -211,19 +203,6 @@ int session_create(char *name, char *path, uid_t uid, gid_t gid) new_session->uid = uid; new_session->gid = gid; - /* Mkdir if we have a valid path and length */ - if (strlen(new_session->path) > 0) { - ret = run_as_mkdir_recursive(new_session->path, S_IRWXU | S_IRWXG, - new_session->uid, new_session->gid); - if (ret < 0) { - if (ret != -EEXIST) { - ERR("Trace directory creation error"); - ret = LTTNG_ERR_CREATE_DIR_FAIL; - goto error; - } - } - } - /* Add new session to the session list */ session_lock_list(); new_session->id = add_session_list(new_session); @@ -234,8 +213,8 @@ int session_create(char *name, char *path, uid_t uid, gid_t gid) * up and, if valid, assign it to the session. */ - DBG("Tracing session %s created in %s with ID %u by UID %d GID %d", name, - path, new_session->id, new_session->uid, new_session->gid); + DBG("Tracing session %s created with ID %u by UID %d GID %d", name, + new_session->id, new_session->uid, new_session->gid); return LTTNG_OK; diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index fd23ab05e..a0b24b2d7 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -56,7 +56,6 @@ struct ltt_session_list { */ struct ltt_session { char name[NAME_MAX]; - char path[PATH_MAX]; struct ltt_kernel_session *kernel_session; struct ltt_ust_session *ust_session; /* @@ -89,7 +88,7 @@ struct ltt_session { }; /* Prototypes */ -int session_create(char *name, char *path, uid_t uid, gid_t gid); +int session_create(char *name, uid_t uid, gid_t gid); int session_destroy(struct ltt_session *session); void session_lock(struct ltt_session *session); diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 6a17776aa..afb578cfd 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -77,7 +77,7 @@ struct ltt_kernel_event *trace_kernel_get_event_by_name( * * Return pointer to structure or NULL. */ -struct ltt_kernel_session *trace_kernel_create_session(char *path) +struct ltt_kernel_session *trace_kernel_create_session(void) { struct ltt_kernel_session *lks = NULL; @@ -109,25 +109,6 @@ struct ltt_kernel_session *trace_kernel_create_session(char *path) */ lks->tmp_consumer = NULL; - if (*path != '\0') { - int ret; - - /* Use the default consumer output which is the tracing session path. */ - ret = snprintf(lks->consumer->dst.trace_path, PATH_MAX, - "%s" DEFAULT_KERNEL_TRACE_DIR, path); - if (ret < 0) { - PERROR("snprintf consumer trace path"); - goto error; - } - - /* Set session path */ - ret = asprintf(&lks->trace_path, "%s" DEFAULT_KERNEL_TRACE_DIR, path); - if (ret < 0) { - PERROR("asprintf kernel traces path"); - goto error; - } - } - return lks; error: @@ -477,6 +458,5 @@ void trace_kernel_destroy_session(struct ltt_kernel_session *session) consumer_destroy_output(session->consumer); consumer_destroy_output(session->tmp_consumer); - free(session->trace_path); free(session); } diff --git a/src/bin/lttng-sessiond/trace-kernel.h b/src/bin/lttng-sessiond/trace-kernel.h index 87807d989..d1f6e5f00 100644 --- a/src/bin/lttng-sessiond/trace-kernel.h +++ b/src/bin/lttng-sessiond/trace-kernel.h @@ -94,7 +94,6 @@ struct ltt_kernel_session { int consumer_fds_sent; unsigned int channel_count; unsigned int stream_count_global; - char *trace_path; struct ltt_kernel_metadata *metadata; struct ltt_kernel_channel_list channel_list; /* UID/GID of the user owning the session */ @@ -125,7 +124,7 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name( /* * Create functions malloc() the data structure. */ -struct ltt_kernel_session *trace_kernel_create_session(char *path); +struct ltt_kernel_session *trace_kernel_create_session(void); struct ltt_kernel_channel *trace_kernel_create_channel( struct lttng_channel *chan); struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev); diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index cd8ff1053..0c97d37f1 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -180,8 +180,7 @@ error: * * Return pointer to structure or NULL. */ -struct ltt_ust_session *trace_ust_create_session(char *path, - unsigned int session_id) +struct ltt_ust_session *trace_ust_create_session(unsigned int session_id) { struct ltt_ust_session *lus; @@ -224,24 +223,10 @@ struct ltt_ust_session *trace_ust_create_session(char *path, */ lus->tmp_consumer = NULL; - /* Use the default consumer output which is the tracing session path. */ - if (*path != '\0') { - int ret; - - ret = snprintf(lus->consumer->dst.trace_path, PATH_MAX, - "%s" DEFAULT_UST_TRACE_DIR, path); - if (ret < 0) { - PERROR("snprintf UST consumer trace path"); - goto error_path; - } - } - DBG2("UST trace session create successful"); return lus; -error_path: - consumer_destroy_output(lus->consumer); error_consumer: lttng_ht_destroy(lus->domain_global.channels); free(lus); @@ -254,13 +239,11 @@ error: * * Return pointer to structure or NULL. */ -struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan, - char *path) +struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan) { struct ltt_ust_channel *luc; assert(chan); - assert(path); luc = zmalloc(sizeof(struct ltt_ust_channel)); if (luc == NULL) { diff --git a/src/bin/lttng-sessiond/trace-ust.h b/src/bin/lttng-sessiond/trace-ust.h index 92d6aaaf4..b21d8c2a7 100644 --- a/src/bin/lttng-sessiond/trace-ust.h +++ b/src/bin/lttng-sessiond/trace-ust.h @@ -54,7 +54,6 @@ struct ltt_ust_channel { uint64_t id; /* unique id per session. */ unsigned int enabled; char name[LTTNG_UST_SYM_NAME_LEN]; - char pathname[PATH_MAX]; struct lttng_ust_channel_attr attr; struct lttng_ht *ctx; struct lttng_ht *events; @@ -82,7 +81,6 @@ struct ltt_ust_domain_global { struct ltt_ust_session { int id; /* Unique identifier of session */ int start_trace; - char pathname[PATH_MAX]; struct ltt_ust_domain_global domain_global; /* UID/GID of the user owning the session */ uid_t uid; @@ -155,10 +153,8 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, /* * Create functions malloc() the data structure. */ -struct ltt_ust_session *trace_ust_create_session(char *path, - unsigned int session_id); -struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, - char *path); +struct ltt_ust_session *trace_ust_create_session(unsigned int session_id); +struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr); struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev, struct lttng_filter_bytecode *filter); struct ltt_ust_metadata *trace_ust_create_metadata(char *path); @@ -194,14 +190,12 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, } static inline -struct ltt_ust_session *trace_ust_create_session(char *path, - unsigned int session_id) +struct ltt_ust_session *trace_ust_create_session(unsigned int session_id) { return NULL; } static inline -struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, - char *path) +struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr) { return NULL; } diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 8016d8ba5..9bd622d87 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -1381,7 +1381,7 @@ static void shadow_copy_session(struct ust_app_session *ua_sess, switch (ua_sess->buffer_type) { case LTTNG_BUFFER_PER_PID: ret = snprintf(ua_sess->path, sizeof(ua_sess->path), - DEFAULT_UST_TRACE_PID_PATH "/%s-%d-%s/", app->name, app->pid, + DEFAULT_UST_TRACE_PID_PATH "/%s-%d-%s", app->name, app->pid, datetime); break; case LTTNG_BUFFER_PER_UID: diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.c index 93c1f7135..ca96ff727 100644 --- a/src/bin/lttng-sessiond/ust-consumer.c +++ b/src/bin/lttng-sessiond/ust-consumer.c @@ -61,7 +61,7 @@ static char *setup_trace_path(struct consumer_output *consumer, /* Get correct path name destination */ if (consumer->type == CONSUMER_DST_LOCAL) { /* Set application path to the destination path */ - ret = snprintf(pathname, PATH_MAX, "%s/%s/%s", + ret = snprintf(pathname, PATH_MAX, "%s%s%s", consumer->dst.trace_path, consumer->subdir, ua_sess->path); if (ret < 0) { PERROR("snprintf channel path"); @@ -78,7 +78,7 @@ static char *setup_trace_path(struct consumer_output *consumer, } } } else { - ret = snprintf(pathname, PATH_MAX, "%s/%s", consumer->subdir, + ret = snprintf(pathname, PATH_MAX, "%s%s", consumer->subdir, ua_sess->path); if (ret < 0) { PERROR("snprintf channel path"); diff --git a/tests/unit/test_kernel_data.c b/tests/unit/test_kernel_data.c index f36874564..0b4bb08c9 100644 --- a/tests/unit/test_kernel_data.c +++ b/tests/unit/test_kernel_data.c @@ -30,9 +30,6 @@ #include -/* This path will NEVER be created in this test */ -#define PATH1 "/tmp/.test-junk-lttng" - #define RANDOM_STRING_LEN 11 /* Number of TAP tests in this file */ @@ -72,7 +69,7 @@ static char *get_random_string(void) static void test_create_one_kernel_session(void) { - kern = trace_kernel_create_session(PATH1); + kern = trace_kernel_create_session(); ok(kern != NULL, "Create kernel session"); ok(kern->fd == -1 && diff --git a/tests/unit/test_session.c b/tests/unit/test_session.c index 61db187f1..8e1da2148 100644 --- a/tests/unit/test_session.c +++ b/tests/unit/test_session.c @@ -35,14 +35,11 @@ #define SESSION1 "test1" -/* This path will NEVER be created in this test */ -#define PATH1 "/tmp/.test-junk-lttng" - #define MAX_SESSIONS 10000 #define RANDOM_STRING_LEN 11 /* Number of TAP tests in this file */ -#define NUM_TESTS 12 +#define NUM_TESTS 11 static struct ltt_session_list *session_list; @@ -122,11 +119,11 @@ static void empty_session_list(void) /* * Test creation of 1 session */ -static int create_one_session(char *name, char *path) +static int create_one_session(char *name) { int ret; - ret = session_create(name, path, geteuid(), getegid()); + ret = session_create(name, geteuid(), getegid()); if (ret == LTTNG_OK) { /* Validate */ ret = find_session_name(name); @@ -184,7 +181,7 @@ static int two_session_same_name(void) int ret; struct ltt_session *sess; - ret = create_one_session(SESSION1, PATH1); + ret = create_one_session(SESSION1); if (ret < 0) { /* Fail */ return -1; @@ -208,7 +205,7 @@ void test_session_list(void) void test_create_one_session(void) { - ok(create_one_session(SESSION1, PATH1) == 0, + ok(create_one_session(SESSION1) == 0, "Create session: %s", SESSION1); } @@ -223,7 +220,6 @@ void test_validate_session(void) "Validating session: session found"); ok(tmp->kernel_session == NULL && - strlen(tmp->path) && strlen(tmp->name), "Validating session: basic sanity check"); @@ -253,12 +249,8 @@ void test_duplicate_session(void) void test_bogus_session_param(void) { - ok(create_one_session(NULL, NULL) < 0, - "Create session with bogus param: NULL, NULL should fail"); - - ok(create_one_session(NULL, PATH1) < 0, - "Create session with bogus param: NULL, %s should fail", - PATH1); + ok(create_one_session(NULL) < 0, + "Create session with bogus param: NULL should fail"); ok(session_list_count() == 0, "Create session with bogus param: session list empty"); @@ -271,7 +263,7 @@ void test_large_session_number(void) for (i = 0; i < MAX_SESSIONS; i++) { char *tmp_name = get_random_string(); - ret = create_one_session(tmp_name, PATH1); + ret = create_one_session(tmp_name); if (ret < 0) { diag("session %d (name: %s) creation failed", i, tmp_name); ++failed; diff --git a/tests/unit/test_ust_data.c b/tests/unit/test_ust_data.c index 294b5c589..a79e2eb58 100644 --- a/tests/unit/test_ust_data.c +++ b/tests/unit/test_ust_data.c @@ -80,7 +80,7 @@ static void test_create_one_ust_session(void) { dom.type = LTTNG_DOMAIN_UST; - usess = trace_ust_create_session(PATH1, 42); + usess = trace_ust_create_session(42); ok(usess != NULL, "Create UST session"); ok(usess->id == 42 && @@ -129,7 +129,7 @@ static void test_create_ust_channel(void) strncpy(attr.name, "channel0", 8); - uchan = trace_ust_create_channel(&attr, PATH1); + uchan = trace_ust_create_channel(&attr); ok(uchan != NULL, "Create UST channel"); ok(uchan->enabled == 0 &&