X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fagent.c;h=9091a53d7822011e38e97282e56cdcaaea43b97c;hp=b267503fcbcec3e58890fda360c507496645afe6;hb=f1bc01296844846c89e13f34376461f57387d999;hpb=f60140a188c6c0cd1acf948c37e338e96a74be8d diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index b267503fc..9091a53d7 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -16,6 +16,7 @@ */ #define _GNU_SOURCE +#define _LGPL_SOURCE #include #include @@ -443,7 +444,7 @@ int agent_send_registration_done(struct agent_app *app) DBG("Agent sending registration done to app socket %d", app->sock->fd); - return send_header(app->sock, 0, AGENT_CMD_REG_DONE, 0); + return send_header(app->sock, 0, AGENT_CMD_REG_DONE, 1); } /* @@ -493,11 +494,14 @@ error: int agent_disable_event(struct agent_event *event, enum lttng_domain_type domain) { - int ret; + int ret = LTTNG_OK; struct agent_app *app; struct lttng_ht_iter iter; assert(event); + if (!event->enabled) { + goto end; + } rcu_read_lock(); @@ -515,10 +519,10 @@ int agent_disable_event(struct agent_event *event, } event->enabled = 0; - ret = LTTNG_OK; error: rcu_read_unlock(); +end: return ret; } @@ -539,6 +543,8 @@ int agent_list_events(struct lttng_event **events, assert(events); + DBG2("Agent listing events for domain %d", domain); + nbmem = UST_APP_EVENT_LIST_SIZE; tmp_events = zmalloc(nbmem * sizeof(*tmp_events)); if (!tmp_events) { @@ -677,6 +683,8 @@ void agent_add_app(struct agent_app *app) /* * Delete agent application from the global hash table. + * + * rcu_read_lock() must be held by the caller. */ void agent_delete_app(struct agent_app *app) { @@ -688,14 +696,12 @@ void agent_delete_app(struct agent_app *app) DBG3("Agent deleting app pid: %d and sock: %d", app->pid, app->sock->fd); iter.iter.node = &app->node.node; - rcu_read_lock(); ret = lttng_ht_del(agent_apps_ht_by_sock, &iter); - rcu_read_unlock(); assert(!ret); } /* - * Destroy a agent application object by detaching it from its corresponding + * Destroy an agent application object by detaching it from its corresponding * UST app if one is connected by closing the socket. Finally, perform a * delayed memory reclaim. */ @@ -769,6 +775,7 @@ struct agent *agent_create(enum lttng_domain_type domain) ret = agent_init(agt); if (ret < 0) { free(agt); + agt = NULL; goto error; } @@ -896,7 +903,7 @@ struct agent_event *agent_find_event(const char *name, int loglevel, return caa_container_of(node, struct agent_event, node); error: - DBG3("Agent NOT found %s.", name); + DBG3("Agent event NOT found %s.", name); return NULL; } @@ -909,6 +916,7 @@ void agent_destroy_event(struct agent_event *event) { assert(event); + free(event->filter); free(event); } @@ -952,20 +960,71 @@ void agent_destroy(struct agent *agt) } rcu_read_unlock(); - lttng_ht_destroy(agt->events); + ht_cleanup_push(agt->events); } /* - * Initialize agent subsystem. + * Allocate agent_apps_ht_by_sock. */ -int agent_setup(void) +int agent_app_ht_alloc(void) { + int ret = 0; + agent_apps_ht_by_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); if (!agent_apps_ht_by_sock) { - return -1; + ret = -1; } - return 0; + return ret; +} + +/* + * Destroy a agent application by socket. + */ +void agent_destroy_app_by_sock(int sock) +{ + struct agent_app *app; + + assert(sock >= 0); + + /* + * Not finding an application is a very important error that should NEVER + * happen. The hash table deletion is ONLY done through this call when the + * main sessiond thread is torn down. + */ + rcu_read_lock(); + app = agent_find_app_by_sock(sock); + assert(app); + + /* RCU read side lock is assumed to be held by this function. */ + agent_delete_app(app); + + /* The application is freed in a RCU call but the socket is closed here. */ + agent_destroy_app(app); + rcu_read_unlock(); +} + +/* + * Clean-up the agent app hash table and destroy it. + */ +void agent_app_ht_clean(void) +{ + struct lttng_ht_node_ulong *node; + struct lttng_ht_iter iter; + + if (!agent_apps_ht_by_sock) { + return; + } + rcu_read_lock(); + cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, node, node) { + struct agent_app *app; + + app = caa_container_of(node, struct agent_app, node); + agent_destroy_app_by_sock(app->sock->fd); + } + rcu_read_unlock(); + + lttng_ht_destroy(agent_apps_ht_by_sock); } /*