From patchwork Mon Jul 28 11:36:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23992 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A6BE5C3323 for ; Mon, 28 Jul 2025 11:36:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 07EC469153; Mon, 28 Jul 2025 13:36:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GlcZmVFi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 571A769158 for ; Mon, 28 Jul 2025 13:36:46 +0200 (CEST) Received: from pb-laptop.local (185.221.140.39.nat.pool.zt.hu [185.221.140.39]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E4404A4 for ; Mon, 28 Jul 2025 13:36:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753702564; bh=6amt1pfSCZMrGeT/snXCoeIbXZlm0bIT7dtXjOLqdwU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GlcZmVFi8/Yhl/NP38CEnQZ5tB4kDy9D9PTvXboJmvb8KT6bkRdkTe/9iaZ1NDOa6 m3BHQkMoqzhMKAZEYRbIGCYr4otMHje3ZF//Ry++4VP+zZFC69EeYlFJ6fU3r8GzZu lK85pYd6HNgvymmE9E9lGs9buDbOVNNt3rQQPZbc= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v6 3/6] libcamera: process: closeAllFdsExcept(): Take vector by value Date: Mon, 28 Jul 2025 13:36:38 +0200 Message-ID: <20250728113641.238256-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250728113641.238256-1-barnabas.pocze@ideasonboard.com> References: <20250728113641.238256-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Laurent Pinchart --- 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 &fds); + void closeAllFdsExcept(std::vector 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 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 &fds) +void Process::closeAllFdsExcept(std::vector v) { - std::vector v(fds); sort(v.begin(), v.end()); ASSERT(v.empty() || v.front() >= 0);