2 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include "fd-handle.hpp"
10 #include <common/error.hpp>
20 static void fd_handle_release(struct urcu_ref
*ref
)
23 struct fd_handle
*handle
= lttng::utils::container_of(ref
, &fd_handle::ref
);
25 LTTNG_ASSERT(handle
->fd
>= 0);
26 ret
= close(handle
->fd
);
28 PERROR("Failed to close file descriptor of fd_handle upon release: fd = %d",
35 struct fd_handle
*fd_handle_create(int fd
)
37 struct fd_handle
*handle
= nullptr;
40 ERR("Attempted to create an fd_handle from an invalid file descriptor: fd = %d",
45 handle
= zmalloc
<fd_handle
>();
47 PERROR("Failed to allocate fd_handle");
51 urcu_ref_init(&handle
->ref
);
58 void fd_handle_get(struct fd_handle
*handle
)
64 urcu_ref_get(&handle
->ref
);
67 void fd_handle_put(struct fd_handle
*handle
)
73 urcu_ref_put(&handle
->ref
, fd_handle_release
);
76 int fd_handle_get_fd(struct fd_handle
*handle
)
82 struct fd_handle
*fd_handle_copy(const struct fd_handle
*handle
)
84 struct fd_handle
*new_handle
= nullptr;
85 const int new_fd
= dup(handle
->fd
);
88 PERROR("Failed to duplicate file descriptor while copying fd_handle: fd = %d",
93 new_handle
= fd_handle_create(new_fd
);
This page took 0.032209 seconds and 4 git commands to generate.