*
*/
-#include <lttng/destruction-handle.h>
-#include <lttng/rotation.h>
+#include "lttng-ctl-helper.hpp"
-#include <common/optional.hpp>
+#include <common/buffer-view.hpp>
#include <common/compat/poll.hpp>
#include <common/compat/time.hpp>
-#include <common/macros.hpp>
-#include <common/compat/poll.hpp>
#include <common/dynamic-buffer.hpp>
-#include <common/buffer-view.hpp>
+#include <common/macros.hpp>
+#include <common/optional.hpp>
#include <common/sessiond-comm/sessiond-comm.hpp>
+
+#include <lttng/destruction-handle.h>
#include <lttng/location-internal.hpp>
-#include "lttng-ctl-helper.hpp"
+#include <lttng/rotation.h>
#include <algorithm>
#include <stdbool.h>
free(handle);
}
-static
-struct lttng_destruction_handle *lttng_destruction_handle_create(
- int sessiond_socket)
+static struct lttng_destruction_handle *lttng_destruction_handle_create(int sessiond_socket)
{
int ret;
struct lttng_destruction_handle *handle = zmalloc<lttng_destruction_handle>();
goto error;
}
- ret = lttng_poll_add(&handle->communication.events, sessiond_socket,
- LPOLLIN | LPOLLRDHUP);
+ ret = lttng_poll_add(&handle->communication.events, sessiond_socket, LPOLLIN | LPOLLRDHUP);
if (ret) {
goto error;
}
- handle->communication.bytes_left_to_receive =
- sizeof(struct lttcomm_lttng_msg);
+ handle->communication.bytes_left_to_receive = sizeof(struct lttcomm_lttng_msg);
handle->communication.state = COMMUNICATION_STATE_RECEIVE_LTTNG_MSG;
end:
return handle;
error:
lttng_destruction_handle_destroy(handle);
- return NULL;
+ return nullptr;
}
-static
-int handle_state_transition(struct lttng_destruction_handle *handle)
+static int handle_state_transition(struct lttng_destruction_handle *handle)
{
int ret = 0;
case COMMUNICATION_STATE_RECEIVE_LTTNG_MSG:
{
const struct lttcomm_lttng_msg *msg =
- (typeof(msg)) handle->communication.buffer.data;
+ (typeof(msg)) handle->communication.buffer.data;
LTTNG_OPTIONAL_SET(&handle->destruction_return_code,
- (enum lttng_error_code) msg->ret_code);
+ (enum lttng_error_code) msg->ret_code);
if (handle->destruction_return_code.value != LTTNG_OK) {
handle->communication.state = COMMUNICATION_STATE_END;
break;
- } else if (msg->cmd_header_size != sizeof(struct lttcomm_session_destroy_command_header) ||
- msg->data_size > DEFAULT_MAX_TRACE_ARCHIVE_LOCATION_PAYLOAD_SIZE) {
+ } else if (msg->cmd_header_size !=
+ sizeof(struct lttcomm_session_destroy_command_header) ||
+ msg->data_size > DEFAULT_MAX_TRACE_ARCHIVE_LOCATION_PAYLOAD_SIZE) {
handle->communication.state = COMMUNICATION_STATE_ERROR;
ret = -1;
break;
}
- handle->communication.state =
- COMMUNICATION_STATE_RECEIVE_COMMAND_HEADER;
- handle->communication.bytes_left_to_receive =
- msg->cmd_header_size;
- LTTNG_OPTIONAL_SET(&handle->communication.data_size,
- msg->data_size);
- ret = lttng_dynamic_buffer_set_size(
- &handle->communication.buffer, 0);
+ handle->communication.state = COMMUNICATION_STATE_RECEIVE_COMMAND_HEADER;
+ handle->communication.bytes_left_to_receive = msg->cmd_header_size;
+ LTTNG_OPTIONAL_SET(&handle->communication.data_size, msg->data_size);
+ ret = lttng_dynamic_buffer_set_size(&handle->communication.buffer, 0);
LTTNG_ASSERT(!ret);
break;
}
case COMMUNICATION_STATE_RECEIVE_COMMAND_HEADER:
{
const struct lttcomm_session_destroy_command_header *hdr =
- (typeof(hdr)) handle->communication.buffer.data;
+ (typeof(hdr)) handle->communication.buffer.data;
LTTNG_OPTIONAL_SET(&handle->rotation_state,
- (enum lttng_rotation_state) hdr->rotation_state);
+ (enum lttng_rotation_state) hdr->rotation_state);
switch (handle->rotation_state.value) {
case LTTNG_ROTATION_STATE_COMPLETED:
- handle->communication.state =
- COMMUNICATION_STATE_RECEIVE_PAYLOAD;
+ handle->communication.state = COMMUNICATION_STATE_RECEIVE_PAYLOAD;
handle->communication.bytes_left_to_receive =
- LTTNG_OPTIONAL_GET(handle->communication.data_size);
+ LTTNG_OPTIONAL_GET(handle->communication.data_size);
break;
case LTTNG_ROTATION_STATE_ERROR:
case LTTNG_ROTATION_STATE_NO_ROTATION:
ssize_t location_ret;
struct lttng_trace_archive_location *location;
const struct lttng_buffer_view view =
- lttng_buffer_view_from_dynamic_buffer(
- &handle->communication.buffer, 0, -1);
+ lttng_buffer_view_from_dynamic_buffer(&handle->communication.buffer, 0, -1);
- location_ret = lttng_trace_archive_location_create_from_buffer(
- &view, &location);
+ location_ret = lttng_trace_archive_location_create_from_buffer(&view, &location);
if (location_ret < 0) {
ERR("Failed to deserialize trace archive location");
handle->communication.state = COMMUNICATION_STATE_ERROR;
return ret;
}
-static
-int handle_incoming_data(struct lttng_destruction_handle *handle)
+static int handle_incoming_data(struct lttng_destruction_handle *handle)
{
int ret;
ssize_t comm_ret;
/* Reserve space for reception. */
ret = lttng_dynamic_buffer_set_size(&handle->communication.buffer,
- original_buffer_size + handle->communication.bytes_left_to_receive);
+ original_buffer_size +
+ handle->communication.bytes_left_to_receive);
if (ret) {
goto end;
}
comm_ret = lttcomm_recv_unix_sock(handle->communication.socket,
- handle->communication.buffer.data + original_buffer_size,
- handle->communication.bytes_left_to_receive);
+ handle->communication.buffer.data + original_buffer_size,
+ handle->communication.bytes_left_to_receive);
if (comm_ret <= 0) {
ret = -1;
goto end;
if (handle->communication.bytes_left_to_receive == 0) {
ret = handle_state_transition(handle);
} else {
- ret = lttng_dynamic_buffer_set_size(
- &handle->communication.buffer,
- original_buffer_size + comm_ret);
+ ret = lttng_dynamic_buffer_set_size(&handle->communication.buffer,
+ original_buffer_size + comm_ret);
}
end:
return ret;
}
enum lttng_destruction_handle_status
-lttng_destruction_handle_wait_for_completion(
- struct lttng_destruction_handle *handle, int timeout_ms)
+lttng_destruction_handle_wait_for_completion(struct lttng_destruction_handle *handle,
+ int timeout_ms)
{
enum lttng_destruction_handle_status status;
unsigned long time_left_ms = 0;
}
while (handle->communication.state != COMMUNICATION_STATE_END &&
- (time_left_ms || !has_timeout)) {
+ (time_left_ms || !has_timeout)) {
int ret;
uint32_t revents;
struct timespec current_time, diff;
unsigned long diff_ms;
ret = lttng_poll_wait(&handle->communication.events,
- has_timeout ? time_left_ms : -1);
+ has_timeout ? time_left_ms : -1);
if (ret == 0) {
/* timeout */
break;
if (revents & LPOLLIN) {
ret = handle_incoming_data(handle);
if (ret) {
- handle->communication.state =
- COMMUNICATION_STATE_ERROR;
+ handle->communication.state = COMMUNICATION_STATE_ERROR;
status = LTTNG_DESTRUCTION_HANDLE_STATUS_ERROR;
goto end;
}
status = LTTNG_DESTRUCTION_HANDLE_STATUS_ERROR;
goto end;
}
- DBG("%lums elapsed while waiting for session destruction completion",
- diff_ms);
+ DBG("%lums elapsed while waiting for session destruction completion", diff_ms);
diff_ms = std::max(diff_ms, 1UL);
diff_ms = std::min(diff_ms, time_left_ms);
time_left_ms -= diff_ms;
}
status = handle->communication.state == COMMUNICATION_STATE_END ?
- LTTNG_DESTRUCTION_HANDLE_STATUS_COMPLETED :
- LTTNG_DESTRUCTION_HANDLE_STATUS_TIMEOUT;
+ LTTNG_DESTRUCTION_HANDLE_STATUS_COMPLETED :
+ LTTNG_DESTRUCTION_HANDLE_STATUS_TIMEOUT;
end:
return status;
}
enum lttng_destruction_handle_status
-lttng_destruction_handle_get_rotation_state(
- const struct lttng_destruction_handle *handle,
- enum lttng_rotation_state *rotation_state)
+lttng_destruction_handle_get_rotation_state(const struct lttng_destruction_handle *handle,
+ enum lttng_rotation_state *rotation_state)
{
- enum lttng_destruction_handle_status status =
- LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
+ enum lttng_destruction_handle_status status = LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
if (!handle || !rotation_state) {
status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
}
enum lttng_destruction_handle_status
-lttng_destruction_handle_get_archive_location(
- const struct lttng_destruction_handle *handle,
- const struct lttng_trace_archive_location **location)
+lttng_destruction_handle_get_archive_location(const struct lttng_destruction_handle *handle,
+ const struct lttng_trace_archive_location **location)
{
- enum lttng_destruction_handle_status status =
- LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
+ enum lttng_destruction_handle_status status = LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
if (!handle || !location) {
status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
}
enum lttng_destruction_handle_status
-lttng_destruction_handle_get_result(
- const struct lttng_destruction_handle *handle,
- enum lttng_error_code *result)
+lttng_destruction_handle_get_result(const struct lttng_destruction_handle *handle,
+ enum lttng_error_code *result)
{
- enum lttng_destruction_handle_status status =
- LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
+ enum lttng_destruction_handle_status status = LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
if (!handle || !result) {
status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
}
enum lttng_error_code lttng_destroy_session_ext(const char *session_name,
- struct lttng_destruction_handle **_handle)
+ struct lttng_destruction_handle **_handle)
{
int ret;
ssize_t comm_ret;
.fd_count = 0,
};
int sessiond_socket = -1;
- struct lttng_destruction_handle *handle = NULL;
+ struct lttng_destruction_handle *handle = nullptr;
if (!session_name) {
ret_code = LTTNG_ERR_INVALID;
goto error;
}
- ret = lttng_strncpy(lsm.session.name, session_name,
- sizeof(lsm.session.name));
+ ret = lttng_strncpy(lsm.session.name, session_name, sizeof(lsm.session.name));
if (ret) {
ret_code = LTTNG_ERR_INVALID;
goto error;
/* Transfer the handle to the caller. */
if (_handle) {
*_handle = handle;
- handle = NULL;
+ handle = nullptr;
}
error:
if (sessiond_socket >= 0) {