Maintain a channel-per-session_id hash table in the consumers
[lttng-tools.git] / src / common / compat / directory-handle.h
CommitLineData
18710679
JG
1/*
2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#ifndef _COMPAT_DIRECTORY_HANDLE_H
19#define _COMPAT_DIRECTORY_HANDLE_H
20
21#include <common/macros.h>
22#include <common/credentials.h>
23
24/*
25 * Some platforms, such as Solaris 10, do not support directory file descriptors
26 * and their associated functions (*at(...)), which are defined in POSIX.2008.
27 *
28 * This wrapper provides a handle that is either a copy of a directory's path
29 * or a directory file descriptors, depending on the platform's capabilities.
30 */
31#ifdef COMPAT_DIRFD
32struct lttng_directory_handle {
33 int dirfd;
34};
35#else
36struct lttng_directory_handle {
37 char *base_path;
38};
39#endif
40
41/*
42 * Initialize a directory handle to the provided path. Passing a NULL path
43 * returns a handle to the current working directory. The working directory
44 * is not sampled; it will be accessed at the time of use of the functions
45 * of this API.
46 *
47 * An initialized directory handle must be finalized using
48 * lttng_directory_handle_fini().
49 */
50LTTNG_HIDDEN
51int lttng_directory_handle_init(struct lttng_directory_handle *handle,
52 const char *path);
53
15d59b1d
JG
54/*
55 * Initialize a new directory handle from an existing directory fd.
56 *
57 * The new directory handle assumes the ownership of the directory fd.
58 * Note that this method should only be used in very specific cases, such as
59 * re-creating a directory handle from a dirfd passed over a unix socket.
60 *
61 * An initialized directory handle must be finalized using
62 * lttng_directory_handle_fini().
63 */
18710679
JG
64LTTNG_HIDDEN
65int lttng_directory_handle_init_from_dirfd(
66 struct lttng_directory_handle *handle, int dirfd);
67
578e21bd
JG
68/*
69 * Copy a directory handle.
70 */
71LTTNG_HIDDEN
72int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
73 struct lttng_directory_handle *new_copy);
74
46307ffe
JG
75/*
76 * Move a directory handle. The original directory handle may no longer be
77 * used after this call. This call cannot fail; directly assign the
78 * return value to the new directory handle.
79 *
80 * It is safe (but unnecessary) to call lttng_directory_handle_fini on the
81 * original handle.
82 */
83LTTNG_HIDDEN
84struct lttng_directory_handle
85lttng_directory_handle_move(struct lttng_directory_handle *original);
86
18710679
JG
87/*
88 * Release the resources of a directory handle.
89 */
90LTTNG_HIDDEN
91void lttng_directory_handle_fini(struct lttng_directory_handle *handle);
92
93/*
94 * Create a subdirectory relative to a directory handle.
95 */
96LTTNG_HIDDEN
97int lttng_directory_handle_create_subdirectory(
98 const struct lttng_directory_handle *handle,
99 const char *subdirectory,
100 mode_t mode);
101
102/*
103 * Create a subdirectory relative to a directory handle
104 * as a given user.
105 */
106LTTNG_HIDDEN
107int lttng_directory_handle_create_subdirectory_as_user(
108 const struct lttng_directory_handle *handle,
109 const char *subdirectory,
69e3a560 110 mode_t mode, const struct lttng_credentials *creds);
18710679
JG
111
112/*
113 * Recursively create a directory relative to a directory handle.
114 */
115LTTNG_HIDDEN
116int lttng_directory_handle_create_subdirectory_recursive(
117 const struct lttng_directory_handle *handle,
118 const char *subdirectory_path,
119 mode_t mode);
120
121/*
122 * Recursively create a directory relative to a directory handle
123 * as a given user.
124 */
125LTTNG_HIDDEN
126int lttng_directory_handle_create_subdirectory_recursive_as_user(
127 const struct lttng_directory_handle *handle,
128 const char *subdirectory_path,
69e3a560 129 mode_t mode, const struct lttng_credentials *creds);
18710679
JG
130
131#endif /* _COMPAT_PATH_HANDLE_H */
This page took 0.027344 seconds and 4 git commands to generate.