From: Mathieu Desnoyers Date: Fri, 2 Mar 2012 16:54:13 +0000 (-0500) Subject: Fix: incorrect close of fd 0 for syscall kernel event destroy X-Git-Tag: v2.0.0-rc2~14 X-Git-Url: http://git.lttng.org/?a=commitdiff_plain;h=87eb4ab891dda35c54ffa95f356a4c4b198d8716;p=lttng-tools.git Fix: incorrect close of fd 0 for syscall kernel event destroy Signed-off-by: Mathieu Desnoyers --- diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 371ee4f98..2936406d8 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -208,6 +208,11 @@ int kernel_create_event(struct lttng_event *ev, */ if (ret == 0 && event->event->instrumentation == LTTNG_KERNEL_SYSCALL) { DBG2("Kernel event syscall creation success"); + /* + * We use fd == -1 to ensure that we never trigger a close of fd + * 0. + */ + event->fd = -1; goto add_list; } diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 36f7c9708..68753286f 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -321,9 +321,13 @@ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) */ void trace_kernel_destroy_event(struct ltt_kernel_event *event) { - DBG("[trace] Closing event fd %d", event->fd); - /* Close kernel fd */ - close(event->fd); + if (event->fd >= 0) { + DBG("[trace] Closing event fd %d", event->fd); + /* Close kernel fd */ + close(event->fd); + } else { + DBG("[trace] Tearing down event (no associated fd)"); + } /* Remove from event list */ cds_list_del(&event->list);