libcamera: ipc_unixsocket: Use UniqueFD for a file descriptor

IPCUnixSocket::create() creates two file descriptors. One of
them is stored in IPCUnixSocket and the other is returned to a
caller. This clarifies the ownership using UniqueFD.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Hirokazu Honda
2021-12-04 23:05:03 +02:00
committed by Laurent Pinchart
parent edd70612e5
commit 9143668887
6 changed files with 49 additions and 44 deletions
+7 -7
View File
@@ -52,9 +52,9 @@ public:
ipc_.readyRead.connect(this, &UnixSocketTestSlave::readyRead);
}
int run(int fd)
int run(UniqueFD fd)
{
if (ipc_.bind(fd)) {
if (ipc_.bind(std::move(fd))) {
cerr << "Failed to connect to IPC channel" << endl;
return EXIT_FAILURE;
}
@@ -359,11 +359,11 @@ protected:
int run()
{
int slavefd = ipc_.create();
if (slavefd < 0)
UniqueFD slavefd = ipc_.create();
if (!slavefd.isValid())
return TestFail;
if (slaveStart(slavefd)) {
if (slaveStart(slavefd.release())) {
cerr << "Failed to start slave" << endl;
return TestFail;
}
@@ -495,9 +495,9 @@ private:
int main(int argc, char **argv)
{
if (argc == 2) {
int ipcfd = std::stoi(argv[1]);
UniqueFD ipcfd = UniqueFD(std::stoi(argv[1]));
UnixSocketTestSlave slave;
return slave.run(ipcfd);
return slave.run(std::move(ipcfd));
}
UnixSocketTest test;