X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=2b99bbc993e8d9570b4b50744ec139f04926b4eb;hb=6a4e403927ffef4cae8726064dcf53c463eb128c;hp=c542179371327b951d71255902b949c789f265fd;hpb=d7ba13889c8692b14f99238ddf2721ed78df89d2;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index c54217937..2b99bbc99 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -135,16 +135,16 @@ static struct consumer_data ustconsumer32_data = { static const struct option long_options[] = { { "client-sock", 1, 0, 'c' }, { "apps-sock", 1, 0, 'a' }, - { "kconsumerd-cmd-sock", 1, 0, 'C' }, - { "kconsumerd-err-sock", 1, 0, 'E' }, - { "ustconsumerd32-cmd-sock", 1, 0, 'G' }, - { "ustconsumerd32-err-sock", 1, 0, 'H' }, - { "ustconsumerd64-cmd-sock", 1, 0, 'D' }, - { "ustconsumerd64-err-sock", 1, 0, 'F' }, - { "consumerd32-path", 1, 0, 'u' }, - { "consumerd32-libdir", 1, 0, 'U' }, - { "consumerd64-path", 1, 0, 't' }, - { "consumerd64-libdir", 1, 0, 'T' }, + { "kconsumerd-cmd-sock", 1, 0, '\0' }, + { "kconsumerd-err-sock", 1, 0, '\0' }, + { "ustconsumerd32-cmd-sock", 1, 0, '\0' }, + { "ustconsumerd32-err-sock", 1, 0, '\0' }, + { "ustconsumerd64-cmd-sock", 1, 0, '\0' }, + { "ustconsumerd64-err-sock", 1, 0, '\0' }, + { "consumerd32-path", 1, 0, '\0' }, + { "consumerd32-libdir", 1, 0, '\0' }, + { "consumerd64-path", 1, 0, '\0' }, + { "consumerd64-libdir", 1, 0, '\0' }, { "daemonize", 0, 0, 'd' }, { "background", 0, 0, 'b' }, { "sig-parent", 0, 0, 'S' }, @@ -153,14 +153,14 @@ static const struct option long_options[] = { { "version", 0, 0, 'V' }, { "quiet", 0, 0, 'q' }, { "verbose", 0, 0, 'v' }, - { "verbose-consumer", 0, 0, 'Z' }, - { "no-kernel", 0, 0, 'N' }, + { "verbose-consumer", 0, 0, '\0' }, + { "no-kernel", 0, 0, '\0' }, { "pidfile", 1, 0, 'p' }, - { "agent-tcp-port", 1, 0, 'J' }, + { "agent-tcp-port", 1, 0, '\0' }, { "config", 1, 0, 'f' }, { "load", 1, 0, 'l' }, - { "kmod-probes", 1, 0, 'P' }, - { "extra-kmod-probes", 1, 0, 'e' }, + { "kmod-probes", 1, 0, '\0' }, + { "extra-kmod-probes", 1, 0, '\0' }, { NULL, 0, 0, 0 } }; @@ -676,6 +676,9 @@ static void sessiond_cleanup(void) } } + DBG("Cleaning up all agent apps"); + agent_app_ht_clean(); + DBG("Closing all UST sockets"); ust_app_clean_list(); buffer_reg_destroy_registries(); @@ -994,10 +997,30 @@ static void update_ust_app(int app_sock) /* For all tracing session(s) */ cds_list_for_each_entry_safe(sess, stmp, &session_list_ptr->head, list) { + struct ust_app *app; + session_lock(sess); - if (sess->ust_session) { - ust_app_global_update(sess->ust_session, app_sock); + if (!sess->ust_session) { + goto unlock_session; } + + rcu_read_lock(); + assert(app_sock >= 0); + app = ust_app_find_by_sock(app_sock); + if (app == NULL) { + /* + * Application can be unregistered before so + * this is possible hence simply stopping the + * update. + */ + DBG3("UST app update failed to find app sock %d", + app_sock); + goto unlock_rcu; + } + ust_app_global_update(sess->ust_session, app); + unlock_rcu: + rcu_read_unlock(); + unlock_session: session_unlock(sess); } } @@ -2766,6 +2789,9 @@ static int create_ust_session(struct ltt_session *session, lus->live_timer_interval = session->live_timer; session->ust_session = lus; if (session->shm_path[0]) { + strncpy(lus->root_shm_path, session->shm_path, + sizeof(lus->root_shm_path)); + lus->root_shm_path[sizeof(lus->root_shm_path) - 1] = '\0'; strncpy(lus->shm_path, session->shm_path, sizeof(lus->shm_path)); lus->shm_path[sizeof(lus->shm_path) - 1] = '\0'; @@ -2937,6 +2963,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, case LTTNG_LIST_CHANNELS: case LTTNG_LIST_EVENTS: case LTTNG_LIST_SYSCALLS: + case LTTNG_LIST_TRACKER_PIDS: break; default: /* Setup lttng message with no payload */ @@ -3249,6 +3276,20 @@ skip_domain: &cmd_ctx->lsm->u.channel.chan, kernel_poll_pipe[1]); break; } + case LTTNG_TRACK_PID: + { + ret = cmd_track_pid(cmd_ctx->session, + cmd_ctx->lsm->domain.type, + cmd_ctx->lsm->u.pid_tracker.pid); + break; + } + case LTTNG_UNTRACK_PID: + { + ret = cmd_untrack_pid(cmd_ctx->session, + cmd_ctx->lsm->domain.type, + cmd_ctx->lsm->u.pid_tracker.pid); + break; + } case LTTNG_ENABLE_EVENT: { struct lttng_event_exclusion *exclusion = NULL; @@ -3458,6 +3499,38 @@ skip_domain: ret = LTTNG_OK; break; } + case LTTNG_LIST_TRACKER_PIDS: + { + int32_t *pids = NULL; + ssize_t nr_pids; + + nr_pids = cmd_list_tracker_pids(cmd_ctx->session, + cmd_ctx->lsm->domain.type, &pids); + if (nr_pids < 0) { + /* Return value is a negative lttng_error_code. */ + ret = -nr_pids; + goto error; + } + + /* + * Setup lttng message with payload size set to the event list size in + * bytes and then copy list into the llm payload. + */ + ret = setup_lttng_msg(cmd_ctx, sizeof(int32_t) * nr_pids); + if (ret < 0) { + free(pids); + goto setup_error; + } + + /* Copy event list into message payload */ + memcpy(cmd_ctx->llm->payload, pids, + sizeof(int) * nr_pids); + + free(pids); + + ret = LTTNG_OK; + break; + } case LTTNG_SET_CONSUMER_URI: { size_t nb_uri, len; @@ -4609,6 +4682,10 @@ static int set_option(int opt, const char *arg, const char *optname) } else { unsigned long v; + if (!arg) { + ret = -EINVAL; + goto end; + } errno = 0; v = strtoul(arg, NULL, 0); if (errno != 0 || !isdigit(arg[0])) { @@ -5556,13 +5633,17 @@ int main(int argc, char **argv) * cleanup() can get called after that point. */ if (ust_app_ht_alloc()) { + ERR("Failed to allocate UST app hash table"); retval = -1; goto exit_init_data; } - /* Initialize agent domain subsystem. */ - if (agent_setup()) { - /* ENOMEM at this point. */ + /* + * Initialize agent app hash table. We allocate the hash table here + * since cleanup() can get called after this point. + */ + if (agent_app_ht_alloc()) { + ERR("Failed to allocate Agent app hash table"); retval = -1; goto exit_init_data; }