X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fagent.cpp;h=31f1634bd70b70a681b6479433e0eb743fe72492;hb=6d31b87d46a9301fe86d273616ab3d7214d24e65;hp=b0ac94b1300a11e98fc83683028c149887419d56;hpb=48b7cdc221a445188d6d9bd08fc1686837e71224;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/agent.cpp b/src/bin/lttng-sessiond/agent.cpp index b0ac94b13..31f1634bd 100644 --- a/src/bin/lttng-sessiond/agent.cpp +++ b/src/bin/lttng-sessiond/agent.cpp @@ -11,24 +11,24 @@ #include #include -#include +#include #include #include #include #include #include -#include -#include +#include +#include -#include -#include +#include +#include -#include +#include -#include "agent.h" -#include "ust-app.h" -#include "utils.h" -#include "common/error.h" +#include "agent.hpp" +#include "ust-app.hpp" +#include "utils.hpp" +#include "common/error.hpp" typedef enum lttng_event_rule_status (*event_rule_logging_get_name_pattern)( const struct lttng_event_rule *rule, const char **pattern); @@ -39,6 +39,7 @@ typedef enum lttng_event_rule_status (*event_rule_logging_get_log_level_rule)( /* * Agent application context representation. */ +namespace { struct agent_app_ctx { char *provider_name; char *ctx_name; @@ -49,6 +50,7 @@ struct agent_app_ctx { /* For call_rcu teardown. */ struct rcu_head rcu_node; }; +} /* namespace */ /* * Human readable agent return code. @@ -200,9 +202,9 @@ static void add_unique_agent_event(struct lttng_ht *ht, static void destroy_event_agent_rcu(struct rcu_head *head) { struct lttng_ht_node_str *node = - caa_container_of(head, struct lttng_ht_node_str, head); + lttng::utils::container_of(head, <tng_ht_node_str::head); struct agent_event *event = - caa_container_of(node, struct agent_event, node); + lttng::utils::container_of(node, &agent_event::node); agent_destroy_event(event); } @@ -213,9 +215,9 @@ static void destroy_event_agent_rcu(struct rcu_head *head) static void destroy_app_agent_rcu(struct rcu_head *head) { struct lttng_ht_node_ulong *node = - caa_container_of(head, struct lttng_ht_node_ulong, head); + lttng::utils::container_of(head, <tng_ht_node_ulong::head); struct agent_app *app = - caa_container_of(node, struct agent_app, node); + lttng::utils::container_of(node, &agent_app::node); free(app); } @@ -348,7 +350,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events) goto error; } - reply = (lttcomm_agent_list_reply *) zmalloc(data_size); + reply = zmalloc(data_size); if (!reply) { ret = LTTNG_ERR_NOMEM; goto error; @@ -361,7 +363,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events) } nb_event = be32toh(reply->nb_event); - tmp_events = (lttng_event *) zmalloc(sizeof(*tmp_events) * nb_event); + tmp_events = calloc(nb_event); if (!tmp_events) { ret = LTTNG_ERR_NOMEM; goto error; @@ -441,7 +443,7 @@ static int enable_event(const struct agent_app *app, struct agent_event *event) goto error_io; } - bytes_to_send = (char *) zmalloc(data_size); + bytes_to_send = calloc(data_size); if (!bytes_to_send) { ret = LTTNG_ERR_NOMEM; goto error; @@ -726,7 +728,7 @@ struct agent_app_ctx *create_app_ctx(const struct lttng_event_context *ctx) } LTTNG_ASSERT(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT); - agent_ctx = (agent_app_ctx *) zmalloc(sizeof(*ctx)); + agent_ctx = zmalloc(); if (!agent_ctx) { goto end; } @@ -898,7 +900,7 @@ int agent_list_events(struct lttng_event **events, DBG2("Agent listing events for domain %d", domain); nbmem = UST_APP_EVENT_LIST_SIZE; - tmp_events = (lttng_event *) zmalloc(nbmem * sizeof(*tmp_events)); + tmp_events = calloc(nbmem); if (!tmp_events) { PERROR("zmalloc agent list events"); ret = -ENOMEM; @@ -974,7 +976,7 @@ struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, LTTNG_ASSERT(sock); - app = (agent_app *) zmalloc(sizeof(*app)); + app = zmalloc(); if (!app) { PERROR("Failed to allocate agent application instance"); goto error; @@ -1011,7 +1013,7 @@ struct agent_app *agent_find_app_by_sock(int sock) if (node == NULL) { goto error; } - app = caa_container_of(node, struct agent_app, node); + app = lttng::utils::container_of(node, &agent_app::node); DBG3("Agent app pid %d found by sock %d.", app->pid, sock); return app; @@ -1117,7 +1119,7 @@ struct agent *agent_create(enum lttng_domain_type domain) int ret; struct agent *agt; - agt = (agent *) zmalloc(sizeof(struct agent)); + agt = zmalloc(); if (!agt) { goto error; } @@ -1156,7 +1158,7 @@ struct agent_event *agent_create_event(const char *name, goto error; } - event = (agent_event *) zmalloc(sizeof(*event)); + event = zmalloc(); if (!event) { goto error; } @@ -1386,7 +1388,7 @@ struct agent_event *agent_find_event(const char *name, } DBG3("Agent event found %s.", name); - return caa_container_of(node, struct agent_event, node); + return lttng::utils::container_of(node, &agent_event::node); error: DBG3("Agent event NOT found %s.", name); @@ -1412,7 +1414,7 @@ static void destroy_app_ctx_rcu(struct rcu_head *head) { struct agent_app_ctx *ctx = - caa_container_of(head, struct agent_app_ctx, rcu_node); + lttng::utils::container_of(head, &agent_app_ctx::rcu_node); destroy_app_ctx(ctx); } @@ -1441,7 +1443,7 @@ void agent_destroy(struct agent *agt) * value is not important since we have to continue anyway * destroying the object. */ - event = caa_container_of(node, struct agent_event, node); + event = lttng::utils::container_of(node, &agent_event::node); (void) agent_disable_event(event, agt->domain); ret = lttng_ht_del(agt->events, &iter); @@ -1510,7 +1512,7 @@ void agent_app_ht_clean(void) the_agent_apps_ht_by_sock->ht, &iter.iter, node, node) { struct agent_app *app; - app = caa_container_of(node, struct agent_app, node); + app = lttng::utils::container_of(node, &agent_app::node); agent_destroy_app_by_sock(app->sock->fd); } rcu_read_unlock(); @@ -1596,7 +1598,7 @@ void agent_by_event_notifier_domain_ht_destroy(void) cds_lfht_for_each_entry(the_trigger_agents_ht_by_domain->ht, &iter.iter, node, node) { struct agent *agent = - caa_container_of(node, struct agent, node); + lttng::utils::container_of(node, &agent::node); const int ret = lttng_ht_del( the_trigger_agents_ht_by_domain, &iter); @@ -1627,7 +1629,7 @@ struct agent *agent_find_by_event_notifier_domain( goto end; } - agt = caa_container_of(node, struct agent, node); + agt = lttng::utils::container_of(node, &agent::node); end: return agt;