* This is opaque to the public library.
*/
struct lttng_rotation_immediate_attr {
- /* Session name to rotate. */
- char session_name[LTTNG_NAME_MAX];
/* For the rotate pending request. */
uint64_t rotate_id;
};
* This is opaque to the public library.
*/
struct lttng_rotation_schedule_attr {
- /* Session name to rotate. */
- char session_name[LTTNG_NAME_MAX];
/* > 0 if a timer is set. */
uint64_t timer_us;
/* > 0 if the session should rotate when it has written that many bytes. */
struct lttng_rotation_handle;
/*
- * Return a newly allocated immediate session rotation descriptor object or NULL
- * on error.
- */
-extern struct lttng_rotation_immediate_attr *
-lttng_rotation_immediate_attr_create(void);
-
-/*
- * Return a newly allocated scheduled rotate session descriptor object or NULL
+ * Return a newly allocated session rotation schedule descriptor object or NULL
* on error.
+ *
+ * The rotation schedule may be expressed as a size or as a time period.
*/
extern struct lttng_rotation_schedule_attr *
lttng_rotation_schedule_attr_create(void);
-/*
- * Destroy a given immediate session rotation descriptor object.
- */
-extern void lttng_rotation_immediate_attr_destroy(
- struct lttng_rotation_immediate_attr *attr);
-
/*
* Destroy a given scheduled rotate session descriptor object.
*/
struct lttng_rotation_schedule_attr *attr);
/*
- * Set the name of the session to rotate immediately.
- *
- * The session_name parameter is copied to the immediate session rotation
- * attributes.
- */
-extern enum lttng_rotation_status lttng_rotation_immediate_attr_set_session_name(
- struct lttng_rotation_immediate_attr *attr,
- const char *session_name);
-
-/*
- * Set the name of the session to rotate automatically.
- *
- * The session_name parameter is copied to the immediate session rotation
- * attributes.
- */
-extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_session_name(
- struct lttng_rotation_schedule_attr *attr,
- const char *session_name);
-
-/*
- * Set the timer to periodically rotate the session (µs, -1ULL to disable).
+ * Set the timer to periodically rotate the session (in µs).
*/
extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period(
struct lttng_rotation_schedule_attr *attr, uint64_t timer);
/*
- * Set the size to rotate the session (bytes, -1ULL to disable).
+ * Set the size to rotate the session (in bytes).
*/
void lttng_rotation_schedule_attr_set_size(
struct lttng_rotation_schedule_attr *attr, uint64_t size);
struct lttng_rotation_handle *rotation_handle);
/*
- * Rotate the output folder of the session
+ * Rotate the output folder of the session.
*
* On success, handle is allocated and can be used to monitor the progress
* of the rotation with lttng_rotation_get_state(). The handle must be freed
* by the caller with lttng_rotation_handle_destroy().
*
+ * Passing NULL as the immediate rotation attribute results in the default
+ * options being used.
+ *
* Return 0 if the rotate action was successfully launched or a negative
* LTTng error code on error.
*/
-extern int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr,
+extern int lttng_rotate_session(const char *session_name,
+ struct lttng_rotation_immediate_attr *attr,
struct lttng_rotation_handle **rotation_handle);
/*
- * Configure a session to rotate periodically or based on the size written.
+ * Configure a session to rotate according to a given schedule.
*/
-extern int lttng_rotation_set_schedule(
+extern int lttng_rotation_set_schedule(const char *session_name,
struct lttng_rotation_schedule_attr *attr);
/*
}
}
- ret = lttng_rotation_schedule_attr_set_session_name(attr, session_name);
- if (ret < 0) {
- goto error;
- }
-
if (lttng_opt_mi) {
ret = mi_lttng_writer_write_element_string(writer,
mi_lttng_element_session_name, session_name);
MSG("Disabling rotation based on size on session %s", session_name);
}
- ret = lttng_rotation_set_schedule(attr);
+ ret = lttng_rotation_set_schedule(session_name, attr);
if (ret) {
ERR("%s", lttng_strerror(ret));
if (lttng_opt_mi) {
goto error;
}
- ret = lttng_rotation_schedule_attr_set_session_name(attr, session_name);
- if (ret < 0) {
- goto error;
- }
-
if (lttng_opt_mi) {
/* Open rotation_schedule element */
ret = mi_lttng_writer_open_element(writer,
}
}
- ret = lttng_rotation_set_schedule(attr);
+ ret = lttng_rotation_set_schedule(session_name, attr);
if (ret) {
ERR("%s", lttng_strerror(ret));
if (lttng_opt_mi) {
static int rotate_tracing(char *session_name)
{
int ret;
- struct lttng_rotation_immediate_attr *attr = NULL;
struct lttng_rotation_handle *handle = NULL;
enum lttng_rotation_status rotation_status;
enum lttng_rotation_state rotation_state = LTTNG_ROTATION_STATE_ONGOING;
DBG("Rotating the output files of session %s", session_name);
- attr = lttng_rotation_immediate_attr_create();
- if (!attr) {
- goto error;
- }
-
- ret = lttng_rotation_immediate_attr_set_session_name(attr, session_name);
- if (ret < 0) {
- ERR("Session name exceeds the maximal allowed length");
- goto error;
- }
-
- ret = lttng_rotate_session(attr, &handle);
+ ret = lttng_rotate_session(session_name, NULL, &handle);
if (ret < 0) {
switch (-ret) {
case LTTNG_ERR_SESSION_NOT_STARTED:
ret = CMD_ERROR;
end:
lttng_rotation_handle_destroy(handle);
- lttng_rotation_immediate_attr_destroy(attr);
return ret;
}
}
if (rotation_timer_interval || rotation_size) {
- struct lttng_rotation_schedule_attr *rotation_attr = lttng_rotation_schedule_attr_create();
+ struct lttng_rotation_schedule_attr *rotation_attr =
+ lttng_rotation_schedule_attr_create();
if (!rotation_attr) {
goto error;
}
- ret = lttng_rotation_schedule_attr_set_session_name(rotation_attr, (const char *) name);
- if (ret) {
- lttng_rotation_schedule_attr_destroy(rotation_attr);
- goto error;
- }
lttng_rotation_schedule_attr_set_timer_period(rotation_attr,
rotation_timer_interval);
- lttng_rotation_schedule_attr_set_size(rotation_attr, rotation_size);
- ret = lttng_rotation_set_schedule(rotation_attr);
+ lttng_rotation_schedule_attr_set_size(rotation_attr,
+ rotation_size);
+ ret = lttng_rotation_set_schedule((const char *) name,
+ rotation_attr);
lttng_rotation_schedule_attr_destroy(rotation_attr);
if (ret) {
goto error;
#include "lttng-ctl-helper.h"
-struct lttng_rotation_immediate_attr *lttng_rotation_immediate_attr_create(void)
-{
- return zmalloc(sizeof(struct lttng_rotation_immediate_attr));
-}
-
struct lttng_rotation_schedule_attr *lttng_rotation_schedule_attr_create(void)
{
return zmalloc(sizeof(struct lttng_rotation_schedule_attr));
}
-void lttng_rotation_immediate_attr_destroy(
- struct lttng_rotation_immediate_attr *attr)
-{
- free(attr);
-}
-
void lttng_rotation_schedule_attr_destroy(struct lttng_rotation_schedule_attr *attr)
{
if (attr) {
}
}
-enum lttng_rotation_status lttng_rotation_immediate_attr_set_session_name(
- struct lttng_rotation_immediate_attr *attr,
- const char *session_name)
-{
- enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
- int ret;
-
- if (!attr || !session_name) {
- status = LTTNG_ROTATION_STATUS_INVALID;
- goto error;
- }
-
- ret = lttng_strncpy(attr->session_name, session_name,
- sizeof(attr->session_name));
- if (ret) {
- status = LTTNG_ROTATION_STATUS_INVALID;
- goto error;
- }
-
-error:
- return status;
-}
-
static
enum lttng_rotation_status ask_rotation_info(
struct lttng_rotation_handle *rotation_handle,
}
-enum lttng_rotation_status lttng_rotation_schedule_attr_set_session_name(
- struct lttng_rotation_schedule_attr *attr,
- const char *session_name)
-{
- enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
- int ret;
-
- if (!attr || !session_name) {
- status = LTTNG_ROTATION_STATUS_INVALID;
- goto error;
- }
-
- ret = lttng_strncpy(attr->session_name, session_name,
- sizeof(attr->session_name));
- if (ret) {
- status = LTTNG_ROTATION_STATUS_INVALID;
- goto error;
- }
-
-error:
- return status;
-}
-
enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period(
struct lttng_rotation_schedule_attr *attr,
uint64_t timer)
static
int init_rotation_handle(struct lttng_rotation_handle *rotation_handle,
+ const char *session_name,
struct lttng_rotate_session_return *rotate_return,
struct lttng_rotation_immediate_attr *attr)
{
int ret;
- ret = lttng_strncpy(rotation_handle->session_name, attr->session_name,
+ ret = lttng_strncpy(rotation_handle->session_name, session_name,
sizeof(rotation_handle->session_name));
if (ret) {
goto end;
*
* Return 0 on success else a negative LTTng error code.
*/
-int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr,
+int lttng_rotate_session(const char *session_name,
+ struct lttng_rotation_immediate_attr *attr,
struct lttng_rotation_handle **rotation_handle)
{
struct lttcomm_session_msg lsm;
struct lttng_rotate_session_return *rotate_return = NULL;
int ret;
+ size_t session_name_len;
- if (!attr) {
+ if (!session_name) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ session_name_len = strlen(session_name);
+ if (session_name_len >= sizeof(lsm.session.name) ||
+ session_name_len >= member_sizeof(struct lttng_rotation_handle, session_name)) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_ROTATE_SESSION;
- lttng_ctl_copy_string(lsm.session.name, attr->session_name,
+ lttng_ctl_copy_string(lsm.session.name, session_name,
sizeof(lsm.session.name));
ret = lttng_ctl_ask_sessiond(&lsm, (void **) &rotate_return);
goto end;
}
- init_rotation_handle(*rotation_handle, rotate_return, attr);
+ init_rotation_handle(*rotation_handle, session_name, rotate_return,
+ attr);
ret = 0;
/*
* Configure the automatic rotate parameters.
*/
-int lttng_rotation_set_schedule(
+int lttng_rotation_set_schedule(const char *session_name,
struct lttng_rotation_schedule_attr *attr)
{
struct lttcomm_session_msg lsm;
int ret;
- if (!attr) {
+ if (!attr || !session_name) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (strlen(session_name) >= sizeof(lsm.session.name)) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_ROTATION_SET_SCHEDULE;
- lttng_ctl_copy_string(lsm.session.name, attr->session_name,
+ lttng_ctl_copy_string(lsm.session.name, session_name,
sizeof(lsm.session.name));
lsm.u.rotate_setup.timer_us = attr->timer_us;
lsm.u.rotate_setup.size = attr->size;