#define _LGPL_SOURCE
#include <lttng/trigger/trigger.h>
-#include <common/error.h>
-#include <common/config/session-config.h>
-#include <common/defaults.h>
-#include <common/utils.h>
-#include <common/futex.h>
-#include <common/align.h>
-#include <common/time.h>
-#include <common/hashtable/utils.h>
+#include <common/error.hpp>
+#include <common/config/session-config.hpp>
+#include <common/defaults.hpp>
+#include <common/utils.hpp>
+#include <common/futex.hpp>
+#include <common/align.hpp>
+#include <common/time.hpp>
+#include <common/hashtable/utils.hpp>
#include <sys/stat.h>
#include <time.h>
#include <signal.h>
#include <inttypes.h>
-#include <common/kernel-ctl/kernel-ctl.h>
-#include <lttng/notification/channel-internal.h>
-#include <lttng/rotate-internal.h>
-#include <lttng/location-internal.h>
-
-#include "rotation-thread.h"
-#include "lttng-sessiond.h"
-#include "health-sessiond.h"
-#include "rotate.h"
-#include "cmd.h"
-#include "session.h"
-#include "timer.h"
-#include "notification-thread-commands.h"
-#include "utils.h"
-#include "thread.h"
+#include <common/kernel-ctl/kernel-ctl.hpp>
+#include <lttng/notification/channel-internal.hpp>
+#include <lttng/rotate-internal.hpp>
+#include <lttng/location-internal.hpp>
+#include <lttng/condition/condition-internal.hpp>
+#include <lttng/notification/notification-internal.hpp>
+
+#include "rotation-thread.hpp"
+#include "lttng-sessiond.hpp"
+#include "health-sessiond.hpp"
+#include "rotate.hpp"
+#include "cmd.hpp"
+#include "session.hpp"
+#include "timer.hpp"
+#include "notification-thread-commands.hpp"
+#include "utils.hpp"
+#include "thread.hpp"
#include <urcu.h>
#include <urcu/list.h>
struct lttng_poll_event events;
};
-struct rotation_thread_job {
- enum rotation_thread_job_type type;
- struct ltt_session *session;
- /* List member in struct rotation_thread_timer_queue. */
- struct cds_list_head head;
-};
-
/*
* The timer thread enqueues jobs and wakes up the rotation thread.
* When the rotation thread wakes up, it empties the queue.
struct lttng_pipe *quit_pipe;
};
+namespace {
+struct rotation_thread_job {
+ enum rotation_thread_job_type type;
+ struct ltt_session *session;
+ /* List member in struct rotation_thread_timer_queue. */
+ struct cds_list_head head;
+};
+} /* namespace */
+
static
const char *get_job_type_str(enum rotation_thread_job_type job_type)
{
{
struct rotation_thread_timer_queue *queue = NULL;
- queue = (rotation_thread_timer_queue *) zmalloc(sizeof(*queue));
+ queue = zmalloc<rotation_thread_timer_queue>();
if (!queue) {
PERROR("Failed to allocate timer rotate queue");
goto end;
{
struct rotation_thread_handle *handle;
- handle = (rotation_thread_handle *) zmalloc(sizeof(*handle));
+ handle = zmalloc<rotation_thread_handle>();
if (!handle) {
goto end;
}
goto end;
}
- job = (rotation_thread_job *) zmalloc(sizeof(struct rotation_thread_job));
+ job = zmalloc<rotation_thread_job>();
if (!job) {
PERROR("Failed to allocate rotation thread job of type \"%s\" for session \"%s\"",
job_type_str, session->name);
* the job will be processed when the rotation_thread catches
* up.
*/
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_LOGICAL_OP
if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ DIAGNOSTIC_POP
/*
* Not an error, but would be surprising and indicate
* that the rotation thread can't keep up with the
}
ret = lttng_poll_add(poll_set,
- lttng_pipe_get_readfd(handle->quit_pipe),
- LPOLLIN | LPOLLERR);
+ lttng_pipe_get_readfd(handle->quit_pipe), LPOLLIN);
if (ret < 0) {
ERR("Failed to add quit pipe read fd to poll set");
goto error;
ret = lttng_poll_add(poll_set,
lttng_pipe_get_readfd(handle->rotation_timer_queue->event_pipe),
- LPOLLIN | LPOLLERR);
+ LPOLLIN);
if (ret < 0) {
ERR("Failed to add rotate_pending fd to poll set");
goto error;
goto end;
}
ret = lttng_poll_add(&state->events, rotate_notification_channel->socket,
- LPOLLIN | LPOLLERR);
+ LPOLLIN);
if (ret < 0) {
ERR("Failed to add notification fd to pollset");
goto end;
location = session_get_trace_archive_location(session);
ret = notification_thread_command_session_rotation_completed(
notification_thread_handle,
- session->name,
- session->uid,
- session->gid,
+ session->id,
session->last_archived_chunk_id.value,
location);
lttng_trace_archive_location_put(location);
static
int handle_job_queue(struct rotation_thread_handle *handle,
- struct rotation_thread *state,
+ struct rotation_thread *state __attribute__((unused)),
struct rotation_thread_timer_queue *queue)
{
int ret = 0;
session = job->session;
if (!session) {
DBG("Session \"%s\" not found",
- session->name);
+ session->name != NULL ? session->name : "");
/*
* This is a non-fatal error, and we cannot report it to
* the user (timer), so just print the error and
}
static
-int handle_condition(const struct lttng_condition *condition,
- const struct lttng_evaluation *evaluation,
+int handle_condition(const struct lttng_notification *notification,
struct notification_thread_handle *notification_thread_handle)
{
int ret = 0;
enum lttng_evaluation_status evaluation_status;
uint64_t consumed;
struct ltt_session *session;
+ const struct lttng_condition *condition =
+ lttng_notification_get_const_condition(notification);
+ const struct lttng_evaluation *evaluation =
+ lttng_notification_get_const_evaluation(notification);
condition_type = lttng_condition_get_type(condition);
session_lock_list();
session = session_find_by_name(condition_session_name);
if (!session) {
- ret = -1;
- session_unlock_list();
- ERR("Session \"%s\" not found",
+ DBG("Failed to find session while handling notification: notification type = %s, session name = `%s`",
+ lttng_condition_type_str(condition_type),
condition_session_name);
+ /*
+ * Not a fatal error: a session can be destroyed before we get
+ * the chance to handle the notification.
+ */
+ ret = 0;
+ session_unlock_list();
goto end;
}
session_lock(session);
+ if (!lttng_trigger_is_equal(session->rotate_trigger,
+ lttng_notification_get_const_trigger(notification))) {
+ /* Notification does not originate from our rotation trigger. */
+ ret = 0;
+ goto end_unlock;
+ }
+
ret = unsubscribe_session_consumed_size_rotation(session,
notification_thread_handle);
if (ret) {
goto end_unlock;
}
- ret = cmd_rotate_session(session, NULL, false,
- LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED);
- if (ret == -LTTNG_ERR_ROTATION_PENDING) {
+ ret = cmd_rotate_session(
+ session, NULL, false, LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED);
+ switch (ret) {
+ case LTTNG_OK:
+ break;
+ case -LTTNG_ERR_ROTATION_PENDING:
DBG("Rotate already pending, subscribe to the next threshold value");
- } else if (ret != LTTNG_OK) {
- ERR("Failed to rotate on size notification with error: %s",
- lttng_strerror(ret));
+ break;
+ case -LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP:
+ DBG("Rotation already happened since last stop, subscribe to the next threshold value");
+ break;
+ case -LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR:
+ DBG("Rotation already happened since last stop and clear, subscribe to the next threshold value");
+ break;
+ default:
+ ERR("Failed to rotate on size notification with error: %s", lttng_strerror(ret));
ret = -1;
goto end_unlock;
}
- ret = subscribe_session_consumed_size_rotation(session,
- consumed + session->rotate_size,
- notification_thread_handle);
+
+ ret = subscribe_session_consumed_size_rotation(
+ session, consumed + session->rotate_size, notification_thread_handle);
if (ret) {
ERR("Failed to subscribe to session consumed size condition");
goto end_unlock;
}
static
-int handle_notification_channel(int fd,
+int handle_notification_channel(int fd __attribute__((unused)),
struct rotation_thread_handle *handle,
- struct rotation_thread *state)
+ struct rotation_thread *state __attribute__((unused)))
{
int ret;
bool notification_pending;
struct lttng_notification *notification = NULL;
enum lttng_notification_channel_status status;
- const struct lttng_evaluation *notification_evaluation;
- const struct lttng_condition *notification_condition;
status = lttng_notification_channel_has_pending_notification(
rotate_notification_channel, ¬ification_pending);
goto end;
}
- notification_condition = lttng_notification_get_condition(notification);
- notification_evaluation = lttng_notification_get_evaluation(notification);
-
- ret = handle_condition(notification_condition, notification_evaluation,
+ ret = handle_condition(notification,
handle->notification_thread_handle);
end: