2 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
11 #include "fd-handle.hpp"
12 #include <common/error.hpp>
19 static void fd_handle_release(struct urcu_ref
*ref
)
22 struct fd_handle
*handle
= lttng::utils::container_of(ref
, &fd_handle::ref
);
24 LTTNG_ASSERT(handle
->fd
>= 0);
25 ret
= close(handle
->fd
);
27 PERROR("Failed to close file descriptor of fd_handle upon release: fd = %d",
34 struct fd_handle
*fd_handle_create(int fd
)
36 struct fd_handle
*handle
= NULL
;
39 ERR("Attempted to create an fd_handle from an invalid file descriptor: fd = %d",
44 handle
= zmalloc
<fd_handle
>();
46 PERROR("Failed to allocate fd_handle");
50 urcu_ref_init(&handle
->ref
);
57 void fd_handle_get(struct fd_handle
*handle
)
63 urcu_ref_get(&handle
->ref
);
66 void fd_handle_put(struct fd_handle
*handle
)
72 urcu_ref_put(&handle
->ref
, fd_handle_release
);
75 int fd_handle_get_fd(struct fd_handle
*handle
)
81 struct fd_handle
*fd_handle_copy(const struct fd_handle
*handle
)
83 struct fd_handle
*new_handle
= NULL
;
84 const int new_fd
= dup(handle
->fd
);
87 PERROR("Failed to duplicate file descriptor while copying fd_handle: fd = %d", handle
->fd
);
91 new_handle
= fd_handle_create(new_fd
);
This page took 0.032013 seconds and 4 git commands to generate.