*/
#define _LGPL_SOURCE
-#include <algorithm>
-#include <string.h>
+#include "lttng-ctl-helper.hpp"
-#include <lttng/lttng-error.h>
-#include <lttng/clear.h>
-#include <lttng/clear-handle.h>
-#include <common/sessiond-comm/sessiond-comm.hpp>
-#include <common/macros.hpp>
+#include <common/buffer-view.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-ctl-helper.hpp"
+#include <lttng/clear-handle.h>
+#include <lttng/clear.h>
+#include <lttng/lttng-error.h>
+
+#include <algorithm>
+#include <string.h>
enum communication_state {
COMMUNICATION_STATE_RECEIVE_LTTNG_MSG,
free(handle);
}
-static
-struct lttng_clear_handle *lttng_clear_handle_create(int sessiond_socket)
+static struct lttng_clear_handle *lttng_clear_handle_create(int sessiond_socket)
{
int ret;
- struct lttng_clear_handle *handle = (lttng_clear_handle *) zmalloc(sizeof(*handle));
+ struct lttng_clear_handle *handle = zmalloc<lttng_clear_handle>();
if (!handle) {
goto end;
goto error;
}
- ret = lttng_poll_add(&handle->communication.events, sessiond_socket,
- LPOLLIN | LPOLLHUP | LPOLLRDHUP | LPOLLERR);
+ 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_clear_handle_destroy(handle);
- return NULL;
+ return nullptr;
}
-static
-int handle_state_transition(struct lttng_clear_handle *handle)
+static int handle_state_transition(struct lttng_clear_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->clear_return_code,
- (enum lttng_error_code) msg->ret_code);
+ (enum lttng_error_code) msg->ret_code);
if (handle->clear_return_code.value != LTTNG_OK) {
handle->communication.state = COMMUNICATION_STATE_END;
break;
handle->communication.state = COMMUNICATION_STATE_END;
handle->communication.bytes_left_to_receive = 0;
LTTNG_OPTIONAL_SET(&handle->communication.data_size, 0);
- ret = lttng_dynamic_buffer_set_size(
- &handle->communication.buffer, 0);
+ ret = lttng_dynamic_buffer_set_size(&handle->communication.buffer, 0);
LTTNG_ASSERT(!ret);
break;
}
return ret;
}
-static
-int handle_incoming_data(struct lttng_clear_handle *handle)
+static int handle_incoming_data(struct lttng_clear_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;
}
extern enum lttng_clear_handle_status
- lttng_clear_handle_wait_for_completion(
- struct lttng_clear_handle *handle, int timeout_ms)
+lttng_clear_handle_wait_for_completion(struct lttng_clear_handle *handle, int timeout_ms)
{
enum lttng_clear_handle_status status;
unsigned long time_left_ms = 0;
goto end;
}
if (has_timeout) {
- int ret = lttng_clock_gettime(CLOCK_MONOTONIC, &initial_time);
+ const int ret = lttng_clock_gettime(CLOCK_MONOTONIC, &initial_time);
if (ret) {
status = LTTNG_CLEAR_HANDLE_STATUS_ERROR;
goto end;
}
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_CLEAR_HANDLE_STATUS_ERROR;
goto end;
}
status = LTTNG_CLEAR_HANDLE_STATUS_ERROR;
goto end;
}
- DBG("%lums elapsed while waiting for session clear completion",
- diff_ms);
+ DBG("%lums elapsed while waiting for session clear 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_CLEAR_HANDLE_STATUS_COMPLETED :
- LTTNG_CLEAR_HANDLE_STATUS_TIMEOUT;
+ LTTNG_CLEAR_HANDLE_STATUS_COMPLETED :
+ LTTNG_CLEAR_HANDLE_STATUS_TIMEOUT;
end:
return status;
}
extern enum lttng_clear_handle_status
- lttng_clear_handle_get_result(
- const struct lttng_clear_handle *handle,
- enum lttng_error_code *result)
+lttng_clear_handle_get_result(const struct lttng_clear_handle *handle,
+ enum lttng_error_code *result)
{
- enum lttng_clear_handle_status status =
- LTTNG_CLEAR_HANDLE_STATUS_OK;
+ enum lttng_clear_handle_status status = LTTNG_CLEAR_HANDLE_STATUS_OK;
if (!handle->clear_return_code.is_set) {
status = LTTNG_CLEAR_HANDLE_STATUS_INVALID;
* Clear the session
*/
enum lttng_error_code lttng_clear_session(const char *session_name,
- struct lttng_clear_handle **_handle)
+ struct lttng_clear_handle **_handle)
{
enum lttng_error_code ret_code = LTTNG_OK;
- struct lttng_clear_handle *handle = NULL;
+ struct lttng_clear_handle *handle = nullptr;
struct lttcomm_session_msg lsm = {
- .cmd_type = LTTNG_CLEAR_SESSION,
+ .cmd_type = LTTCOMM_SESSIOND_COMMAND_CLEAR_SESSION,
.session = {},
.domain = {},
.u = {},
ssize_t comm_ret;
int ret;
- if (session_name == NULL) {
+ if (session_name == nullptr) {
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;
}
if (sessiond_socket >= 0) {
ret = close(sessiond_socket);