From 14a4b602a643099faf6459bb143dd8478c1739a8 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 24 Dec 2014 12:32:30 -0500 Subject: [PATCH] Fix: introduce lttng_get_unused_fd() wrapper for 3.19 kernels get_unused_fd disappears in 3.19 kernel, where get_unused_fd_flags(0) should be used instead. Signed-off-by: Mathieu Desnoyers --- lttng-abi.c | 11 ++++++----- lttng-syscalls.c | 3 ++- wrapper/file.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 wrapper/file.h diff --git a/lttng-abi.c b/lttng-abi.c index 381a7390..5823a1db 100644 --- a/lttng-abi.c +++ b/lttng-abi.c @@ -49,6 +49,7 @@ #include "wrapper/ringbuffer/backend.h" #include "wrapper/ringbuffer/frontend.h" #include "wrapper/poll.h" +#include "wrapper/file.h" #include "lttng-abi.h" #include "lttng-abi-old.h" #include "lttng-events.h" @@ -83,7 +84,7 @@ int lttng_abi_create_session(void) session = lttng_session_create(); if (!session) return -ENOMEM; - session_fd = get_unused_fd(); + session_fd = lttng_get_unused_fd(); if (session_fd < 0) { ret = session_fd; goto fd_error; @@ -112,7 +113,7 @@ int lttng_abi_tracepoint_list(void) struct file *tracepoint_list_file; int file_fd, ret; - file_fd = get_unused_fd(); + file_fd = lttng_get_unused_fd(); if (file_fd < 0) { ret = file_fd; goto fd_error; @@ -332,7 +333,7 @@ int lttng_abi_create_channel(struct file *session_file, int chan_fd; int ret = 0; - chan_fd = get_unused_fd(); + chan_fd = lttng_get_unused_fd(); if (chan_fd < 0) { ret = chan_fd; goto fd_error; @@ -783,7 +784,7 @@ int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv, int stream_fd, ret; struct file *stream_file; - stream_fd = get_unused_fd(); + stream_fd = lttng_get_unused_fd(); if (stream_fd < 0) { ret = stream_fd; goto fd_error; @@ -920,7 +921,7 @@ int lttng_abi_create_event(struct file *channel_file, } switch (event_param->instrumentation) { default: - event_fd = get_unused_fd(); + event_fd = lttng_get_unused_fd(); if (event_fd < 0) { ret = event_fd; goto fd_error; diff --git a/lttng-syscalls.c b/lttng-syscalls.c index 1fc86c8e..748c6002 100644 --- a/lttng-syscalls.c +++ b/lttng-syscalls.c @@ -36,6 +36,7 @@ #include "lib/bitfield.h" #include "wrapper/tracepoint.h" +#include "wrapper/file.h" #include "lttng-events.h" #ifndef CONFIG_COMPAT @@ -1269,7 +1270,7 @@ int lttng_abi_syscall_list(void) struct file *syscall_list_file; int file_fd, ret; - file_fd = get_unused_fd(); + file_fd = lttng_get_unused_fd(); if (file_fd < 0) { ret = file_fd; goto fd_error; diff --git a/wrapper/file.h b/wrapper/file.h new file mode 100644 index 00000000..2440745c --- /dev/null +++ b/wrapper/file.h @@ -0,0 +1,47 @@ +#ifndef _LTTNG_WRAPPER_FILE_H +#define _LTTNG_WRAPPER_FILE_H + +/* + * wrapper/file.h + * + * wrapper around linux/file.h. + * + * Copyright (C) 2014 Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; only + * version 2.1 of the License. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) + +static +inline int lttng_get_unused_fd(void) +{ + return get_unused_fd_flags(0); +} + +#else /* #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) */ + +static +inline int lttng_get_unused_fd(void) +{ + return get_unused_fd(); +} + +#endif /* #else #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) */ + +#endif /* _LTTNG_WRAPPER_FILE_H */ -- 2.34.1