X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=lttng-sessiond%2Fmain.c;h=2e6292d38a7e567b84d96484d8be22c10f9e28eb;hp=fa196e7b033bfe07f97ac994803afc384c6f274c;hb=464dd62d5617322366e321877b440951e00a0152;hpb=c70c0ca0e8e46b29376d77b5b4483891cb33679d diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index fa196e7b0..2e6292d38 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -157,6 +157,8 @@ static struct ust_cmd_queue ust_cmd_queue; */ static struct ltt_session_list *session_list_ptr; +int ust_consumer_fd; + /* * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set. */ @@ -588,9 +590,9 @@ static int setup_lttng_msg(struct command_ctx *cmd_ctx, size_t size) buf_size = size; - cmd_ctx->llm = malloc(sizeof(struct lttcomm_lttng_msg) + buf_size); + cmd_ctx->llm = zmalloc(sizeof(struct lttcomm_lttng_msg) + buf_size); if (cmd_ctx->llm == NULL) { - perror("malloc"); + perror("zmalloc"); ret = -ENOMEM; goto error; } @@ -1260,9 +1262,9 @@ static void *thread_registration_apps(void *data) } /* Create UST registration command for enqueuing */ - ust_cmd = malloc(sizeof(struct ust_command)); + ust_cmd = zmalloc(sizeof(struct ust_command)); if (ust_cmd == NULL) { - perror("ust command malloc"); + perror("ust command zmalloc"); goto error; } @@ -1788,6 +1790,7 @@ static void list_lttng_sessions(struct lttng_session *sessions) sessions[i].path[PATH_MAX - 1] = '\0'; strncpy(sessions[i].name, session->name, NAME_MAX); sessions[i].name[NAME_MAX - 1] = '\0'; + sessions[i].enabled = session->enabled; i++; } } @@ -1879,6 +1882,7 @@ static int list_lttng_ust_global_events(char *channel_name, cds_lfht_for_each_entry(uchan->events, &iter, uevent, node) { strncpy(tmp[i].name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN); tmp[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; + tmp[i].enabled = uevent->enabled; switch (uevent->attr.instrumentation) { case LTTNG_UST_TRACEPOINT: tmp[i].type = LTTNG_EVENT_TRACEPOINT; @@ -2085,6 +2089,7 @@ static int cmd_enable_channel(struct ltt_session *session, ret = LTTCOMM_UST_CHAN_FAIL; goto error; } + rcu_read_lock(); hashtable_add_unique(usess->domain_global.channels, &uchan->node); rcu_read_unlock(); @@ -2095,11 +2100,13 @@ static int cmd_enable_channel(struct ltt_session *session, } /* Add channel to all registered applications */ - ret = ust_app_add_channel_all(usess, uchan); + ret = ust_app_create_channel_all(usess, uchan); if (ret != 0) { goto error; } + uchan->enabled = 1; + break; } case LTTNG_DOMAIN_UST_PID: @@ -2353,17 +2360,24 @@ static int cmd_enable_event(struct ltt_session *session, int domain, ret = LTTCOMM_FATAL; goto error; } + } - ret = ust_app_add_event_all(usess, uchan, uevent); + ret = ust_app_create_event_all(usess, uchan, uevent); if (ret < 0) { ret = LTTCOMM_UST_ENABLE_FAIL; goto error; } + /* Add ltt ust event to channel */ rcu_read_lock(); hashtable_add_unique(uchan->events, &uevent->node); rcu_read_unlock(); + + uevent->enabled = 1; + + DBG3("UST ltt event %s added to channel %s", uevent->attr.name, + uchan->name); break; } case LTTNG_DOMAIN_UST_EXEC_NAME: @@ -2499,6 +2513,10 @@ static int cmd_start_trace(struct ltt_session *session) ksession = session->kernel_session; usess = session->ust_session; + if (session->enabled) + return LTTCOMM_UST_START_FAIL; + session->enabled = 1; + /* Kernel tracing */ if (ksession != NULL) { struct ltt_kernel_channel *kchan; @@ -2584,6 +2602,10 @@ static int cmd_stop_trace(struct ltt_session *session) /* Short cut */ ksession = session->kernel_session; + if (!session->enabled) + return LTTCOMM_UST_START_FAIL; + session->enabled = 0; + /* Kernel tracer */ if (ksession != NULL) { DBG("Stop kernel tracing"); @@ -2999,8 +3021,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx) goto error; } - cmd_ctx->session->ust_session->consumer_fd = - ustconsumer_data.cmd_sock; + ust_consumer_fd = ustconsumer_data.cmd_sock; } pthread_mutex_unlock(&ustconsumer_data.pid_mutex); } @@ -3333,16 +3354,16 @@ static void *thread_manage_clients(void *data) } /* Allocate context command to process the client request */ - cmd_ctx = malloc(sizeof(struct command_ctx)); + cmd_ctx = zmalloc(sizeof(struct command_ctx)); if (cmd_ctx == NULL) { - perror("malloc cmd_ctx"); + perror("zmalloc cmd_ctx"); goto error; } /* Allocate data buffer for reception */ - cmd_ctx->lsm = malloc(sizeof(struct lttcomm_session_msg)); + cmd_ctx->lsm = zmalloc(sizeof(struct lttcomm_session_msg)); if (cmd_ctx->lsm == NULL) { - perror("malloc cmd_ctx->lsm"); + perror("zmalloc cmd_ctx->lsm"); goto error; } @@ -3379,7 +3400,7 @@ static void *thread_manage_clients(void *data) if (ret < 0) { /* * TODO: Inform client somehow of the fatal error. At - * this point, ret < 0 means that a malloc failed + * this point, ret < 0 means that a zmalloc failed * (ENOMEM). Error detected but still accept command. */ clean_command_ctx(&cmd_ctx);