Create a consumer daemon trace chunk registry on launch
[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
fd774fc6 43 * returns a handle to the current working directory.
18710679
JG
44 *
45 * An initialized directory handle must be finalized using
46 * lttng_directory_handle_fini().
47 */
48LTTNG_HIDDEN
49int lttng_directory_handle_init(struct lttng_directory_handle *handle,
50 const char *path);
51
fd774fc6
JG
52/*
53 * Initialize a new directory handle to a path relative to an existing handle.
54 *
55 * The provided path must already exist. Note that the creation of a
56 * subdirectory and the creation of a handle are kept as separate operations
57 * to highlight the fact that there is an inherent race between the creation of
58 * a directory and the creation of a handle to it.
59 *
60 * Passing a NULL path effectively copies the original handle.
61 *
62 * An initialized directory handle must be finalized using
63 * lttng_directory_handle_fini().
64 */
65LTTNG_HIDDEN
66int lttng_directory_handle_init_from_handle(
67 struct lttng_directory_handle *new_handle,
68 const char *path,
69 const struct lttng_directory_handle *handle);
70
15d59b1d
JG
71/*
72 * Initialize a new directory handle from an existing directory fd.
73 *
74 * The new directory handle assumes the ownership of the directory fd.
75 * Note that this method should only be used in very specific cases, such as
76 * re-creating a directory handle from a dirfd passed over a unix socket.
77 *
78 * An initialized directory handle must be finalized using
79 * lttng_directory_handle_fini().
80 */
18710679
JG
81LTTNG_HIDDEN
82int lttng_directory_handle_init_from_dirfd(
83 struct lttng_directory_handle *handle, int dirfd);
84
578e21bd
JG
85/*
86 * Copy a directory handle.
87 */
88LTTNG_HIDDEN
89int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
90 struct lttng_directory_handle *new_copy);
91
46307ffe
JG
92/*
93 * Move a directory handle. The original directory handle may no longer be
94 * used after this call. This call cannot fail; directly assign the
95 * return value to the new directory handle.
96 *
97 * It is safe (but unnecessary) to call lttng_directory_handle_fini on the
98 * original handle.
99 */
100LTTNG_HIDDEN
101struct lttng_directory_handle
102lttng_directory_handle_move(struct lttng_directory_handle *original);
103
18710679
JG
104/*
105 * Release the resources of a directory handle.
106 */
107LTTNG_HIDDEN
108void lttng_directory_handle_fini(struct lttng_directory_handle *handle);
109
110/*
111 * Create a subdirectory relative to a directory handle.
112 */
113LTTNG_HIDDEN
114int lttng_directory_handle_create_subdirectory(
115 const struct lttng_directory_handle *handle,
116 const char *subdirectory,
117 mode_t mode);
118
119/*
120 * Create a subdirectory relative to a directory handle
121 * as a given user.
122 */
123LTTNG_HIDDEN
124int lttng_directory_handle_create_subdirectory_as_user(
125 const struct lttng_directory_handle *handle,
126 const char *subdirectory,
69e3a560 127 mode_t mode, const struct lttng_credentials *creds);
18710679
JG
128
129/*
130 * Recursively create a directory relative to a directory handle.
131 */
132LTTNG_HIDDEN
133int lttng_directory_handle_create_subdirectory_recursive(
134 const struct lttng_directory_handle *handle,
135 const char *subdirectory_path,
136 mode_t mode);
137
138/*
139 * Recursively create a directory relative to a directory handle
140 * as a given user.
141 */
142LTTNG_HIDDEN
143int lttng_directory_handle_create_subdirectory_recursive_as_user(
144 const struct lttng_directory_handle *handle,
145 const char *subdirectory_path,
69e3a560 146 mode_t mode, const struct lttng_credentials *creds);
18710679
JG
147
148#endif /* _COMPAT_PATH_HANDLE_H */
This page took 0.0340200000000001 seconds and 4 git commands to generate.