From: David Goulet Date: Fri, 28 Jun 2013 14:54:44 +0000 (-0400) Subject: Fix: snapshot path X-Git-Tag: v2.3.0-rc1~98 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ee91bab210156bd9a4ec23eac93aa563556f2803;p=lttng-tools.git Fix: snapshot path Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 1b7a39733..8198629f3 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "consumer.h" #include "health.h" @@ -1192,9 +1193,10 @@ end: */ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, struct snapshot_output *output, int metadata, uid_t uid, gid_t gid, - int wait) + const char *session_path, int wait) { int ret; + char datetime[16]; struct lttcomm_consumer_msg msg; assert(socket); @@ -1204,8 +1206,14 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, DBG("Consumer snapshot channel key %" PRIu64, key); - memset(&msg, 0, sizeof(msg)); + ret = utils_get_current_time_str("%Y%m%d-%H%M%S", datetime, + sizeof(datetime)); + if (!ret) { + ret = -EINVAL; + goto error; + } + memset(&msg, 0, sizeof(msg)); msg.cmd_type = LTTNG_CONSUMER_SNAPSHOT_CHANNEL; msg.u.snapshot_channel.key = key; msg.u.snapshot_channel.max_size = output->max_size; @@ -1215,16 +1223,18 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, msg.u.snapshot_channel.relayd_id = output->consumer->net_seq_index; msg.u.snapshot_channel.use_relayd = 1; ret = snprintf(msg.u.snapshot_channel.pathname, - sizeof(msg.u.snapshot_channel.pathname), "%s/%s", - output->consumer->subdir, DEFAULT_SNAPSHOT_NAME); + sizeof(msg.u.snapshot_channel.pathname), "%s/%s-%s%s", + output->consumer->subdir, output->name, datetime, + session_path); if (ret < 0) { ret = -LTTNG_ERR_NOMEM; goto error; } } else { ret = snprintf(msg.u.snapshot_channel.pathname, - sizeof(msg.u.snapshot_channel.pathname), "%s/%s", - output->consumer->dst.trace_path, DEFAULT_SNAPSHOT_NAME); + sizeof(msg.u.snapshot_channel.pathname), "%s/%s-%s%s", + output->consumer->dst.trace_path, output->name, datetime, + session_path); if (ret < 0) { ret = -LTTNG_ERR_NOMEM; goto error; diff --git a/src/bin/lttng-sessiond/consumer.h b/src/bin/lttng-sessiond/consumer.h index a954a073e..4d8f66a72 100644 --- a/src/bin/lttng-sessiond/consumer.h +++ b/src/bin/lttng-sessiond/consumer.h @@ -247,6 +247,6 @@ int consumer_flush_channel(struct consumer_socket *socket, uint64_t key); /* Snapshot command. */ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, struct snapshot_output *output, int metadata, uid_t uid, gid_t gid, - int wait); + const char *session_path, int wait); #endif /* _CONSUMER_H */ diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 1ba6b16e6..6f2604c60 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -883,7 +883,7 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, cds_list_for_each_entry(chan, &ksess->channel_list.head, list) { pthread_mutex_lock(socket->lock); ret = consumer_snapshot_channel(socket, chan->fd, output, 0, - ksess->uid, ksess->gid, wait); + ksess->uid, ksess->gid, DEFAULT_KERNEL_TRACE_DIR, wait); pthread_mutex_unlock(socket->lock); if (ret < 0) { ret = LTTNG_ERR_KERN_CONSUMER_FAIL; @@ -894,7 +894,7 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, /* Snapshot metadata, */ pthread_mutex_lock(socket->lock); ret = consumer_snapshot_channel(socket, ksess->metadata->fd, output, - 1, ksess->uid, ksess->gid, wait); + 1, ksess->uid, ksess->gid, DEFAULT_KERNEL_TRACE_DIR, wait); pthread_mutex_unlock(socket->lock); if (ret < 0) { ret = LTTNG_ERR_KERN_CONSUMER_FAIL; diff --git a/src/bin/lttng-sessiond/snapshot.c b/src/bin/lttng-sessiond/snapshot.c index 77255fa2c..ba7cdff2c 100644 --- a/src/bin/lttng-sessiond/snapshot.c +++ b/src/bin/lttng-sessiond/snapshot.c @@ -55,7 +55,7 @@ int snapshot_output_init(uint64_t max_size, const char *name, } lttng_ht_node_init_ulong(&output->node, (unsigned long) output->id); - if (name) { + if (name && name[0] != '\0') { strncpy(output->name, name, sizeof(output->name)); } else { /* Set default name. */ diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 56cbb8578..e457cae68 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -4889,7 +4889,7 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess, cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter, ua_chan, node.node) { ret = consumer_snapshot_channel(socket, ua_chan->key, output, 0, - ua_sess->euid, ua_sess->egid, wait); + ua_sess->euid, ua_sess->egid, ua_sess->path, wait); if (ret < 0) { goto error; } @@ -4898,7 +4898,7 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess, registry = get_session_registry(ua_sess); assert(registry); ret = consumer_snapshot_channel(socket, registry->metadata_key, output, - 1, ua_sess->euid, ua_sess->egid, wait); + 1, ua_sess->euid, ua_sess->egid, ua_sess->path, wait); if (ret < 0) { goto error; }