#include <common/utils.h>
#include <common/compat/string.h>
#include <common/kernel-ctl/kernel-ctl.h>
+#include <common/dynamic-buffer.h>
+#include <common/buffer-view.h>
+#include <lttng/trigger/trigger-internal.h>
+#include <lttng/condition/condition.h>
+#include <lttng/action/action.h>
+#include <lttng/channel.h>
+#include <lttng/channel-internal.h>
+#include <common/string-utils/string-utils.h>
#include "channel.h"
#include "consumer.h"
#include "syscall.h"
#include "agent.h"
#include "buffer-registry.h"
+#include "notification-thread.h"
+#include "notification-thread-commands.h"
+#include "rotation-thread.h"
#include "cmd.h"
static pthread_mutex_t relayd_net_seq_idx_lock = PTHREAD_MUTEX_INITIALIZER;
static uint64_t relayd_net_seq_idx;
-static int validate_event_name(const char *);
static int validate_ust_event_name(const char *);
static int cmd_enable_event_internal(struct ltt_session *session,
struct lttng_domain *domain,
/*
* Fill lttng_channel array of all channels.
*/
-static void list_lttng_channels(enum lttng_domain_type domain,
+static ssize_t list_lttng_channels(enum lttng_domain_type domain,
struct ltt_session *session, struct lttng_channel *channels,
- struct lttcomm_channel_extended *chan_exts)
+ struct lttng_channel_extended *chan_exts)
{
- int i = 0, ret;
+ int i = 0, ret = 0;
struct ltt_kernel_channel *kchan;
DBG("Listing channels for session %s", session->name);
cds_list_for_each_entry(kchan,
&session->kernel_session->channel_list.head, list) {
uint64_t discarded_events, lost_packets;
+ struct lttng_channel_extended *extended;
+
+ extended = (struct lttng_channel_extended *)
+ kchan->channel->attr.extended.ptr;
ret = get_kernel_runtime_stats(session, kchan,
&discarded_events, &lost_packets);
chan_exts[i].discarded_events =
discarded_events;
chan_exts[i].lost_packets = lost_packets;
+ chan_exts[i].monitor_timer_interval =
+ extended->monitor_timer_interval;
+ chan_exts[i].blocking_timeout = 0;
i++;
}
}
break;
}
+ chan_exts[i].monitor_timer_interval =
+ uchan->monitor_timer_interval;
+ chan_exts[i].blocking_timeout =
+ uchan->attr.u.s.blocking_timeout;
+
ret = get_ust_runtime_stats(session, uchan,
&discarded_events, &lost_packets);
if (ret < 0) {
}
end:
- return;
+ if (ret < 0) {
+ return -LTTNG_ERR_FATAL;
+ } else {
+ return LTTNG_OK;
+ }
}
static void increment_extended_len(const char *filter_expression,
break;
case LTTNG_DST_PATH:
DBG2("Setting trace directory path from URI to %s", uri->dst.path);
- memset(consumer->dst.trace_path, 0,
- sizeof(consumer->dst.trace_path));
+ memset(consumer->dst.session_root_path, 0,
+ sizeof(consumer->dst.session_root_path));
/* Explicit length checks for strcpy and strcat. */
if (strlen(uri->dst.path) + strlen(default_trace_dir)
- >= sizeof(consumer->dst.trace_path)) {
+ >= sizeof(consumer->dst.session_root_path)) {
ret = LTTNG_ERR_FATAL;
goto error;
}
- strcpy(consumer->dst.trace_path, uri->dst.path);
+ strcpy(consumer->dst.session_root_path, uri->dst.path);
/* Append default trace dir */
- strcat(consumer->dst.trace_path, default_trace_dir);
+ strcat(consumer->dst.session_root_path, default_trace_dir);
/* Flag consumer as local. */
consumer->type = CONSUMER_DST_LOCAL;
break;
attr->attr.switch_timer_interval = 0;
}
+ /* Check for feature support */
+ switch (domain->type) {
+ case LTTNG_DOMAIN_KERNEL:
+ {
+ if (kernel_supports_ring_buffer_snapshot_sample_positions(kernel_tracer_fd) != 1) {
+ /* Sampling position of buffer is not supported */
+ WARN("Kernel tracer does not support buffer monitoring. "
+ "Setting the monitor interval timer to 0 "
+ "(disabled) for channel '%s' of session '%s'",
+ attr-> name, session->name);
+ lttng_channel_set_monitor_timer_interval(attr, 0);
+ }
+ break;
+ }
+ case LTTNG_DOMAIN_UST:
+ case LTTNG_DOMAIN_JUL:
+ case LTTNG_DOMAIN_LOG4J:
+ case LTTNG_DOMAIN_PYTHON:
+ break;
+ default:
+ ret = LTTNG_ERR_UNKNOWN_DOMAIN;
+ goto error;
+ }
+
switch (domain->type) {
case LTTNG_DOMAIN_KERNEL:
{
DBG("Disable event command for event \'%s\'", event->name);
event_name = event->name;
- if (validate_event_name(event_name)) {
- ret = LTTNG_ERR_INVALID_EVENT_NAME;
- goto error;
- }
/* Error out on unhandled search criteria */
if (event->loglevel_type || event->loglevel != -1 || event->enabled
free(attr);
goto error;
}
- free(attr);
+ channel_attr_destroy(attr);
chan_ust_created = 1;
}
return ret;
}
-static int validate_event_name(const char *name)
-{
- int ret = 0;
- const char *c = name;
- const char *event_name_end = c + LTTNG_SYMBOL_NAME_LEN;
- bool null_terminated = false;
-
- /*
- * Make sure that unescaped wildcards are only used as the last
- * character of the event name.
- */
- while (c < event_name_end) {
- switch (*c) {
- case '\0':
- null_terminated = true;
- goto end;
- case '\\':
- c++;
- break;
- case '*':
- if ((c + 1) < event_name_end && *(c + 1)) {
- /* Wildcard is not the last character */
- ret = LTTNG_ERR_INVALID_EVENT_NAME;
- goto end;
- }
- default:
- break;
- }
- c++;
- }
-end:
- if (!ret && !null_terminated) {
- ret = LTTNG_ERR_INVALID_EVENT_NAME;
- }
- return ret;
-}
-
static inline bool name_starts_with(const char *name, const char *prefix)
{
const size_t max_cmp_len = min(strlen(prefix), LTTNG_SYMBOL_NAME_LEN);
struct lttng_event_exclusion *exclusion,
int wpipe, bool internal_event)
{
- int ret, channel_created = 0;
+ int ret = 0, channel_created = 0;
struct lttng_channel *attr = NULL;
assert(session);
/* If we have a filter, we must have its filter expression */
assert(!(!!filter_expression ^ !!filter));
- DBG("Enable event command for event \'%s\'", event->name);
+ /* Normalize event name as a globbing pattern */
+ strutils_normalize_star_glob_pattern(event->name);
- rcu_read_lock();
+ /* Normalize exclusion names as globbing patterns */
+ if (exclusion) {
+ size_t i;
- ret = validate_event_name(event->name);
- if (ret) {
- goto error;
+ for (i = 0; i < exclusion->count; i++) {
+ char *name = LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, i);
+
+ strutils_normalize_star_glob_pattern(name);
+ }
}
+ DBG("Enable event command for event \'%s\'", event->name);
+
+ rcu_read_lock();
+
switch (domain->type) {
case LTTNG_DOMAIN_KERNEL:
{
free(filter_expression);
free(filter);
free(exclusion);
- free(attr);
+ channel_attr_destroy(attr);
rcu_read_unlock();
return ret;
}
goto error;
}
+ /*
+ * Record the timestamp of the first time the session is started for
+ * an eventual session rotation call.
+ */
+ if (!session->has_been_started) {
+ session->session_start_ts = time(NULL);
+ if (session->session_start_ts == (time_t) -1) {
+ PERROR("Get start time");
+ ret = LTTNG_ERR_FATAL;
+ goto error;
+ }
+ }
+
/* Kernel tracing */
if (ksession != NULL) {
ret = start_kernel_session(ksession, kernel_tracer_fd);
}
}
+ session->session_last_stop_ts = time(NULL);
+
/* Flag inactive after a successful stop. */
session->active = 0;
ret = LTTNG_OK;
trace_ust_destroy_session(usess);
}
+ if (session->rotate_count > 0) {
+ session->rotate_count++;
+ /*
+ * The currently active tracing path is now the folder we
+ * want to rename.
+ */
+ snprintf(session->rotation_chunk.current_rotate_path,
+ PATH_MAX, "%s",
+ session->rotation_chunk.active_tracing_path);
+ ret = rename_complete_chunk(session,
+ session->session_last_stop_ts);
+ if (ret < 0) {
+ ERR("Renaming session on destroy");
+ }
+ }
+
/*
* Must notify the kernel thread here to update it's poll set in order to
* remove the channel(s)' fd just destroyed.
return ret;
}
-/*
- * Command LTTNG_CALIBRATE processed by the client thread.
- */
-int cmd_calibrate(enum lttng_domain_type domain,
- struct lttng_calibrate *calibrate)
-{
- int ret;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- {
- struct lttng_kernel_calibrate kcalibrate;
-
- switch (calibrate->type) {
- case LTTNG_CALIBRATE_FUNCTION:
- default:
- /* Default and only possible calibrate option. */
- kcalibrate.type = LTTNG_KERNEL_CALIBRATE_KRETPROBE;
- break;
- }
-
- ret = kernel_calibrate(kernel_tracer_fd, &kcalibrate);
- if (ret < 0) {
- ret = LTTNG_ERR_KERN_ENABLE_FAIL;
- goto error;
- }
- break;
- }
- case LTTNG_DOMAIN_UST:
- {
- struct lttng_ust_calibrate ucalibrate;
-
- switch (calibrate->type) {
- case LTTNG_CALIBRATE_FUNCTION:
- default:
- /* Default and only possible calibrate option. */
- ucalibrate.type = LTTNG_UST_CALIBRATE_TRACEPOINT;
- break;
- }
-
- ret = ust_app_calibrate_glb(&ucalibrate);
- if (ret < 0) {
- ret = LTTNG_ERR_UST_CALIBRATE_FAIL;
- goto error;
- }
- break;
- }
- default:
- ret = LTTNG_ERR_UND;
- goto error;
- }
-
- ret = LTTNG_OK;
-
-error:
- return ret;
-}
-
/*
* Command LTTNG_REGISTER_CONSUMER processed by the client thread.
*/
if (nb_chan > 0) {
const size_t channel_size = sizeof(struct lttng_channel) +
- sizeof(struct lttcomm_channel_extended);
- struct lttcomm_channel_extended *channel_exts;
+ sizeof(struct lttng_channel_extended);
+ struct lttng_channel_extended *channel_exts;
payload_size = nb_chan * channel_size;
*channels = zmalloc(payload_size);
channel_exts = ((void *) *channels) +
(nb_chan * sizeof(struct lttng_channel));
- list_lttng_channels(domain, session, *channels, channel_exts);
+ ret = list_lttng_channels(domain, session, *channels, channel_exts);
+ if (ret != LTTNG_OK) {
+ free(*channels);
+ *channels = NULL;
+ goto end;
+ }
} else {
*channels = NULL;
}
sizeof(sessions[i].path), session);
} else {
ret = snprintf(sessions[i].path, sizeof(sessions[i].path), "%s",
- session->consumer->dst.trace_path);
+ session->consumer->dst.session_root_path);
}
if (ret < 0) {
PERROR("snprintf session path");
DBG("Cmd snapshot add output for session %s", session->name);
/*
- * Permission denied to create an output if the session is not
- * set in no output mode.
+ * Can't create an output if the session is not set in no-output mode.
*/
if (session->output_traces) {
- ret = LTTNG_ERR_EPERM;
+ ret = LTTNG_ERR_NOT_SNAPSHOT_SESSION;
goto error;
}
* set in no output mode.
*/
if (session->output_traces) {
- ret = LTTNG_ERR_EPERM;
+ ret = LTTNG_ERR_NOT_SNAPSHOT_SESSION;
goto error;
}
* set in no output mode.
*/
if (session->output_traces) {
- ret = -LTTNG_ERR_EPERM;
- goto error;
+ ret = -LTTNG_ERR_NOT_SNAPSHOT_SESSION;
+ goto end;
}
if (session->snapshot.nb_output == 0) {
ret = 0;
- goto error;
+ goto end;
}
list = zmalloc(session->snapshot.nb_output * sizeof(*list));
if (!list) {
ret = -LTTNG_ERR_NOMEM;
- goto error;
+ goto end;
}
/* Copy list from session to the new list object. */
}
if (output->consumer->type == CONSUMER_DST_LOCAL) {
if (lttng_strncpy(list[idx].ctrl_url,
- output->consumer->dst.trace_path,
+ output->consumer->dst.session_root_path,
sizeof(list[idx].ctrl_url))) {
ret = -LTTNG_ERR_INVALID;
goto error;
list = NULL;
ret = session->snapshot.nb_output;
error:
- free(list);
rcu_read_unlock();
+ free(list);
+end:
return ret;
}
return ret;
}
+static
+int clear_metadata_file(int fd)
+{
+ int ret;
+
+ ret = lseek(fd, 0, SEEK_SET);
+ if (ret < 0) {
+ PERROR("lseek");
+ goto end;
+ }
+
+ ret = ftruncate(fd, 0);
+ if (ret < 0) {
+ PERROR("ftruncate");
+ goto end;
+ }
+
+end:
+ return ret;
+}
+
static
int ust_regenerate_metadata(struct ltt_ust_session *usess)
{
memset(registry->metadata, 0, registry->metadata_alloc_len);
registry->metadata_len = 0;
registry->metadata_version++;
+ if (registry->metadata_fd > 0) {
+ /* Clear the metadata file's content. */
+ ret = clear_metadata_file(registry->metadata_fd);
+ if (ret) {
+ pthread_mutex_unlock(®istry->lock);
+ goto end;
+ }
+ }
+
ret = ust_metadata_session_statedump(registry, NULL,
registry->major, registry->minor);
if (ret) {
ret = LTTNG_ERR_SESSION_NOT_STARTED;
goto end;
}
- ret = 0;
if (session->kernel_session) {
ret = kernctl_session_regenerate_statedump(
return ret;
}
+int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock,
+ struct notification_thread_handle *notification_thread)
+{
+ int ret;
+ size_t trigger_len;
+ ssize_t sock_recv_len;
+ struct lttng_trigger *trigger = NULL;
+ struct lttng_buffer_view view;
+ struct lttng_dynamic_buffer trigger_buffer;
+
+ lttng_dynamic_buffer_init(&trigger_buffer);
+ trigger_len = (size_t) cmd_ctx->lsm->u.trigger.length;
+ ret = lttng_dynamic_buffer_set_size(&trigger_buffer, trigger_len);
+ if (ret) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ sock_recv_len = lttcomm_recv_unix_sock(sock, trigger_buffer.data,
+ trigger_len);
+ if (sock_recv_len < 0 || sock_recv_len != trigger_len) {
+ ERR("Failed to receive \"register trigger\" command payload");
+ /* TODO: should this be a new error enum ? */
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ view = lttng_buffer_view_from_dynamic_buffer(&trigger_buffer, 0, -1);
+ if (lttng_trigger_create_from_buffer(&view, &trigger) !=
+ trigger_len) {
+ ERR("Invalid trigger payload received in \"register trigger\" command");
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ ret = notification_thread_command_register_trigger(notification_thread,
+ trigger);
+ /* Ownership of trigger was transferred. */
+ trigger = NULL;
+end:
+ lttng_trigger_destroy(trigger);
+ lttng_dynamic_buffer_reset(&trigger_buffer);
+ return ret;
+}
+
+int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock,
+ struct notification_thread_handle *notification_thread)
+{
+ int ret;
+ size_t trigger_len;
+ ssize_t sock_recv_len;
+ struct lttng_trigger *trigger = NULL;
+ struct lttng_buffer_view view;
+ struct lttng_dynamic_buffer trigger_buffer;
+
+ lttng_dynamic_buffer_init(&trigger_buffer);
+ trigger_len = (size_t) cmd_ctx->lsm->u.trigger.length;
+ ret = lttng_dynamic_buffer_set_size(&trigger_buffer, trigger_len);
+ if (ret) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ sock_recv_len = lttcomm_recv_unix_sock(sock, trigger_buffer.data,
+ trigger_len);
+ if (sock_recv_len < 0 || sock_recv_len != trigger_len) {
+ ERR("Failed to receive \"unregister trigger\" command payload");
+ /* TODO: should this be a new error enum ? */
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ view = lttng_buffer_view_from_dynamic_buffer(&trigger_buffer, 0, -1);
+ if (lttng_trigger_create_from_buffer(&view, &trigger) !=
+ trigger_len) {
+ ERR("Invalid trigger payload received in \"unregister trigger\" command");
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ ret = notification_thread_command_unregister_trigger(notification_thread,
+ trigger);
+end:
+ lttng_trigger_destroy(trigger);
+ lttng_dynamic_buffer_reset(&trigger_buffer);
+ return ret;
+}
+
/*
* Send relayd sockets from snapshot output to consumer. Ignore request if the
* snapshot output is *not* set with a remote destination.
* set in no output mode.
*/
if (session->output_traces) {
- ret = LTTNG_ERR_EPERM;
+ ret = LTTNG_ERR_NOT_SNAPSHOT_SESSION;
goto error;
}
return 0;
}
+static
+int rename_first_chunk(struct consumer_output *consumer, char *datetime)
+{
+ int ret;
+ char *tmppath = NULL, *tmppath2 = NULL;
+
+ tmppath = zmalloc(PATH_MAX * sizeof(char));
+ if (!tmppath) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ tmppath2 = zmalloc(PATH_MAX * sizeof(char));
+ if (!tmppath2) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+
+ /* Current domain path: <session>/kernel */
+ snprintf(tmppath, PATH_MAX, "%s/%s",
+ consumer->dst.session_root_path, consumer->subdir);
+ /* New domain path: <session>/<start-date>-/kernel */
+ snprintf(tmppath2, PATH_MAX, "%s/%s-/%s",
+ consumer->dst.session_root_path, datetime,
+ consumer->subdir);
+ /*
+ * Move the per-domain folder inside the first rotation
+ * folder.
+ */
+ ret = rename(tmppath, tmppath2);
+ if (ret < 0) {
+ PERROR("Rename first trace directory");
+ ret = -LTTNG_ERR_ROTATE_NO_DATA;
+ goto error;
+ }
+
+ ret = 0;
+
+error:
+ free(tmppath);
+ free(tmppath2);
+
+ return ret;
+}
+
+/*
+ * Command LTTNG_ROTATE_SESSION from the lttng-ctl library.
+ *
+ * Ask the consumer to rotate the session output directory.
+ *
+ * Return 0 on success or else a LTTNG_ERR code.
+ */
+int cmd_rotate_session(struct ltt_session *session,
+ struct lttng_rotate_session_return **rotate_return)
+{
+ int ret;
+ struct tm *timeinfo;
+ char datetime[16];
+ time_t now;
+
+ assert(session);
+
+ *rotate_return = zmalloc(sizeof(struct lttng_rotate_session_return));
+ if (!*rotate_return) {
+ ret = -ENOMEM;
+ goto end;
+ }
+
+ if (session->live_timer || session->snapshot_mode ||
+ !session->output_traces) {
+ ret = -LTTNG_ERR_ROTATE_NOT_AVAILABLE;
+ goto error;
+ }
+
+ if (session->rotate_pending) {
+ ret = -LTTNG_ERR_ROTATE_PENDING;
+ goto error;
+ }
+
+ /* Special case for the first rotation. */
+ if (session->rotate_count == 0) {
+ timeinfo = localtime(&session->session_start_ts);
+ strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
+ if (session->kernel_session) {
+ snprintf(session->rotation_chunk.current_rotate_path,
+ PATH_MAX, "%s/%s-",
+ session->kernel_session->consumer->dst.session_root_path,
+ datetime);
+ } else if (session->ust_session) {
+ snprintf(session->rotation_chunk.current_rotate_path,
+ PATH_MAX, "%s/%s-",
+ session->ust_session->consumer->dst.session_root_path,
+ datetime);
+ } else {
+ assert(0);
+ }
+
+ /*
+ * Create the first rotation folder to move the existing
+ * kernel/ust folders into.
+ */
+ ret = run_as_mkdir_recursive(session->rotation_chunk.current_rotate_path,
+ S_IRWXU | S_IRWXG, session->uid, session->gid);
+ if (ret < 0) {
+ if (errno != EEXIST) {
+ ERR("Trace directory creation error");
+ ret = -LTTNG_ERR_ROTATE_NOT_AVAILABLE;
+ goto error;
+ }
+ }
+ if (session->kernel_session) {
+ ret = rename_first_chunk(session->kernel_session->consumer,
+ datetime);
+ if (ret < 0) {
+ goto error;
+ }
+ }
+ if (session->ust_session) {
+ ret = rename_first_chunk(session->ust_session->consumer,
+ datetime);
+ if (ret < 0) {
+ goto error;
+ }
+ }
+ } else {
+ /*
+ * The currently active tracing path is now the folder we
+ * want to rotate.
+ */
+ snprintf(session->rotation_chunk.current_rotate_path,
+ PATH_MAX, "%s",
+ session->rotation_chunk.active_tracing_path);
+ }
+
+ session->rotate_count++;
+ session->rotate_pending = 1;
+
+ /*
+ * Create the path name for the next chunk.
+ */
+ now = time(NULL);
+ if (now == (time_t) -1) {
+ ret = -LTTNG_ERR_ROTATE_NOT_AVAILABLE;
+ goto error;
+ }
+
+ timeinfo = localtime(&now);
+ strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
+ if (session->kernel_session) {
+ /* The active path for the next rotation/destroy. */
+ snprintf(session->rotation_chunk.active_tracing_path,
+ PATH_MAX, "%s/%s-",
+ session->kernel_session->consumer->dst.session_root_path,
+ datetime);
+ /* The sub-directory for the consumer. */
+ snprintf(session->kernel_session->consumer->chunk_path,
+ PATH_MAX, "/%s-/%s/", datetime,
+ session->kernel_session->consumer->subdir);
+ ret = kernel_rotate_session(session);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+ }
+ if (session->ust_session) {
+ snprintf(session->rotation_chunk.active_tracing_path,
+ PATH_MAX, "%s/%s-",
+ session->ust_session->consumer->dst.session_root_path,
+ datetime);
+ snprintf(session->ust_session->consumer->chunk_path,
+ PATH_MAX, "/%s-/", datetime);
+ ret = ust_app_rotate_session(session);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+ }
+
+ (*rotate_return)->rotate_id = session->rotate_count;
+ (*rotate_return)->status = LTTNG_ROTATE_STARTED;
+
+ DBG("Cmd rotate session %s, rotate_id %" PRIu64, session->name,
+ session->rotate_count);
+ ret = LTTNG_OK;
+
+ goto end;
+
+error:
+ (*rotate_return)->status = LTTNG_ROTATE_ERROR;
+end:
+ return ret;
+}
+
+/*
+ * Command LTTNG_ROTATE_PENDING from the lttng-ctl library.
+ *
+ * Check if the session has finished its rotation.
+ *
+ * Return 0 on success or else a LTTNG_ERR code.
+ */
+int cmd_rotate_pending(struct ltt_session *session,
+ struct lttng_rotate_pending_return **pending_return,
+ uint64_t rotate_id)
+{
+ int ret;
+
+ assert(session);
+
+ DBG("Cmd rotate pending session %s, rotate_id %" PRIu64, session->name,
+ session->rotate_count);
+
+ *pending_return = zmalloc(sizeof(struct lttng_rotate_pending_return));
+ if (!*pending_return) {
+ ret = -ENOMEM;
+ goto end;
+ }
+
+ if (session->rotate_count != rotate_id) {
+ (*pending_return)->status = LTTNG_ROTATE_EXPIRED;
+ ret = LTTNG_OK;
+ goto end;
+ }
+
+ if (session->rotate_pending) {
+ DBG("Session %s, rotate_id %" PRIu64 " still pending",
+ session->name, session->rotate_count);
+ (*pending_return)->status = LTTNG_ROTATE_STARTED;
+ } else {
+ DBG("Session %s, rotate_id %" PRIu64 " finished",
+ session->name, session->rotate_count);
+ (*pending_return)->status = LTTNG_ROTATE_COMPLETED;
+ snprintf((*pending_return)->output_path, PATH_MAX, "%s",
+ session->rotation_chunk.current_rotate_path);
+ }
+
+ ret = LTTNG_OK;
+
+ goto end;
+
+error:
+ (*pending_return)->status = LTTNG_ROTATE_ERROR;
+end:
+ return ret;
+}
+
/*
* Init command subsystem.
*/