{"id":23249,"url":"https://patchwork.libcamera.org/api/patches/23249/?format=json","web_url":"https://patchwork.libcamera.org/patch/23249/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250424112203.445351-8-barnabas.pocze@ideasonboard.com>","date":"2025-04-24T11:22:00","name":"[RFC,v4,7/9] libcamera: process: Move `closeAllFdsExcept()`","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6a323e0c88605be3a2ab9bd112fefe8f7269e1f1","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23249/mbox/","series":[{"id":5144,"url":"https://patchwork.libcamera.org/api/series/5144/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5144","date":"2025-04-24T11:21:53","name":"libcamera: process: Remove `ProcessManager` singleton","version":4,"mbox":"https://patchwork.libcamera.org/series/5144/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23249/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23249/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 003FFC3322\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Apr 2025 11:22:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3DB7A68AD1;\n\tThu, 24 Apr 2025 13:22:21 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D162168AD5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Apr 2025 13:22:08 +0200 (CEST)","from pb-laptop.local (185.221.143.16.nat.pool.zt.hu\n\t[185.221.143.16])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D59BE16A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Apr 2025 13:22:06 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"I9xSrmvo\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1745493726;\n\tbh=X2o2EEnbixf3rrcrZfDkTDGdmSlEUbfzYv236RR2Je0=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=I9xSrmvon3Q0Vqm89bsWvuNGJw8HPjQUsbKobazSJCDlxk8oRGil6kt+OVI4JvGsG\n\tk0iZTeyNdxdoTFUpmzQ3yOQ8VqOTQ8Mo9EqfKbzYP7fczFiPawDKU07mDESi3kWubu\n\tkBni70pejWlgm9geUsGHmA77AfVEpjmb36l7pZnY=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[RFC PATCH v4 7/9] libcamera: process: Move `closeAllFdsExcept()`","Date":"Thu, 24 Apr 2025 13:22:00 +0200","Message-ID":"<20250424112203.445351-8-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.49.0","In-Reply-To":"<20250424112203.445351-1-barnabas.pocze@ideasonboard.com>","References":"<20250424112203.445351-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Remove `closeAllFdsExcept()` from the `Process` class and have it as a\nlocal function since it is no needed \"outside\" and does not depend on\nany part of the `Process` class.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n include/libcamera/internal/process.h |  1 -\n src/libcamera/process.cpp            | 56 ++++++++++++++--------------\n 2 files changed, 28 insertions(+), 29 deletions(-)","diff":"diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h\nindex b8eb7e043..e55d11fa3 100644\n--- a/include/libcamera/internal/process.h\n+++ b/include/libcamera/internal/process.h\n@@ -45,7 +45,6 @@ public:\n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(Process)\n \n-\tvoid closeAllFdsExcept(Span<const int> fds);\n \tint isolate();\n \tvoid died(int wstatus);\n \ndiff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\nindex 99bc3ad36..369fdb12d 100644\n--- a/src/libcamera/process.cpp\n+++ b/src/libcamera/process.cpp\n@@ -63,6 +63,34 @@ void sigact(int signal, siginfo_t *info, void *ucontext)\n \t}\n }\n \n+void closeAllFdsExcept(Span<const int> fds)\n+{\n+\tstd::vector<int> v(fds.begin(), fds.end());\n+\tsort(v.begin(), v.end());\n+\n+\tASSERT(v.empty() || v.front() >= 0);\n+\n+\tDIR *dir = opendir(\"/proc/self/fd\");\n+\tif (!dir)\n+\t\treturn;\n+\n+\tint dfd = dirfd(dir);\n+\n+\tstruct dirent *ent;\n+\twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tchar *endp;\n+\t\tint fd = strtoul(ent->d_name, &endp, 10);\n+\t\tif (*endp)\n+\t\t\tcontinue;\n+\n+\t\tif (fd >= 0 && fd != dfd &&\n+\t\t    !std::binary_search(v.begin(), v.end(), fd))\n+\t\t\tclose(fd);\n+\t}\n+\n+\tclosedir(dir);\n+}\n+\n } /* namespace */\n \n void ProcessManager::sighandler()\n@@ -282,34 +310,6 @@ int Process::start(const std::string &path,\n \t}\n }\n \n-void Process::closeAllFdsExcept(Span<const int> fds)\n-{\n-\tstd::vector<int> v(fds.begin(), fds.end());\n-\tsort(v.begin(), v.end());\n-\n-\tASSERT(v.empty() || v.front() >= 0);\n-\n-\tDIR *dir = opendir(\"/proc/self/fd\");\n-\tif (!dir)\n-\t\treturn;\n-\n-\tint dfd = dirfd(dir);\n-\n-\tstruct dirent *ent;\n-\twhile ((ent = readdir(dir)) != nullptr) {\n-\t\tchar *endp;\n-\t\tint fd = strtoul(ent->d_name, &endp, 10);\n-\t\tif (*endp)\n-\t\t\tcontinue;\n-\n-\t\tif (fd >= 0 && fd != dfd &&\n-\t\t    !std::binary_search(v.begin(), v.end(), fd))\n-\t\t\tclose(fd);\n-\t}\n-\n-\tclosedir(dir);\n-}\n-\n int Process::isolate()\n {\n \tint ret = unshare(CLONE_NEWUSER | CLONE_NEWNET);\n","prefixes":["RFC","v4","7/9"]}