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:
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user