From 91436688874a2450c7da22527c59e34c2053b9ef Mon Sep 17 00:00:00 2001 From: Hirokazu Honda Date: Thu, 10 Jun 2021 16:50:25 +0900 Subject: 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 Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- .../libcamera_templates/module_ipa_proxy_worker.cpp.tmpl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl index 764e7a3a..b65dc4cf 100644 --- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl +++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl @@ -27,8 +27,9 @@ #include #include -#include #include +#include +#include #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/control_serializer.h" @@ -122,9 +123,9 @@ public: } } - int init(std::unique_ptr &ipam, int socketfd) + int init(std::unique_ptr &ipam, UniqueFD socketfd) { - if (socket_.bind(socketfd) < 0) { + if (socket_.bind(std::move(socketfd)) < 0) { LOG({{proxy_worker_name}}, Error) << "IPC socket binding failed"; return EXIT_FAILURE; @@ -203,10 +204,10 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - int fd = std::stoi(argv[2]); + UniqueFD fd(std::stoi(argv[2])); LOG({{proxy_worker_name}}, Info) << "Starting worker for IPA module " << argv[1] - << " with IPC fd = " << fd; + << " with IPC fd = " << fd.get(); std::unique_ptr ipam = std::make_unique(argv[1]); if (!ipam->isValid() || !ipam->load()) { @@ -228,7 +229,7 @@ int main(int argc, char **argv) } {{proxy_worker_name}} proxyWorker; - int ret = proxyWorker.init(ipam, fd); + int ret = proxyWorker.init(ipam, std::move(fd)); if (ret < 0) { LOG({{proxy_worker_name}}, Error) << "Failed to initialize proxy worker"; -- cgit v1.2.1