From 7a42f3c3d88926aa05b07d9c6a783bdbbfb73610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 22 Jan 2025 12:35:15 +0100 Subject: [PATCH] libcamera: process: start(): Use span instead of vector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a span instead of a const reference to a vector, this does not change the behaviour and allows e.g. arrays to be used to hold arguments/file descriptors. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/process.h | 6 +++--- src/libcamera/ipc_pipe_unixsocket.cpp | 9 +++------ src/libcamera/process.cpp | 6 +++--- test/process/process_test.cpp | 5 ++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h index 891e7894..307c809f 100644 --- a/include/libcamera/internal/process.h +++ b/include/libcamera/internal/process.h @@ -9,10 +9,10 @@ #include #include -#include #include #include +#include #include namespace libcamera { @@ -32,8 +32,8 @@ public: ~Process(); int start(const std::string &path, - const std::vector &args = std::vector(), - const std::vector &fds = std::vector()); + Span args = {}, + Span fds = {}); ExitStatus exitStatus() const { return exitStatus_; } int exitCode() const { return exitCode_; } diff --git a/src/libcamera/ipc_pipe_unixsocket.cpp b/src/libcamera/ipc_pipe_unixsocket.cpp index 668ec73b..7ee7cac7 100644 --- a/src/libcamera/ipc_pipe_unixsocket.cpp +++ b/src/libcamera/ipc_pipe_unixsocket.cpp @@ -28,10 +28,6 @@ IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath, const char *ipaProxyWorkerPath) : IPCPipe() { - std::vector fds; - std::vector args; - args.push_back(ipaModulePath); - socket_ = std::make_unique(); UniqueFD fd = socket_->create(); if (!fd.isValid()) { @@ -39,8 +35,9 @@ IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath, return; } socket_->readyRead.connect(this, &IPCPipeUnixSocket::readyRead); - args.push_back(std::to_string(fd.get())); - fds.push_back(fd.get()); + + std::array args{ std::string(ipaModulePath), std::to_string(fd.get()) }; + std::array fds{ fd.get() }; proc_ = std::make_unique(); int ret = proc_->start(ipaProxyWorkerPath, args, fds); diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index a7add0b1..479163e8 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -235,8 +235,8 @@ Process::~Process() * or a negative error code otherwise */ int Process::start(const std::string &path, - const std::vector &args, - const std::vector &fds) + Span args, + Span fds) { int ret; @@ -262,7 +262,7 @@ int Process::start(const std::string &path, if (isolate()) _exit(EXIT_FAILURE); - std::vector v(fds); + std::vector v(fds.begin(), fds.end()); v.push_back(STDERR_FILENO); closeAllFdsExcept(v); diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp index e9f5e7e9..a88d8fef 100644 --- a/test/process/process_test.cpp +++ b/test/process/process_test.cpp @@ -5,9 +5,9 @@ * Process test */ +#include #include #include -#include #include #include @@ -48,8 +48,7 @@ protected: Timer timeout; int exitCode = 42; - vector args; - args.push_back(to_string(exitCode)); + std::array args{ to_string(exitCode) }; proc_.finished.connect(this, &ProcessTest::procFinished); /* Test that kill() on an unstarted process is safe. */