Add a copy method to lttng_directory_handle
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 24 Apr 2019 19:33:45 +0000 (15:33 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 18 Jul 2019 19:58:24 +0000 (15:58 -0400)
This method allows the duplication of a directory handle to
existing storage. It duplicates the underlying directory file
descriptor or path, depending on the configured implementation.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/compat/directory-handle.c
src/common/compat/directory-handle.h

index 781f2574b0ea652cadd2d8b8bb0e9e487d891d91..562a7928719031856164f5a7fb2333fe30bcfc75 100644 (file)
@@ -88,6 +88,24 @@ void lttng_directory_handle_fini(struct lttng_directory_handle *handle)
        }
 }
 
+LTTNG_HIDDEN
+int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
+               struct lttng_directory_handle *new_copy)
+{
+       int ret = 0;
+
+       if (handle->dirfd == AT_FDCWD) {
+               new_copy->dirfd = handle->dirfd;
+       } else {
+               new_copy->dirfd = dup(handle->dirfd);
+               if (new_copy->dirfd == -1) {
+                       PERROR("Failed to duplicate directory fd of directory handle");
+                       ret = -1;
+               }
+       }
+       return ret;
+}
+
 static
 int lttng_directory_handle_stat(const struct lttng_directory_handle *handle,
                const char *path, struct stat *st)
@@ -225,6 +243,14 @@ void lttng_directory_handle_fini(struct lttng_directory_handle *handle)
        free(handle->base_path);
 }
 
+LTTNG_HIDDEN
+int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
+               struct lttng_directory_handle *new_copy)
+{
+       new_copy->base_path = strdup(handle->base_path);
+       return new_copy->base_path ? 0 : -1;
+}
+
 static
 int get_full_path(const struct lttng_directory_handle *handle,
                const char *subdirectory, char *fullpath, size_t size)
index 7d2cab339fc28ad15752d6a2652679e3a7df359e..ceebc941e724ea690003698eb7c469789f3f2dba 100644 (file)
@@ -55,6 +55,13 @@ LTTNG_HIDDEN
 int lttng_directory_handle_init_from_dirfd(
                struct lttng_directory_handle *handle, int dirfd);
 
+/*
+ * Copy a directory handle.
+ */
+LTTNG_HIDDEN
+int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
+               struct lttng_directory_handle *new_copy);
+
 /*
  * Release the resources of a directory handle.
  */
This page took 0.027702 seconds and 4 git commands to generate.