X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fevent.c;h=24dd292a4e3fdd5f86e48cf0ae11762938766694;hp=4a86c22cdd6aa694896c1314e026c837dd5a117d;hb=51f1a3b9df60b6951e8748961893cb4129cf4832;hpb=db7586006bc1a2b9057a2c108bf1e7d20fd6903f diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 4a86c22cd..24dd292a4 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -1,18 +1,18 @@ /* * Copyright (C) 2011 - David Goulet * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; only version 2 of the License. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2 only, + * as published by the Free Software Foundation. * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _GNU_SOURCE @@ -45,6 +45,32 @@ static void init_syscalls_kernel_event(struct lttng_event *event) event->type = LTTNG_EVENT_SYSCALL; } +/* + * Return 1 if loglevels match or 0 on failure. + */ +static int loglevel_match(struct ltt_ust_event *uevent, + enum lttng_ust_loglevel_type log_type, int loglevel) +{ + /* + * For the loglevel type ALL, the loglevel is set to -1 but the event + * received by the session daemon is 0 which does not match the negative + * value in the existing event. + */ + if (log_type == LTTNG_UST_LOGLEVEL_ALL) { + loglevel = -1; + } + + if (uevent == NULL || uevent->attr.loglevel_type != log_type || + uevent->attr.loglevel != loglevel) { + goto no_match; + } + + return 1; + +no_match: + return 0; +} + /* * Disable kernel tracepoint event for a channel from the kernel session. */ @@ -134,10 +160,16 @@ int event_kernel_enable_tracepoint(struct ltt_kernel_session *ksession, if (kevent == NULL) { ret = kernel_create_event(event, kchan); if (ret < 0) { - if (ret == -EEXIST) { + switch (-ret) { + case EEXIST: ret = LTTCOMM_KERN_EVENT_EXIST; - } else { + break; + case ENOSYS: + ret = LTTCOMM_KERN_EVENT_ENOSYS; + break; + default: ret = LTTCOMM_KERN_ENABLE_FAIL; + break; } goto end; } @@ -147,7 +179,12 @@ int event_kernel_enable_tracepoint(struct ltt_kernel_session *ksession, ret = LTTCOMM_KERN_ENABLE_FAIL; goto end; } + } else { + /* At this point, the event is considered enabled */ + ret = LTTCOMM_KERN_EVENT_EXIST; + goto end; } + ret = LTTCOMM_OK; end: return ret; @@ -234,15 +271,26 @@ end: int event_kernel_enable_all(struct ltt_kernel_session *ksession, struct ltt_kernel_channel *kchan, int kernel_tracer_fd) { - int ret; + int tp_ret; - ret = event_kernel_enable_all_tracepoints(ksession, kchan, kernel_tracer_fd); - if (ret != LTTCOMM_OK) { + tp_ret = event_kernel_enable_all_tracepoints(ksession, kchan, kernel_tracer_fd); + if (tp_ret != LTTCOMM_OK) { goto end; } - ret = event_kernel_enable_all_syscalls(ksession, kchan, kernel_tracer_fd); + + /* + * Reaching this code path means that all tracepoints were enabled without + * errors so we ignore the error value of syscalls. + * + * At the moment, failing to enable syscalls on "lttng enable-event -a -k" + * is not considered an error that need to be returned to the client since + * 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(ksession, kchan, kernel_tracer_fd); + end: - return ret; + return tp_ret; } /* @@ -257,8 +305,7 @@ end: int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess, int domain, struct ltt_ust_channel *uchan) { - int ret, i; - size_t size; + int ret, i, size; struct lttng_ht_iter iter; struct ltt_ust_event *uevent = NULL; struct lttng_event *events = NULL; @@ -334,11 +381,13 @@ int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess, int domain, free(events); break; } +#if 0 case LTTNG_DOMAIN_UST_EXEC_NAME: case LTTNG_DOMAIN_UST_PID: case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: +#endif default: - ret = LTTCOMM_NOT_IMPLEMENTED; + ret = LTTCOMM_UND; goto error; } @@ -372,8 +421,23 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess, int domain, to_create = 1; } + /* Check loglevels */ + ret = loglevel_match(uevent, event->loglevel_type, event->loglevel); + if (ret == 0) { + /* + * No match meaning that the user tried to enable a known event but + * with a different loglevel. + */ + DBG("Enable event %s does not match existing event %s with loglevel " + "respectively of %d and %d", event->name, uevent->attr.name, + uevent->attr.loglevel, event->loglevel); + ret = LTTCOMM_EVENT_EXIST_LOGLEVEL; + goto error; + } + if (uevent->enabled) { /* It's already enabled so everything is OK */ + ret = LTTCOMM_OK; goto end; } @@ -401,11 +465,13 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess, int domain, } break; } +#if 0 case LTTNG_DOMAIN_UST_EXEC_NAME: case LTTNG_DOMAIN_UST_PID: case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: +#endif default: - ret = LTTCOMM_NOT_IMPLEMENTED; + ret = LTTCOMM_UND; goto end; } @@ -468,11 +534,13 @@ int event_ust_disable_tracepoint(struct ltt_ust_session *usess, int domain, goto error; } break; +#if 0 case LTTNG_DOMAIN_UST_EXEC_NAME: case LTTNG_DOMAIN_UST_PID: case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: +#endif default: - ret = LTTCOMM_NOT_IMPLEMENTED; + ret = LTTCOMM_UND; goto error; } @@ -493,8 +561,7 @@ error: int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, int domain, struct ltt_ust_channel *uchan) { - int ret, i; - size_t size; + int ret, i, size; struct lttng_ht_iter iter; struct ltt_ust_event *uevent = NULL; struct lttng_event *events = NULL; @@ -539,11 +606,13 @@ int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, int domain, free(events); break; } +#if 0 case LTTNG_DOMAIN_UST_EXEC_NAME: case LTTNG_DOMAIN_UST_PID: case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: +#endif default: - ret = LTTCOMM_NOT_IMPLEMENTED; + ret = LTTCOMM_UND; goto error; }