X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fagent.cpp;h=2a880a19c800722a6f3bc4c785f43632e61aef28;hb=f149493493fbd8a3efa4748832c03278c96c38ca;hp=620ec787f01833b9ed1e9d9899d3d8755fe44397;hpb=3c3390532736cfb5198f863d0d2b218e21fcf76d;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/agent.cpp b/src/bin/lttng-sessiond/agent.cpp index 620ec787f..2a880a19c 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. @@ -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; @@ -1003,6 +1005,7 @@ struct agent_app *agent_find_app_by_sock(int sock) struct agent_app *app; LTTNG_ASSERT(sock >= 0); + ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(the_agent_apps_ht_by_sock, (void *) ((unsigned long) sock), &iter); @@ -1042,6 +1045,7 @@ void agent_delete_app(struct agent_app *app) struct lttng_ht_iter iter; LTTNG_ASSERT(app); + ASSERT_RCU_READ_LOCKED(); DBG3("Agent deleting app pid: %d and sock: %d", app->pid, app->sock->fd); @@ -1115,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; } @@ -1154,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; } @@ -1229,6 +1233,7 @@ void agent_find_events_by_name(const char *name, struct agent *agt, LTTNG_ASSERT(agt); LTTNG_ASSERT(agt->events); LTTNG_ASSERT(iter); + ASSERT_RCU_READ_LOCKED(); ht = agt->events; key.name = name; @@ -1264,6 +1269,7 @@ struct agent_event *agent_find_event_by_trigger( LTTNG_ASSERT(agt); LTTNG_ASSERT(agt->events); + ASSERT_RCU_READ_LOCKED(); condition = lttng_trigger_get_const_condition(trigger); @@ -1336,6 +1342,8 @@ void agent_event_next_duplicate(const char *name, { struct agent_ht_key key; + ASSERT_RCU_READ_LOCKED(); + key.name = name; cds_lfht_next_duplicate(agt->events->ht, ht_match_event_by_name, @@ -1364,6 +1372,7 @@ struct agent_event *agent_find_event(const char *name, LTTNG_ASSERT(name); LTTNG_ASSERT(agt); LTTNG_ASSERT(agt->events); + ASSERT_RCU_READ_LOCKED(); ht = agt->events; key.name = name;