#include <common/filter/filter-ast.hpp>
#include <common/filter/filter-parser.hpp>
#include <common/filter/memstream.hpp>
+#include <common/make-unique-wrapper.hpp>
#include <common/payload-view.hpp>
#include <common/payload.hpp>
#include <common/sessiond-comm/sessiond-comm.hpp>
#include <string.h>
#include <unistd.h>
-#define COPY_DOMAIN_PACKED(dst, src) \
- do { \
- struct lttng_domain _tmp_domain; \
- \
- lttng_ctl_copy_lttng_domain(&_tmp_domain, &src); \
- dst = _tmp_domain; \
+#define COPY_DOMAIN_PACKED(dst, src) \
+ do { \
+ struct lttng_domain _tmp_domain; \
+ \
+ lttng_ctl_copy_lttng_domain(&_tmp_domain, &(src)); \
+ (dst) = _tmp_domain; \
} while (0)
/* Socket to session daemon for communication */
*
* If yes return 1, else return -1.
*/
-int lttng_check_tracing_group(void)
+int lttng_check_tracing_group()
{
gid_t *grp_list, tracing_gid;
int grp_list_size, grp_id, i;
}
/* Get number of supplementary group IDs */
- grp_list_size = getgroups(0, NULL);
+ grp_list_size = getgroups(0, nullptr);
if (grp_list_size < 0) {
PERROR("getgroups");
goto end;
* Returns 0 on success, negative value on failure (the sessiond socket path
* is somehow too long or ENOMEM).
*/
-static int set_session_daemon_path(void)
+static int set_session_daemon_path()
{
int in_tgroup = 0; /* In tracing group. */
uid_t uid;
*
* On success, return the socket's file descriptor. On error, return -1.
*/
-int connect_sessiond(void)
+int connect_sessiond()
{
int ret;
return -1;
}
-static void reset_global_sessiond_connection_state(void)
+static void reset_global_sessiond_connection_state()
{
sessiond_socket = -1;
connected = 0;
*
* On success, return 0. On error, return -1.
*/
-static int disconnect_sessiond(void)
+static int disconnect_sessiond()
{
int ret = 0;
static int recv_sessiond_optional_data(size_t len, void **user_buf, size_t *user_len)
{
int ret = 0;
- char *buf = NULL;
+ char *buf = nullptr;
if (len) {
if (!user_len) {
/* Move ownership of command header buffer to user. */
*user_buf = buf;
- buf = NULL;
+ buf = nullptr;
*user_len = len;
} else {
/* No command header. */
}
if (user_buf) {
- *user_buf = NULL;
+ *user_buf = nullptr;
}
}
struct lttng_handle *lttng_create_handle(const char *session_name, struct lttng_domain *domain)
{
int ret;
- struct lttng_handle *handle = NULL;
+ struct lttng_handle *handle = nullptr;
handle = zmalloc<lttng_handle>();
- if (handle == NULL) {
+ if (handle == nullptr) {
PERROR("malloc handle");
goto end;
}
return handle;
error:
free(handle);
- return NULL;
+ return nullptr;
}
/*
int ret;
struct lttcomm_session_msg lsm;
- if (handle == NULL || socket_path == NULL) {
+ if (handle == nullptr || socket_path == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
goto end;
}
- ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ ret = lttng_ctl_ask_sessiond(&lsm, nullptr);
end:
return ret;
}
int ret;
struct lttcomm_session_msg lsm;
- if (session_name == NULL) {
+ if (session_name == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
goto end;
}
- ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ ret = lttng_ctl_ask_sessiond(&lsm, nullptr);
end:
return ret;
}
int ret, data_ret;
struct lttcomm_session_msg lsm;
- if (session_name == NULL) {
+ if (session_name == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto error;
}
goto error;
}
- ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ ret = lttng_ctl_ask_sessiond(&lsm, nullptr);
if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
goto error;
}
lttng_payload_init(&payload);
/* Safety check. Both are mandatory. */
- if (handle == NULL || ctx == NULL) {
+ if (handle == nullptr || ctx == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
struct lttng_event *ev,
const char *channel_name)
{
- return lttng_enable_event_with_exclusions(handle, ev, channel_name, NULL, 0, NULL);
+ return lttng_enable_event_with_exclusions(handle, ev, channel_name, nullptr, 0, nullptr);
}
/*
const char *filter_expression)
{
return lttng_enable_event_with_exclusions(
- handle, event, channel_name, filter_expression, 0, NULL);
+ handle, event, channel_name, filter_expression, 0, nullptr);
}
/*
static char *set_agent_filter(const char *filter, struct lttng_event *ev)
{
int err;
- char *agent_filter = NULL;
+ char *agent_filter = nullptr;
LTTNG_ASSERT(ev);
return agent_filter;
error:
free(agent_filter);
- return NULL;
+ return nullptr;
}
/*
struct lttng_payload payload;
int ret = 0;
unsigned int free_filter_expression = 0;
- struct filter_parser_ctx *ctx = NULL;
+ struct filter_parser_ctx *ctx = nullptr;
size_t bytecode_len = 0;
/*
*/
char *filter_expression = (char *) original_filter_expression;
- if (handle == NULL || ev == NULL) {
+ if (handle == nullptr || ev == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto error;
}
}
/* Parse filter expression. */
- if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL ||
+ if (filter_expression != nullptr || handle->domain.type == LTTNG_DOMAIN_JUL ||
handle->domain.type == LTTNG_DOMAIN_LOG4J ||
handle->domain.type == LTTNG_DOMAIN_PYTHON) {
if (handle->domain.type == LTTNG_DOMAIN_JUL ||
exclusion_list,
filter_expression,
bytecode_len,
- (ctx && bytecode_len) ? &ctx->bytecode->b : NULL,
+ (ctx && bytecode_len) ? &ctx->bytecode->b : nullptr,
&payload);
if (ret) {
ret = -LTTNG_ERR_INVALID;
lsm.fd_count = fd_count;
ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm,
- fd_count ? &fd_to_send : NULL,
+ fd_count ? &fd_to_send : nullptr,
fd_count,
- view.buffer.size ? view.buffer.data : NULL,
+ view.buffer.size ? view.buffer.data :
+ nullptr,
view.buffer.size,
- NULL,
- NULL,
- 0);
+ nullptr,
+ nullptr,
+ nullptr);
}
error:
struct lttng_payload payload;
int ret = 0;
unsigned int free_filter_expression = 0;
- struct filter_parser_ctx *ctx = NULL;
+ struct filter_parser_ctx *ctx = nullptr;
size_t bytecode_len = 0;
/*
*/
char *filter_expression = (char *) original_filter_expression;
- if (handle == NULL || ev == NULL) {
+ if (handle == nullptr || ev == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto error;
}
}
/* Parse filter expression. */
- if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL ||
+ if (filter_expression != nullptr || handle->domain.type == LTTNG_DOMAIN_JUL ||
handle->domain.type == LTTNG_DOMAIN_LOG4J ||
handle->domain.type == LTTNG_DOMAIN_PYTHON) {
if (handle->domain.type == LTTNG_DOMAIN_JUL ||
serialize:
ret = lttng_event_serialize(ev,
0,
- NULL,
+ nullptr,
filter_expression,
bytecode_len,
- (ctx && bytecode_len) ? &ctx->bytecode->b : NULL,
+ (ctx && bytecode_len) ? &ctx->bytecode->b : nullptr,
&payload);
if (ret) {
ret = -LTTNG_ERR_INVALID;
}
ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm,
- fd_count ? &fd_to_send : NULL,
+ fd_count ? &fd_to_send : nullptr,
fd_count,
- view.buffer.size ? view.buffer.data : NULL,
+ view.buffer.size ? view.buffer.data :
+ nullptr,
view.buffer.size,
- NULL,
- NULL,
- 0);
+ nullptr,
+ nullptr,
+ nullptr);
}
error:
goto end;
}
- ret = lttng_disable_event_ext(handle, &ev, channel_name, NULL);
+ ret = lttng_disable_event_ext(handle, &ev, channel_name, nullptr);
end:
return ret;
}
struct lttng_channel *lttng_channel_create(struct lttng_domain *domain)
{
- struct lttng_channel *channel = NULL;
+ struct lttng_channel *channel = nullptr;
if (!domain) {
goto end;
struct lttng_dynamic_buffer buffer;
struct lttcomm_session_msg lsm;
uint64_t total_buffer_size_needed_per_cpu = 0;
- struct lttng_channel *channel = NULL;
+ struct lttng_channel *channel = nullptr;
lttng_dynamic_buffer_init(&buffer);
/* NULL arguments are forbidden. No default values. */
- if (handle == NULL || in_chan == NULL) {
+ if (handle == nullptr || in_chan == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
lsm.u.channel.length = buffer.size;
- ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buffer.data, buffer.size, NULL);
+ ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buffer.data, buffer.size, nullptr);
end:
lttng_channel_destroy(channel);
lttng_dynamic_buffer_reset(&buffer);
struct lttcomm_session_msg lsm;
/* Safety check. Both are mandatory. */
- if (handle == NULL || name == NULL) {
+ if (handle == nullptr || name == nullptr) {
return -LTTNG_ERR_INVALID;
}
goto end;
}
- ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ ret = lttng_ctl_ask_sessiond(&lsm, nullptr);
end:
return ret;
}
{
enum lttng_error_code ret_code;
int ret, total_payload_received;
- char *reception_buffer = NULL;
+ char *reception_buffer = nullptr;
struct lttcomm_session_msg lsm = {
.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINTS,
.session = {},
.u = {},
.fd_count = 0,
};
- struct lttcomm_list_command_header *cmd_header = NULL;
+ struct lttcomm_list_command_header *cmd_header = nullptr;
size_t cmd_header_len;
unsigned int nb_events = 0;
- if (handle == NULL) {
+ if (handle == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
COPY_DOMAIN_PACKED(lsm.domain, handle->domain);
ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm,
- NULL,
+ nullptr,
0,
- NULL,
+ nullptr,
0,
(void **) &reception_buffer,
(void **) &cmd_header,
enum lttng_error_code ret_code;
int ret;
struct lttcomm_session_msg lsm;
- const struct lttcomm_list_command_header *cmd_header = NULL;
+ const struct lttcomm_list_command_header *cmd_header = nullptr;
unsigned int nb_event_fields = 0;
struct lttng_payload reply;
lttng_payload_init(&reply);
- if (handle == NULL) {
+ if (handle == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
{
enum lttng_error_code ret_code;
int ret, total_payload_received;
- char *reception_buffer = NULL;
+ char *reception_buffer = nullptr;
struct lttcomm_session_msg lsm = {};
- struct lttcomm_list_command_header *cmd_header = NULL;
+ struct lttcomm_list_command_header *cmd_header = nullptr;
size_t cmd_header_len;
uint32_t nb_events = 0;
lsm.domain.type = LTTNG_DOMAIN_KERNEL;
ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm,
- NULL,
+ nullptr,
0,
- NULL,
+ nullptr,
0,
(void **) &reception_buffer,
(void **) &cmd_header,
.u = {},
.fd_count = 0,
};
- void *reply = NULL;
+ void *reply = nullptr;
struct lttng_buffer_view reply_view;
int reply_ret;
bool sessiond_must_generate_ouput;
struct lttng_dynamic_buffer payload;
int ret;
size_t descriptor_size;
- struct lttng_session_descriptor *descriptor_reply = NULL;
+ struct lttng_session_descriptor *descriptor_reply = nullptr;
lttng_dynamic_buffer_init(&payload);
if (!session_descriptor) {
{
int ret;
ssize_t size;
- struct lttng_uri *uris = NULL;
- struct lttng_session_descriptor *descriptor = NULL;
+ struct lttng_uri *uris = nullptr;
+ struct lttng_session_descriptor *descriptor = nullptr;
enum lttng_error_code ret_code;
if (!name) {
goto end;
}
- size = uri_parse_str_urls(url, NULL, &uris);
+ size = uri_parse_str_urls(url, nullptr, &uris);
if (size < 0) {
ret = -LTTNG_ERR_INVALID;
goto end;
descriptor = lttng_session_descriptor_local_create(name, uris[0].dst.path);
break;
case 2:
- descriptor = lttng_session_descriptor_network_create(name, url, NULL);
+ descriptor = lttng_session_descriptor_network_create(name, url, nullptr);
break;
default:
ret = -LTTNG_ERR_INVALID;
int ret;
enum lttng_error_code ret_code;
ssize_t size;
- struct lttng_uri *uris = NULL;
- struct lttng_session_descriptor *descriptor = NULL;
+ struct lttng_uri *uris = nullptr;
+ struct lttng_session_descriptor *descriptor = nullptr;
if (!name) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
- size = uri_parse_str_urls(snapshot_url, NULL, &uris);
+ size = uri_parse_str_urls(snapshot_url, nullptr, &uris);
if (size < 0) {
ret = -LTTNG_ERR_INVALID;
goto end;
descriptor = lttng_session_descriptor_snapshot_local_create(name, uris[0].dst.path);
break;
case 2:
- descriptor =
- lttng_session_descriptor_snapshot_network_create(name, snapshot_url, NULL);
+ descriptor = lttng_session_descriptor_snapshot_network_create(
+ name, snapshot_url, nullptr);
break;
default:
ret = -LTTNG_ERR_INVALID;
{
int ret;
enum lttng_error_code ret_code;
- struct lttng_session_descriptor *descriptor = NULL;
+ struct lttng_session_descriptor *descriptor = nullptr;
if (!name) {
ret = -LTTNG_ERR_INVALID;
if (url) {
descriptor = lttng_session_descriptor_live_network_create(
- name, url, NULL, timer_interval);
+ name, url, nullptr, timer_interval);
} else {
descriptor = lttng_session_descriptor_live_create(name, timer_interval);
}
int ret;
enum lttng_error_code ret_code;
enum lttng_destruction_handle_status status;
- struct lttng_destruction_handle *handle = NULL;
+ struct lttng_destruction_handle *handle = nullptr;
/*
* Stop the tracing and wait for the data to be
{
enum lttng_error_code ret_code;
- ret_code = lttng_destroy_session_ext(session_name, NULL);
+ ret_code = lttng_destroy_session_ext(session_name, nullptr);
return ret_code == LTTNG_OK ? 0 : -ret_code;
}
sizeof(struct lttng_session) + sizeof(struct lttng_session_extended);
size_t session_count, i;
struct lttng_session_extended *sessions_extended_begin;
- struct lttng_session *sessions = NULL;
+ struct lttng_session *sessions = nullptr;
memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_SESSIONS;
* lttng_list_sessions returns 0, thus allowing *out_sessions to
* be subsequently freed.
*/
- *out_sessions = NULL;
+ *out_sessions = nullptr;
ret = lttng_ctl_ask_sessiond(&lsm, (void **) &sessions);
if (ret <= 0) {
goto end;
int ret;
struct lttcomm_session_msg lsm;
- if (session_name == NULL) {
+ if (session_name == nullptr) {
return -LTTNG_ERR_INVALID;
}
goto end;
}
- ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ ret = lttng_ctl_ask_sessiond(&lsm, nullptr);
end:
return ret;
}
int ret;
struct lttcomm_session_msg lsm;
- if (session_name == NULL) {
+ if (session_name == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto error;
}
{
int ret, total_payload_received;
struct lttcomm_session_msg lsm;
- char *reception_buffer = NULL;
+ char *reception_buffer = nullptr;
size_t cmd_header_len = 0;
- struct lttcomm_list_command_header *cmd_header = NULL;
+ struct lttcomm_list_command_header *cmd_header = nullptr;
struct lttng_dynamic_buffer tmp_buffer;
lttng_dynamic_buffer_init(&tmp_buffer);
- if (handle == NULL) {
+ if (handle == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
COPY_DOMAIN_PACKED(lsm.domain, handle->domain);
ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm,
- NULL,
+ nullptr,
0,
- NULL,
+ nullptr,
0,
(void **) &reception_buffer,
(void **) &cmd_header,
lttng_payload_init(&reply);
/* Safety check. An handle and channel name are mandatory. */
- if (handle == NULL || channel_name == NULL) {
+ if (handle == nullptr || channel_name == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
}
{
- const struct lttcomm_list_command_header *cmd_reply_header = NULL;
+ const struct lttcomm_list_command_header *cmd_reply_header = nullptr;
const lttng_payload_view cmd_reply_header_view =
lttng_payload_view_from_payload(&reply, 0, sizeof(*cmd_reply_header));
int ret = 0;
char *new_group;
- if (name == NULL) {
+ if (name == nullptr) {
ret = -LTTNG_ERR_INVALID;
goto end;
}
free(tracing_group);
tracing_group = new_group;
- new_group = NULL;
+ new_group = nullptr;
end:
return ret;
struct lttng_channel_extended *extended;
/* Safety check */
- if (attr == NULL || domain == NULL) {
+ if (attr == nullptr || domain == nullptr) {
return;
}
int ret;
ssize_t size;
struct lttcomm_session_msg lsm;
- struct lttng_uri *uris = NULL;
+ struct lttng_uri *uris = nullptr;
- if (handle == NULL || (control_url == NULL && data_url == NULL)) {
+ if (handle == nullptr || (control_url == nullptr && data_url == nullptr)) {
ret = -LTTNG_ERR_INVALID;
goto error;
}
lsm.u.uri.size = size;
ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(
- &lsm, uris, sizeof(struct lttng_uri) * size, NULL);
+ &lsm, uris, sizeof(struct lttng_uri) * size, nullptr);
free(uris);
error:
{
int ret;
struct lttcomm_session_msg lsm;
- uint8_t *pending = NULL;
+ uint8_t *pending = nullptr;
- if (session_name == NULL) {
+ if (session_name == nullptr) {
return -LTTNG_ERR_INVALID;
}
return ret;
}
+/*
+ * Get the status of the kernel tracer
+ *
+ * Sets the value of the argument
+ */
+enum lttng_error_code lttng_get_kernel_tracer_status(enum lttng_kernel_tracer_status *out_status)
+{
+ if (out_status == nullptr) {
+ return LTTNG_ERR_INVALID;
+ }
+
+ struct lttcomm_session_msg lsm = {};
+ lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_KERNEL_TRACER_STATUS;
+
+ uint32_t *raw_tracer_status = nullptr;
+ const auto ask_ret = lttng_ctl_ask_sessiond(&lsm, (void **) &raw_tracer_status);
+
+ const auto tracer_status =
+ lttng::make_unique_wrapper<uint32_t, lttng::memory::free>(raw_tracer_status);
+
+ if (ask_ret != 4) {
+ return LTTNG_ERR_INVALID;
+ }
+
+ *out_status = (enum lttng_kernel_tracer_status) * tracer_status;
+ return LTTNG_OK;
+}
+
/*
* Regenerate the metadata for a session.
* Return 0 on success, a negative error code on error.
goto end;
}
- ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ ret = lttng_ctl_ask_sessiond(&lsm, nullptr);
if (ret < 0) {
goto end;
}
goto end;
}
- ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ ret = lttng_ctl_ask_sessiond(&lsm, nullptr);
if (ret < 0) {
goto end;
}
struct lttcomm_session_msg *message_lsm;
struct lttng_payload message;
struct lttng_payload reply;
- struct lttng_trigger *reply_trigger = NULL;
+ struct lttng_trigger *reply_trigger = nullptr;
enum lttng_domain_type domain_type;
const struct lttng_credentials user_creds = {
.uid = LTTNG_OPTIONAL_INIT_VALUE(geteuid()),
.gid = LTTNG_OPTIONAL_INIT_UNSET,
};
- const char *unused_trigger_name = NULL;
+ const char *unused_trigger_name = nullptr;
enum lttng_trigger_status trigger_status;
lttng_payload_init(&message);
goto end;
end_unset_name:
- trigger_status = lttng_trigger_set_name(trigger, NULL);
+ trigger_status = lttng_trigger_set_name(trigger, nullptr);
if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
ret = -LTTNG_ERR_UNK;
}
int lttng_register_trigger(struct lttng_trigger *trigger)
{
/* Register an anonymous trigger. */
- return _lttng_register_trigger(trigger, NULL, false);
+ return _lttng_register_trigger(trigger, nullptr, false);
}
enum lttng_error_code lttng_register_trigger_with_name(struct lttng_trigger *trigger,
struct lttcomm_session_msg *message_lsm;
struct lttng_payload message;
struct lttng_payload reply;
- struct lttng_trigger *copy = NULL;
+ struct lttng_trigger *copy = nullptr;
const struct lttng_credentials user_creds = {
.uid = LTTNG_OPTIONAL_INIT_VALUE(geteuid()),
.gid = LTTNG_OPTIONAL_INIT_UNSET,
.u = {},
.fd_count = 0,
};
- struct lttng_triggers *local_triggers = NULL;
+ struct lttng_triggers *local_triggers = nullptr;
struct lttng_payload reply;
struct lttng_payload_view lsm_view =
lttng_payload_view_init_from_buffer((const char *) &lsm, 0, sizeof(lsm));
}
*triggers = local_triggers;
- local_triggers = NULL;
+ local_triggers = nullptr;
end:
lttng_payload_reset(&reply);
lttng_triggers_destroy(local_triggers);
/*
* lib constructor.
*/
-static void __attribute__((constructor)) init(void)
+static void __attribute__((constructor)) init()
{
/* Set default session group */
lttng_set_tracing_group(DEFAULT_TRACING_GROUP);
/*
* lib destructor.
*/
-static void __attribute__((destructor)) lttng_ctl_exit(void)
+static void __attribute__((destructor)) lttng_ctl_exit()
{
free(tracing_group);
}