[v6,3/6] libcamera: process: closeAllFdsExcept(): Take vector by value
diff mbox series

Message ID 20250728113641.238256-4-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: process: Remove `ProcessManager` singleton
Related show

Commit Message

Barnabás Pőcze July 28, 2025, 11:36 a.m. UTC
Instead of creating a new vector, take the vector by value to make it
possible for the caller to use move construction when calling the function.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/internal/process.h | 2 +-
 src/libcamera/process.cpp            | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart July 30, 2025, 4:24 p.m. UTC | #1
Hi Barnabàs,

Thank you for the patch.

On Mon, Jul 28, 2025 at 01:36:38PM +0200, Barnabás Pőcze wrote:
> Instead of creating a new vector, take the vector by value to make it
> possible for the caller to use move construction when calling the function.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  include/libcamera/internal/process.h | 2 +-
>  src/libcamera/process.cpp            | 5 ++---
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h
> index 307c809f7..4ab846b24 100644
> --- a/include/libcamera/internal/process.h
> +++ b/include/libcamera/internal/process.h
> @@ -45,7 +45,7 @@ public:
>  private:
>  	LIBCAMERA_DISABLE_COPY_AND_MOVE(Process)
>  
> -	void closeAllFdsExcept(const std::vector<int> &fds);
> +	void closeAllFdsExcept(std::vector<int> v);
>  	int isolate();
>  	void died(int wstatus);
>  
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index 479163e83..5193386ce 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -264,7 +264,7 @@ int Process::start(const std::string &path,
>  
>  		std::vector<int> v(fds.begin(), fds.end());
>  		v.push_back(STDERR_FILENO);
> -		closeAllFdsExcept(v);
> +		closeAllFdsExcept(std::move(v));
>  
>  		const auto tryDevNullLowestFd = [](int expected, int oflag) {
>  			int fd = open("/dev/null", oflag);
> @@ -296,9 +296,8 @@ int Process::start(const std::string &path,
>  	}
>  }
>  
> -void Process::closeAllFdsExcept(const std::vector<int> &fds)
> +void Process::closeAllFdsExcept(std::vector<int> v)
>  {
> -	std::vector<int> v(fds);
>  	sort(v.begin(), v.end());
>  
>  	ASSERT(v.empty() || v.front() >= 0);

Patch
diff mbox series

diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h
index 307c809f7..4ab846b24 100644
--- a/include/libcamera/internal/process.h
+++ b/include/libcamera/internal/process.h
@@ -45,7 +45,7 @@  public:
 private:
 	LIBCAMERA_DISABLE_COPY_AND_MOVE(Process)
 
-	void closeAllFdsExcept(const std::vector<int> &fds);
+	void closeAllFdsExcept(std::vector<int> v);
 	int isolate();
 	void died(int wstatus);
 
diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
index 479163e83..5193386ce 100644
--- a/src/libcamera/process.cpp
+++ b/src/libcamera/process.cpp
@@ -264,7 +264,7 @@  int Process::start(const std::string &path,
 
 		std::vector<int> v(fds.begin(), fds.end());
 		v.push_back(STDERR_FILENO);
-		closeAllFdsExcept(v);
+		closeAllFdsExcept(std::move(v));
 
 		const auto tryDevNullLowestFd = [](int expected, int oflag) {
 			int fd = open("/dev/null", oflag);
@@ -296,9 +296,8 @@  int Process::start(const std::string &path,
 	}
 }
 
-void Process::closeAllFdsExcept(const std::vector<int> &fds)
+void Process::closeAllFdsExcept(std::vector<int> v)
 {
-	std::vector<int> v(fds);
 	sort(v.begin(), v.end());
 
 	ASSERT(v.empty() || v.front() >= 0);