X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fevent.c;h=a8e63896d001a5e36a64a6639c410603d4006dfd;hp=52fd9f5478a753492eb9ffee7b0c6d8eaf18d5e4;hb=90e7d72ff2b93752b8c81c49e9251a83b01703c6;hpb=fefd409b002735b415c5f653cdb2587be454f145 diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 52fd9f547..a8e63896d 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -16,6 +16,7 @@ */ #define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -57,21 +58,6 @@ static void add_unique_ust_event(struct lttng_ht *ht, assert(node_ptr == &event->node.node); } -/* - * Setup a lttng_event used to enable *all* syscall tracing. - */ -static void init_syscalls_kernel_event(struct lttng_event *event) -{ - assert(event); - - event->name[0] = '\0'; - /* - * We use LTTNG_EVENT* here since the trace kernel creation will make the - * right changes for the kernel. - */ - event->type = LTTNG_EVENT_SYSCALL; -} - /* * Disable kernel tracepoint event for a channel from the kernel session. */ @@ -104,6 +90,57 @@ error: return ret; } +/* + * Enable kernel system call for a channel from the kernel session. + */ +int event_kernel_enable_syscall(struct ltt_kernel_channel *kchan, + char *syscall_name) +{ + int ret; + + assert(kchan); + + ret = kernel_enable_syscall(syscall_name, kchan); + if (ret < 0) { + ret = LTTNG_ERR_KERN_ENABLE_FAIL; + goto error; + } + + DBG("Kernel event %s enable for channel %s.", + syscall_name, kchan->channel->name); + + ret = LTTNG_OK; + +error: + return ret; +} + +/* + * Disable kernel system call for a channel from the kernel session. + */ +int event_kernel_disable_syscall(struct ltt_kernel_channel *kchan, + char *syscall_name) +{ + int ret; + + assert(kchan); + + ret = kernel_disable_syscall(syscall_name, kchan); + if (ret < 0) { + ret = LTTNG_ERR_KERN_DISABLE_FAIL; + goto error; + } + + DBG("Kernel syscall %s disable for channel %s.", + syscall_name[0] == '\0' ? "" : syscall_name, + kchan->channel->name); + + ret = LTTNG_OK; + +error: + return ret; +} + /* * Disable kernel tracepoint events for a channel from the kernel session. */ @@ -126,15 +163,6 @@ int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan) return ret; } -/* - * Disable kernel syscall events for a channel from the kernel session. - */ -int event_kernel_disable_all_syscalls(struct ltt_kernel_channel *kchan) -{ - ERR("Cannot disable syscall tracing for existing session. Please destroy session instead."); - return LTTNG_OK; /* Return OK so disable all succeeds */ -} - /* * Disable all kernel event for a channel from the kernel session. */ @@ -147,12 +175,13 @@ int event_kernel_disable_all(struct ltt_kernel_channel *kchan) ret = event_kernel_disable_all_tracepoints(kchan); if (ret != LTTNG_OK) return ret; - ret = event_kernel_disable_all_syscalls(kchan); + ret = event_kernel_disable_syscall(kchan, ""); return ret; } /* * Enable kernel tracepoint event for a channel from the kernel session. + * We own filter_expression and filter. */ int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan, struct lttng_event *event) @@ -245,36 +274,6 @@ end: return ret; } -/* - * Enable all kernel sycalls events of a channel of the kernel session. - */ -int event_kernel_enable_all_syscalls(struct ltt_kernel_channel *kchan, - int kernel_tracer_fd) -{ - int ret; - struct lttng_event event; - - assert(kchan); - - init_syscalls_kernel_event(&event); - - DBG("Enabling all syscall tracing"); - - ret = kernel_create_event(&event, kchan); - if (ret < 0) { - if (ret == -EEXIST) { - ret = LTTNG_ERR_KERN_EVENT_EXIST; - } else { - ret = LTTNG_ERR_KERN_ENABLE_FAIL; - } - goto end; - } - - ret = LTTNG_OK; -end: - return ret; -} - /* * Enable all kernel events of a channel of the kernel session. */ @@ -299,7 +298,7 @@ int event_kernel_enable_all(struct ltt_kernel_channel *kchan, * tracepoints did not fail. Future work will allow us to send back * multiple errors to the client in one API call. */ - (void) event_kernel_enable_all_syscalls(kchan, kernel_tracer_fd); + (void) event_kernel_enable_syscall(kchan, ""); end: return tp_ret; @@ -410,6 +409,7 @@ error: /* * Enable UST tracepoint event for a channel from a UST session. + * We own filter_expression, filter, and exclusion. */ int event_ust_enable_tracepoint(struct ltt_ust_session *usess, struct ltt_ust_channel *uchan, struct lttng_event *event, @@ -431,6 +431,10 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess, if (uevent == NULL) { uevent = trace_ust_create_event(event, filter_expression, filter, exclusion); + /* We have passed ownership */ + filter_expression = NULL; + filter = NULL; + exclusion = NULL; if (uevent == NULL) { ret = LTTNG_ERR_UST_ENABLE_FAIL; goto error; @@ -478,6 +482,9 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess, end: rcu_read_unlock(); + free(filter_expression); + free(filter); + free(exclusion); return ret; error: @@ -493,6 +500,9 @@ error: trace_ust_destroy_event(uevent); } rcu_read_unlock(); + free(filter_expression); + free(filter); + free(exclusion); return ret; } @@ -710,6 +720,39 @@ error: return ret; } +/* + * Return the agent default event name to use by testing if the process is root + * or not. Return NULL on error. + */ +const char *event_get_default_agent_ust_name(enum lttng_domain_type domain) +{ + const char *default_event_name = NULL; + + switch (domain) { + case LTTNG_DOMAIN_LOG4J: + if (is_root) { + default_event_name = DEFAULT_SYS_LOG4J_EVENT_NAME; + } else { + default_event_name = DEFAULT_USER_LOG4J_EVENT_NAME; + } + break; + case LTTNG_DOMAIN_JUL: + if (is_root) { + default_event_name = DEFAULT_SYS_JUL_EVENT_NAME; + } else { + default_event_name = DEFAULT_USER_JUL_EVENT_NAME; + } + break; + case LTTNG_DOMAIN_PYTHON: + default_event_name = DEFAULT_USER_PYTHON_EVENT_NAME; + break; + default: + assert(0); + } + + return default_event_name; +} + /* * Disable a single agent event for a given UST session. * @@ -722,7 +765,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, struct agent_event *aevent; struct ltt_ust_event *uevent = NULL; struct ltt_ust_channel *uchan = NULL; - char *ust_event_name; + const char *ust_event_name, *ust_channel_name; assert(agt); assert(usess); @@ -741,21 +784,32 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, goto end; } + if (agt->domain == LTTNG_DOMAIN_JUL) { + ust_channel_name = DEFAULT_JUL_CHANNEL_NAME; + } else if (agt->domain == LTTNG_DOMAIN_LOG4J) { + ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME; + } else if (agt->domain == LTTNG_DOMAIN_PYTHON) { + ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME; + } else { + ret = LTTNG_ERR_INVALID; + goto error; + } + /* * Disable it on the UST side. First get the channel reference then find * the event and finally disable it. */ uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, - DEFAULT_JUL_CHANNEL_NAME); + (char *) ust_channel_name); if (!uchan) { ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; goto error; } - if (is_root) { - ust_event_name = DEFAULT_SYS_JUL_EVENT_NAME; - } else { - ust_event_name = DEFAULT_USER_JUL_EVENT_NAME; + ust_event_name = event_get_default_agent_ust_name(agt->domain); + if (!ust_event_name) { + ret = LTTNG_ERR_FATAL; + goto error; } /* @@ -763,7 +817,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, * with the loglevel type to ALL thus the loglevel stays 0. The event's * filter is the one handling the loglevel for agent. */ - uevent = trace_ust_find_event(uchan->events, ust_event_name, + uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name, aevent->filter, 0, NULL); /* If the agent event exists, it must be available on the UST side. */ assert(uevent); @@ -774,6 +828,12 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, goto error; } + /* + * Flag event that it's disabled so the shadow copy on the ust app side + * will disable it if an application shows up. + */ + uevent->enabled = 0; + ret = agent_disable_event(aevent, agt->domain); if (ret != LTTNG_OK) { goto error; @@ -793,40 +853,35 @@ error: int event_agent_disable_all(struct ltt_ust_session *usess, struct agent *agt) { - int ret, do_disable = 0; + int ret; struct agent_event *aevent; struct lttng_ht_iter iter; assert(agt); assert(usess); - /* Disable event on agent application through TCP socket. */ + /* + * Disable event on agent application. Continue to disable all other events + * if the * event is not found. + */ ret = event_agent_disable(usess, agt, "*"); - if (ret != LTTNG_OK) { - if (ret == LTTNG_ERR_UST_EVENT_NOT_FOUND) { - /* - * This means that no enable all was done before but still a user - * could want to disable everything even though the * wild card - * event does not exists. - */ - do_disable = 1; - } else { - goto error; - } + if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) { + goto error; } /* Flag every event that they are now enabled. */ rcu_read_lock(); cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent, node.node) { - if (aevent->enabled && do_disable) { - ret = event_agent_disable(usess, agt, aevent->name); - if (ret != LTTNG_OK) { - rcu_read_unlock(); - goto error; - } + if (!aevent->enabled) { + continue; + } + + ret = event_agent_disable(usess, agt, aevent->name); + if (ret != LTTNG_OK) { + rcu_read_unlock(); + goto error; } - aevent->enabled = 0; } rcu_read_unlock();