session->kernel_session->consumer;
snapshot_kernel_consumer_output =
consumer_copy_output(snapshot_output->consumer);
+ strcpy(snapshot_kernel_consumer_output->chunk_path,
+ snapshot_chunk_name);
ret = consumer_copy_sockets(snapshot_kernel_consumer_output,
original_kernel_consumer_output);
if (ret < 0) {
original_ust_consumer_output = session->ust_session->consumer;
snapshot_ust_consumer_output =
consumer_copy_output(snapshot_output->consumer);
+ strcpy(snapshot_ust_consumer_output->chunk_path,
+ snapshot_chunk_name);
ret = consumer_copy_sockets(snapshot_ust_consumer_output,
original_ust_consumer_output);
if (ret < 0) {
#include "utils.h"
#include "lttng-sessiond.h"
+/*
+ * Return allocated full pathname of the session using the consumer trace path
+ * and subdir if available.
+ *
+ * The caller can safely free(3) the returned value. On error, NULL is
+ * returned.
+ */
+char *setup_channel_trace_path(struct consumer_output *consumer,
+ const char *session_path)
+{
+ int ret;
+ char *pathname;
+
+ assert(consumer);
+ assert(session_path);
+
+ health_code_update();
+
+ /*
+ * Allocate the string ourself to make sure we never exceed
+ * LTTNG_PATH_MAX.
+ */
+ pathname = zmalloc(LTTNG_PATH_MAX);
+ if (!pathname) {
+ goto error;
+ }
+
+ /* Get correct path name destination */
+ if (consumer->type == CONSUMER_DST_NET &&
+ consumer->relay_major_version == 2 &&
+ consumer->relay_minor_version < 11) {
+ ret = snprintf(pathname, LTTNG_PATH_MAX, "%s%s/%s%s",
+ consumer->dst.net.base_dir,
+ consumer->chunk_path, consumer->domain_subdir,
+ session_path);
+ } else {
+ ret = snprintf(pathname, LTTNG_PATH_MAX, "%s%s",
+ consumer->domain_subdir, session_path);
+ }
+ DBG3("Consumer trace path relative to current trace chunk: \"%s\"",
+ pathname);
+ if (ret < 0) {
+ PERROR("Failed to format channel path");
+ goto error;
+ } else if (ret >= LTTNG_PATH_MAX) {
+ ERR("Truncation occurred while formatting channel path");
+ ret = -1;
+ goto error;
+ }
+
+ return pathname;
+error:
+ free(pathname);
+ return NULL;
+}
+
/*
* Send a data payload using a given consumer socket of size len.
*
struct lttng_trace_chunk *chunk,
enum consumer_trace_chunk_exists_status *result);
+char *setup_channel_trace_path(struct consumer_output *consumer,
+ const char *session_path);
+
#endif /* _CONSUMER_H */
struct consumer_socket *socket;
struct lttng_ht_iter iter;
struct ltt_kernel_metadata *saved_metadata;
+ char *trace_path = NULL;
assert(ksess);
assert(ksess->consumer);
goto error_open_stream;
}
+ trace_path = setup_channel_trace_path(ksess->consumer,
+ DEFAULT_KERNEL_TRACE_DIR);
+ if (!trace_path) {
+ status = LTTNG_ERR_INVALID;
+ goto error;
+ }
/* Send metadata to consumer and snapshot everything. */
cds_lfht_for_each_entry(output->socks->ht, &iter.iter,
socket, node.node) {
cds_list_for_each_entry(chan, &ksess->channel_list.head, list) {
status = consumer_snapshot_channel(socket, chan->key, output, 0,
ksess->uid, ksess->gid,
- DEFAULT_KERNEL_TRACE_DIR, wait,
+ trace_path, wait,
nb_packets_per_stream);
if (status != LTTNG_OK) {
(void) kernel_consumer_destroy_metadata(socket,
/* Snapshot metadata, */
status = consumer_snapshot_channel(socket, ksess->metadata->key, output,
- 1, ksess->uid, ksess->gid,
- DEFAULT_KERNEL_TRACE_DIR, wait, 0);
+ 1, ksess->uid, ksess->gid, trace_path, wait, 0);
if (status != LTTNG_OK) {
goto error_consumer;
}
ksess->metadata = saved_metadata;
ksess->metadata_stream_fd = saved_metadata_fd;
rcu_read_unlock();
+ free(trace_path);
return status;
}
enum lttng_error_code status = LTTNG_OK;
struct lttng_ht_iter iter;
struct ust_app *app;
- char pathname[PATH_MAX];
assert(usess);
assert(output);
cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) {
struct buffer_reg_channel *reg_chan;
struct consumer_socket *socket;
+ char *trace_path = NULL;
+ char pathname[PATH_MAX];
if (!reg->registry->reg.ust->metadata_key) {
/* Skip since no metadata is present */
status = LTTNG_ERR_INVALID;
goto error;
}
-
+ trace_path = setup_channel_trace_path(usess->consumer, pathname);
+ if (!trace_path) {
+ status = LTTNG_ERR_INVALID;
+ goto error;
+ }
/* Add the UST default trace dir to path. */
cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter,
reg_chan, node.node) {
status = consumer_snapshot_channel(socket,
reg_chan->consumer_key,
output, 0, usess->uid,
- usess->gid, pathname, wait,
+ usess->gid, trace_path, wait,
nb_packets_per_stream);
if (status != LTTNG_OK) {
+ free(trace_path);
goto error;
}
}
status = consumer_snapshot_channel(socket,
reg->registry->reg.ust->metadata_key, output, 1,
- usess->uid, usess->gid, pathname, wait, 0);
+ usess->uid, usess->gid, trace_path, wait, 0);
+ free(trace_path);
if (status != LTTNG_OK) {
goto error;
}
struct ust_app_channel *ua_chan;
struct ust_app_session *ua_sess;
struct ust_registry_session *registry;
+ char *trace_path = NULL;
+ char pathname[PATH_MAX];
ua_sess = lookup_session_by_app(usess, app);
if (!ua_sess) {
PERROR("snprintf snapshot path");
goto error;
}
-
+ trace_path = setup_channel_trace_path(usess->consumer, pathname);
+ if (!trace_path) {
+ status = LTTNG_ERR_INVALID;
+ goto error;
+ }
cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter,
ua_chan, node.node) {
status = consumer_snapshot_channel(socket,
.uid,
ua_sess->effective_credentials
.gid,
- pathname, wait,
+ trace_path, wait,
nb_packets_per_stream);
switch (status) {
case LTTNG_OK:
break;
case LTTNG_ERR_CHAN_NOT_FOUND:
+ free(trace_path);
continue;
default:
+ free(trace_path);
goto error;
}
}
registry->metadata_key, output, 1,
ua_sess->effective_credentials.uid,
ua_sess->effective_credentials.gid,
- pathname, wait, 0);
+ trace_path, wait, 0);
+ free(trace_path);
switch (status) {
case LTTNG_OK:
break;
#include "session.h"
#include "lttng-sessiond.h"
-/*
- * Return allocated full pathname of the session using the consumer trace path
- * and subdir if available.
- *
- * The caller can safely free(3) the returned value. On error, NULL is
- * returned.
- */
-static char *setup_channel_trace_path(struct consumer_output *consumer,
- struct ust_app_session *ua_sess)
-{
- int ret;
- char *pathname;
-
- assert(consumer);
- assert(ua_sess);
-
- health_code_update();
-
- /*
- * Allocate the string ourself to make sure we never exceed
- * LTTNG_PATH_MAX.
- */
- pathname = zmalloc(LTTNG_PATH_MAX);
- if (!pathname) {
- goto error;
- }
-
- /* Get correct path name destination */
- if (consumer->type == CONSUMER_DST_NET &&
- consumer->relay_major_version == 2 &&
- consumer->relay_minor_version < 11) {
- ret = snprintf(pathname, LTTNG_PATH_MAX, "%s%s/%s%s",
- consumer->dst.net.base_dir,
- consumer->chunk_path, consumer->domain_subdir,
- ua_sess->path);
- } else {
- ret = snprintf(pathname, LTTNG_PATH_MAX, "%s%s",
- consumer->domain_subdir, ua_sess->path);
- }
- DBG3("Userspace consumer trace path relative to current trace chunk: \"%s\"",
- pathname);
- if (ret < 0) {
- PERROR("Failed to format channel path");
- goto error;
- } else if (ret >= LTTNG_PATH_MAX) {
- ERR("Truncation occurred while formatting channel path");
- ret = -1;
- goto error;
- }
-
- return pathname;
-error:
- free(pathname);
- return NULL;
-}
-
/*
* Send a single channel to the consumer using command ASK_CHANNEL_CREATION.
*
is_local_trace = consumer->net_seq_index == -1ULL;
/* Format the channel's path (relative to the current trace chunk). */
- pathname = setup_channel_trace_path(consumer, ua_sess);
+ pathname = setup_channel_trace_path(consumer, ua_sess->path);
if (!pathname) {
ret = -1;
goto error;