summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/base/file_descriptor.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/libcamera/base/file_descriptor.cpp b/src/libcamera/base/file_descriptor.cpp
index da696b25..8e181abc 100644
--- a/src/libcamera/base/file_descriptor.cpp
+++ b/src/libcamera/base/file_descriptor.cpp
@@ -222,17 +222,23 @@ FileDescriptor &FileDescriptor::operator=(FileDescriptor &&other)
* \brief Duplicate a FileDescriptor
*
* Duplicating a FileDescriptor creates a duplicate of the wrapped file
- * descriptor and returns a new FileDescriptor instance that wraps the
- * duplicate. The fd() function of the original and duplicate instances will
- * return different values. The duplicate instance will not be affected by
- * destruction of the original instance or its copies.
+ * descriptor and returns a UniqueFD that owns the duplicate. The fd() function
+ * of the original and the get() function of the duplicate will return different
+ * values. The duplicate instance will not be affected by destruction of the
+ * original instance or its copies.
*
- * \return A new FileDescriptor instance wrapping a duplicate of the original
- * file descriptor
+ * \return A UniqueFD owning a duplicate of the original file descriptor
*/
-FileDescriptor FileDescriptor::dup() const
+UniqueFD FileDescriptor::dup() const
{
- return FileDescriptor(fd());
+ UniqueFD dupFd(::dup(fd()));
+ if (!dupFd.isValid()) {
+ int ret = -errno;
+ LOG(FileDescriptor, Error)
+ << "Failed to dup() fd: " << strerror(-ret);
+ }
+
+ return dupFd;
}
FileDescriptor::Descriptor::Descriptor(int fd, bool duplicate)