From: Jérémie Galarneau Date: Wed, 29 Jan 2020 04:39:01 +0000 (-0500) Subject: directory-handle: query if instance is backed by a file descriptor X-Git-Tag: v2.12.0-rc1~38 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9a1a997f2f22b556f63437d911b98c7b522b38e4;p=lttng-tools.git directory-handle: query if instance is backed by a file descriptor Allow a user of a directory handle to know if a given instance is backed by a file descriptor. This is needed to ensure the fd-tracker can accurately track the number of file descriptors in use at a given moment. Signed-off-by: Jérémie Galarneau Change-Id: I64aeeae2623a35ed07964432bb18b16aeeeb89ec --- diff --git a/src/common/compat/directory-handle.c b/src/common/compat/directory-handle.c index 9548da216..729f69cb9 100644 --- a/src/common/compat/directory-handle.c +++ b/src/common/compat/directory-handle.c @@ -248,6 +248,13 @@ int lttng_directory_handle_stat(const struct lttng_directory_handle *handle, return fstatat(handle->dirfd, path, st, 0); } +LTTNG_HIDDEN +bool lttng_directory_handle_uses_fd( + const struct lttng_directory_handle *handle) +{ + return handle->dirfd != AT_FDCWD; +} + static int lttng_directory_handle_mkdir( const struct lttng_directory_handle *handle, @@ -617,6 +624,13 @@ end: return ret; } +LTTNG_HIDDEN +bool lttng_directory_handle_uses_fd( + const struct lttng_directory_handle *handle) +{ + return false; +} + static int lttng_directory_handle_mkdir(const struct lttng_directory_handle *handle, const char *subdirectory, mode_t mode) diff --git a/src/common/compat/directory-handle.h b/src/common/compat/directory-handle.h index 551fa50b4..b6ee8b384 100644 --- a/src/common/compat/directory-handle.h +++ b/src/common/compat/directory-handle.h @@ -267,6 +267,14 @@ int lttng_directory_handle_stat( const char *name, struct stat *stat_buf); +/* + * Returns true if this directory handle is backed by a file + * descriptor, false otherwise. + */ +LTTNG_HIDDEN +bool lttng_directory_handle_uses_fd( + const struct lttng_directory_handle *handle); + /* * Compare two directory handles. *