libcamera: base: {unique,shared}_fd: Warn if closing fails

If the contained file descriptor cannot be successfully closed,
that is usually a sign of a more serious invariant violation,
which deserves attention, so report those cases.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze
2025-07-25 09:43:05 +02:00
parent c0bf335a6c
commit 48560d72cd
2 changed files with 11 additions and 4 deletions
+5 -2
View File
@@ -284,8 +284,11 @@ SharedFD::Descriptor::Descriptor(int fd, bool duplicate)
SharedFD::Descriptor::~Descriptor()
{
if (fd_ != -1)
close(fd_);
if (fd_ >= 0 && close(fd_) < 0) {
int ret = -errno;
LOG(SharedFD, Error) << "Failed to close file descriptor "
<< fd_ << ": " << strerror(-ret);
}
}
} /* namespace libcamera */
+6 -2
View File
@@ -7,6 +7,7 @@
#include <libcamera/base/unique_fd.h>
#include <string.h>
#include <unistd.h>
#include <utility>
@@ -98,8 +99,11 @@ void UniqueFD::reset(int fd)
std::swap(fd, fd_);
if (fd >= 0)
close(fd);
if (fd >= 0 && close(fd) < 0) {
int ret = -errno;
LOG(UniqueFD, Error) << "Failed to close file descriptor "
<< fd << ": " << strerror(-ret);
}
}
/**