[{"id":34313,"web_url":"https://patchwork.libcamera.org/comment/34313/","msgid":"<174785098114.14042.13403193866782416668@calcite>","date":"2025-05-21T18:09:41","subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Julien Vuillaumier (2025-05-19 14:23:52)\n> When a child process is started from Process::start(), the file\n> descriptors inherited from the parent process are closed, except\n> the ones explicitly listed in the fds[] argument.\n> \n> One issue is that the file descriptors for stdin, stdout and stderr\n> being closed, the subsequent file descriptors created by the child\n> process will reuse the values 0, 1 and 2 that are now available.\n> Thus, usage of printf(), assert() or alike may direct its output\n> to the new resource bound to one of these reused file descriptors.\n> The other issue is that the child process can no longer log on\n> the console because stderr has been closed.\n> \n> To address the 2 issues, Process:start() is amended as below:\n> - Child process inherits from parent's stderr fd in order to share\n> the same logging descriptor\n> - Child process stdin, stdout and stderr fds are bound to /dev/null\n> if not inherited from parent. That is to prevent those descriptors\n> to be reused for any other resource, that could be corrupted by\n> the presence of printf(), assert() or alike.\n> \n> Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/libcamera/process.cpp | 16 +++++++++++++++-\n>  1 file changed, 15 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n> index 68fad327..fa92f58c 100644\n> --- a/src/libcamera/process.cpp\n> +++ b/src/libcamera/process.cpp\n> @@ -259,7 +259,21 @@ int Process::start(const std::string &path,\n>                 if (isolate())\n>                         _exit(EXIT_FAILURE);\n>  \n> -               closeAllFdsExcept(fds);\n> +               std::vector<int> v(fds);\n> +               v.push_back(STDERR_FILENO);\n> +               closeAllFdsExcept(v);\n> +\n> +               const auto tryDevNullLowestFd = [](int expected, int oflag) {\n> +                       int fd = open(\"/dev/null\", oflag);\n> +                       if (fd < 0)\n> +                               exit(EXIT_FAILURE);\n> +                       if (fd != expected)\n> +                               close(fd);\n> +               };\n> +\n> +               tryDevNullLowestFd(STDIN_FILENO, O_RDONLY);\n> +               tryDevNullLowestFd(STDOUT_FILENO, O_WRONLY);\n> +               tryDevNullLowestFd(STDERR_FILENO, O_WRONLY);\n>  \n>                 const char *file = utils::secure_getenv(\"LIBCAMERA_LOG_FILE\");\n>                 if (file && strcmp(file, \"syslog\"))\n> -- \n> 2.34.1\n>","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 202ABBD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 May 2025 18:09:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D8FE768D93;\n\tWed, 21 May 2025 20:09:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 23D4F68C91\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 May 2025 20:09:44 +0200 (CEST)","from pyrite.rasen.tech (unknown [149.232.183.6])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 815443A4;\n\tWed, 21 May 2025 20:09:22 +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=\"ejNjNV/Z\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747850962;\n\tbh=lAtuO0w22puCa7O6kvG0VOKLDjJawzRwauksPTHIhJs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=ejNjNV/Z65K6Pdc11y6UGKwhisi3za4lDjM+HqxqNkqZ+6O44wF1YeSNevYbl8hmf\n\tmSam6pwfNUvllSE6S3f1WcOcl5W5qszLssHX2uNdJD/T4e9lC9dc5KjpBvK2I8ASHj\n\tcu+7TlSB104QY2wW0zEekbas5zq7lC9E7Q7R4Geo=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250519122352.1675360-2-julien.vuillaumier@nxp.com>","References":"<20250519122352.1675360-1-julien.vuillaumier@nxp.com>\n\t<20250519122352.1675360-2-julien.vuillaumier@nxp.com>","Subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Julien Vuillaumier <julien.vuillaumier@nxp.com>","To":"Julien Vuillaumier <julien.vuillaumier@nxp.com>,\n\tbarnabas.pocze@ideasonboard.com, libcamera-devel@lists.libcamera.org","Date":"Wed, 21 May 2025 20:09:41 +0200","Message-ID":"<174785098114.14042.13403193866782416668@calcite>","User-Agent":"alot/0.10","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>"}},{"id":34314,"web_url":"https://patchwork.libcamera.org/comment/34314/","msgid":"<68639598-945d-4b93-8b5f-751f79e33abb@ideasonboard.com>","date":"2025-05-21T20:53:55","subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n\n2025. 05. 19. 14:23 keltezéssel, Julien Vuillaumier írta:\n> When a child process is started from Process::start(), the file\n> descriptors inherited from the parent process are closed, except\n> the ones explicitly listed in the fds[] argument.\n> \n> One issue is that the file descriptors for stdin, stdout and stderr\n> being closed, the subsequent file descriptors created by the child\n> process will reuse the values 0, 1 and 2 that are now available.\n> Thus, usage of printf(), assert() or alike may direct its output\n> to the new resource bound to one of these reused file descriptors.\n> The other issue is that the child process can no longer log on\n> the console because stderr has been closed.\n> \n> To address the 2 issues, Process:start() is amended as below:\n> - Child process inherits from parent's stderr fd in order to share\n> the same logging descriptor\n> - Child process stdin, stdout and stderr fds are bound to /dev/null\n> if not inherited from parent. That is to prevent those descriptors\n> to be reused for any other resource, that could be corrupted by\n> the presence of printf(), assert() or alike.\n> \n> Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>\n> ---\n>   src/libcamera/process.cpp | 16 +++++++++++++++-\n>   1 file changed, 15 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n> index 68fad327..fa92f58c 100644\n> --- a/src/libcamera/process.cpp\n> +++ b/src/libcamera/process.cpp\n> @@ -259,7 +259,21 @@ int Process::start(const std::string &path,\n>   \t\tif (isolate())\n>   \t\t\t_exit(EXIT_FAILURE);\n>   \n> -\t\tcloseAllFdsExcept(fds);\n> +\t\tstd::vector<int> v(fds);\n> +\t\tv.push_back(STDERR_FILENO);\n> +\t\tcloseAllFdsExcept(v);\n> +\n> +\t\tconst auto tryDevNullLowestFd = [](int expected, int oflag) {\n> +\t\t\tint fd = open(\"/dev/null\", oflag);\n> +\t\t\tif (fd < 0)\n> +\t\t\t\texit(EXIT_FAILURE);\n\nI have missed this earlier, but I think this should be `_exit()` since calling\nany `at{,_quick_}exit()` handlers is likely problematic.\n\n\nRegards,\nBarnabás Pőcze\n\n\n> +\t\t\tif (fd != expected)\n> +\t\t\t\tclose(fd);\n> +\t\t};\n> +\n> +\t\ttryDevNullLowestFd(STDIN_FILENO, O_RDONLY);\n> +\t\ttryDevNullLowestFd(STDOUT_FILENO, O_WRONLY);\n> +\t\ttryDevNullLowestFd(STDERR_FILENO, O_WRONLY);\n>   \n>   \t\tconst char *file = utils::secure_getenv(\"LIBCAMERA_LOG_FILE\");\n>   \t\tif (file && strcmp(file, \"syslog\"))","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 DB908BD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 May 2025 20:54:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 12E3768C91;\n\tWed, 21 May 2025 22:54:01 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BE87E68C91\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 May 2025 22:53:59 +0200 (CEST)","from [192.168.33.23] (185.221.141.78.nat.pool.zt.hu\n\t[185.221.141.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0407B3A4;\n\tWed, 21 May 2025 22:53:37 +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=\"n0qhVls3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747860818;\n\tbh=ukMVvyj531GrX2VhigLSC6dBHbMn+VNtQtfkQjTQhg4=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=n0qhVls3aTd1yZLNsM0FUfVZqrm4FrQtCnH+/+zbLj5jh4aQZgkEZibDmNxnCq8QQ\n\tFMDNyUq4RwISLho6cw0zcMhQaknt7FCqn8mthfRYcS477Bb7uenYQ1YNZnkyyr2sOn\n\th4zgMA3efNYffV96D+maLd7IlsbgDUKbxH3tGaiU=","Message-ID":"<68639598-945d-4b93-8b5f-751f79e33abb@ideasonboard.com>","Date":"Wed, 21 May 2025 22:53:55 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","To":"Julien Vuillaumier <julien.vuillaumier@nxp.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250519122352.1675360-1-julien.vuillaumier@nxp.com>\n\t<20250519122352.1675360-2-julien.vuillaumier@nxp.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250519122352.1675360-2-julien.vuillaumier@nxp.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}},{"id":34315,"web_url":"https://patchwork.libcamera.org/comment/34315/","msgid":"<20250521230440.GM12514@pendragon.ideasonboard.com>","date":"2025-05-21T23:04:40","subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Julien,\n\nThank you for the patch.\n\nOn Mon, May 19, 2025 at 02:23:52PM +0200, Julien Vuillaumier wrote:\n> When a child process is started from Process::start(), the file\n> descriptors inherited from the parent process are closed, except\n> the ones explicitly listed in the fds[] argument.\n> \n> One issue is that the file descriptors for stdin, stdout and stderr\n> being closed, the subsequent file descriptors created by the child\n> process will reuse the values 0, 1 and 2 that are now available.\n> Thus, usage of printf(), assert() or alike may direct its output\n> to the new resource bound to one of these reused file descriptors.\n> The other issue is that the child process can no longer log on\n> the console because stderr has been closed.\n> \n> To address the 2 issues, Process:start() is amended as below:\n> - Child process inherits from parent's stderr fd in order to share\n> the same logging descriptor\n> - Child process stdin, stdout and stderr fds are bound to /dev/null\n> if not inherited from parent. That is to prevent those descriptors\n> to be reused for any other resource, that could be corrupted by\n> the presence of printf(), assert() or alike.\n> \n> Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>\n> ---\n>  src/libcamera/process.cpp | 16 +++++++++++++++-\n>  1 file changed, 15 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n> index 68fad327..fa92f58c 100644\n> --- a/src/libcamera/process.cpp\n> +++ b/src/libcamera/process.cpp\n> @@ -259,7 +259,21 @@ int Process::start(const std::string &path,\n>  \t\tif (isolate())\n>  \t\t\t_exit(EXIT_FAILURE);\n>  \n> -\t\tcloseAllFdsExcept(fds);\n> +\t\tstd::vector<int> v(fds);\n> +\t\tv.push_back(STDERR_FILENO);\n\nThere's still a risk that STDERR_FILENO refers to a different file than\nstderr. Could you test this patch (with an IPA module running in\nisolated mode) with pipewire ? If that doesn't cause any issue I'll feel\nbetter accepting the risk.\n\n> +\t\tcloseAllFdsExcept(v);\n> +\n> +\t\tconst auto tryDevNullLowestFd = [](int expected, int oflag) {\n> +\t\t\tint fd = open(\"/dev/null\", oflag);\n> +\t\t\tif (fd < 0)\n> +\t\t\t\texit(EXIT_FAILURE);\n> +\t\t\tif (fd != expected)\n> +\t\t\t\tclose(fd);\n> +\t\t};\n> +\n> +\t\ttryDevNullLowestFd(STDIN_FILENO, O_RDONLY);\n> +\t\ttryDevNullLowestFd(STDOUT_FILENO, O_WRONLY);\n> +\t\ttryDevNullLowestFd(STDERR_FILENO, O_WRONLY);\n>  \n>  \t\tconst char *file = utils::secure_getenv(\"LIBCAMERA_LOG_FILE\");\n>  \t\tif (file && strcmp(file, \"syslog\"))","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 B3023C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 May 2025 23:04:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6CE2068D92;\n\tThu, 22 May 2025 01:04:49 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BF2261690\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 22 May 2025 01:04:47 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(179.218-130-109.adsl-dyn.isp.belgacom.be [109.130.218.179])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B06D64A4;\n\tThu, 22 May 2025 01:04:25 +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=\"XIyA19Nm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747868665;\n\tbh=nyj/ah+LOKLcZTw+2XMKFyNJF419yT+P67gUYcu6YQ8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=XIyA19Nmb4LuQPt3iBZaeZgJHVl7p9juChYB58klDPgU5lG5vDk2HzKjWA7SiBe+y\n\tsrpvIGggcRFsHED2vbkrOgcdq7KWMhltvk/gRLrAZQauf23elFtnhNz6osjedmdOhf\n\tMuKfsjl64XXF0gVU2bfg1WGgXgJ22zR6tvAE+IEY=","Date":"Thu, 22 May 2025 01:04:40 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Julien Vuillaumier <julien.vuillaumier@nxp.com>","Cc":"libcamera-devel@lists.libcamera.org, barnabas.pocze@ideasonboard.com","Subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","Message-ID":"<20250521230440.GM12514@pendragon.ideasonboard.com>","References":"<20250519122352.1675360-1-julien.vuillaumier@nxp.com>\n\t<20250519122352.1675360-2-julien.vuillaumier@nxp.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250519122352.1675360-2-julien.vuillaumier@nxp.com>","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>"}},{"id":34347,"web_url":"https://patchwork.libcamera.org/comment/34347/","msgid":"<f36acfd0-ee6d-4fcd-9c0a-32efab4cebdd@nxp.com>","date":"2025-05-23T18:41:35","subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","submitter":{"id":190,"url":"https://patchwork.libcamera.org/api/people/190/","name":"Julien Vuillaumier","email":"julien.vuillaumier@nxp.com"},"content":"Hello Barnabás,\n\nOn 21/05/2025 22:53, Barnabás Pőcze wrote:\n> Hi\n> \n> \n> 2025. 05. 19. 14:23 keltezéssel, Julien Vuillaumier írta:\n>> When a child process is started from Process::start(), the file\n>> descriptors inherited from the parent process are closed, except\n>> the ones explicitly listed in the fds[] argument.\n>>\n>> One issue is that the file descriptors for stdin, stdout and stderr\n>> being closed, the subsequent file descriptors created by the child\n>> process will reuse the values 0, 1 and 2 that are now available.\n>> Thus, usage of printf(), assert() or alike may direct its output\n>> to the new resource bound to one of these reused file descriptors.\n>> The other issue is that the child process can no longer log on\n>> the console because stderr has been closed.\n>>\n>> To address the 2 issues, Process:start() is amended as below:\n>> - Child process inherits from parent's stderr fd in order to share\n>> the same logging descriptor\n>> - Child process stdin, stdout and stderr fds are bound to /dev/null\n>> if not inherited from parent. That is to prevent those descriptors\n>> to be reused for any other resource, that could be corrupted by\n>> the presence of printf(), assert() or alike.\n>>\n>> Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>\n>> ---\n>>   src/libcamera/process.cpp | 16 +++++++++++++++-\n>>   1 file changed, 15 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n>> index 68fad327..fa92f58c 100644\n>> --- a/src/libcamera/process.cpp\n>> +++ b/src/libcamera/process.cpp\n>> @@ -259,7 +259,21 @@ int Process::start(const std::string &path,\n>>               if (isolate())\n>>                       _exit(EXIT_FAILURE);\n>>\n>> -             closeAllFdsExcept(fds);\n>> +             std::vector<int> v(fds);\n>> +             v.push_back(STDERR_FILENO);\n>> +             closeAllFdsExcept(v);\n>> +\n>> +             const auto tryDevNullLowestFd = [](int expected, int \n>> oflag) {\n>> +                     int fd = open(\"/dev/null\", oflag);\n>> +                     if (fd < 0)\n>> +                             exit(EXIT_FAILURE);\n> \n> I have missed this earlier, but I think this should be `_exit()` since \n> calling\n> any `at{,_quick_}exit()` handlers is likely problematic.\n\nAfter some googling, recommendation seems to be using _exit() instead of \nexit() in the child process, for occurrences that are not invoked within \nan exec() - that is to avoid interfering with the parent process [1].\n\nSo I'll add that change, thanks for the suggestion.\n\nWhile at it, the `exit(EXIT_FAILURE)` in case of execv() failure in the \nexisting implementation does not seem correct and presumably needs to be \nconverted to an _exit() as well.\n\n[1] https://stackoverflow.com/a/5423108\n\nThanks,\nJulien","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 81532C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 23 May 2025 18:41:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3218868D96;\n\tFri, 23 May 2025 20:41:42 +0200 (CEST)","from EUR05-DB8-obe.outbound.protection.outlook.com\n\t(mail-db8eur05on20613.outbound.protection.outlook.com\n\t[IPv6:2a01:111:f403:2614::613])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CD3F668D76\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 May 2025 20:41:39 +0200 (CEST)","from AM9PR04MB8147.eurprd04.prod.outlook.com\n\t(2603:10a6:20b:3e0::22)\n\tby AS8PR04MB7942.eurprd04.prod.outlook.com (2603:10a6:20b:2a9::13)\n\twith Microsoft SMTP Server (version=TLS1_2,\n\tcipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8746.30;\n\tFri, 23 May 2025 18:41:38 +0000","from AM9PR04MB8147.eurprd04.prod.outlook.com\n\t([fe80::eace:e980:28a4:ef8a]) by\n\tAM9PR04MB8147.eurprd04.prod.outlook.com\n\t([fe80::eace:e980:28a4:ef8a%7]) with mapi id 15.20.8722.027;\n\tFri, 23 May 2025 18:41:38 +0000"],"Authentication-Results":["lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=nxp.com header.i=@nxp.com header.b=\"H522XBt/\";\n\tdkim-atps=neutral","dkim=none (message not signed)\n\theader.d=none;dmarc=none action=none header.from=nxp.com;"],"ARC-Seal":"i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;\n\tb=j3MytgxFov8sD+oraWsu+WYSTqhLfO4Dnb351UuLopyH9qk3TeC63T8L5mvCDo4EKxXeN9pU66RUqAhvUSTeuqQ7SPzw2HSTKQBwOuxlTKJrx75A8J6OvfIg/EhONwvnDgIOiABzR11p+VcUeZtVhRKZE/Kv8eUcqOT1qiVg9xkBneCnI/52Ps5cGGcPC3DEgvs9rBnFAswzm72pK/4BBOTQAwg9eVOYfKR6cc4594a0gAfcVTq4x/cemaCJrlVdLQX98mNWKsGX35h2RzrVQpnUDxLj+hY7l8IOhIQfo6b0y3egqyMhGvdwSBxhTY+c4GqZGSF2OsN8eMknT7scBg==","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n\ts=arcselector10001;\n\th=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;\n\tbh=Z0QyBJ5+ZLysO89D2GaRzzo3BN4Qoev7SZcR1NcGUKA=;\n\tb=RCa2XITX9+mcM/kbeNYtUIIARzw7WKs59h/es9p1cLJewQQ07314/nIfDrl9zWU3PAk09Ig+PCoCvOhwI0x2Do+W1OPcP1BwSY5aZP0qeErODl4KCHNYHgKQNbF7viAfTsStQ1QC1FAIK2SZcONYgrZ2qT68fiXWblaoxUEILoaHNfLSUxXsx29x7Wb7SvmVXpq8L4ycEExx9I8PlUEPayTNQTHr+5z3AGTZbx+vsBxSeo81sShoigjJbqvOth985RtfkNjnMHd22/gPc9fYgwUK4qCSQAnaEFlkzt2ACYGaIsHsRS38uOSp+BT3V4LSiKqKdfX5X+d9+VSxBFEbKQ==","ARC-Authentication-Results":"i=1; mx.microsoft.com 1; spf=pass\n\tsmtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com;\n\tdkim=pass header.d=nxp.com; arc=none","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1;\n\th=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n\tbh=Z0QyBJ5+ZLysO89D2GaRzzo3BN4Qoev7SZcR1NcGUKA=;\n\tb=H522XBt/ccDUDSNZYhGexs/ZzZxAk37axj6fU1zKCpCoND1ytDR16Mhicd95BdwyAb44pL4QnvP76bTxjXfQGIwN+JqL8Z2kwyG8NhQ3y2R/L05SWKrlj3LGeL0xoYbllnxUUQReKKXpFOU1O/b78QcCZCpV8ySpGqJ9FiRLxcSDLbMcIY7aJFWwu8hatg1iGdBkKCgIMQ0Ru4iVG0Gdiy9vHvaMjZPAUcJmfYwXV0SPsXjP1drr56el+JS7/B5dN09W6FvI6UErjZmKJ4hp01sxxFgNlhFkCWgrkYZSX3x5W1STWpuAkdsJXttyio6TF5uOZznboFUcjb2oX59YIw==","Message-ID":"<f36acfd0-ee6d-4fcd-9c0a-32efab4cebdd@nxp.com>","Date":"Fri, 23 May 2025 20:41:35 +0200","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250519122352.1675360-1-julien.vuillaumier@nxp.com>\n\t<20250519122352.1675360-2-julien.vuillaumier@nxp.com>\n\t<68639598-945d-4b93-8b5f-751f79e33abb@ideasonboard.com>","Content-Language":"en-US","From":"Julien Vuillaumier <julien.vuillaumier@nxp.com>","In-Reply-To":"<68639598-945d-4b93-8b5f-751f79e33abb@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-ClientProxiedBy":"AM0PR01CA0120.eurprd01.prod.exchangelabs.com\n\t(2603:10a6:208:168::25) To AM9PR04MB8147.eurprd04.prod.outlook.com\n\t(2603:10a6:20b:3e0::22)","MIME-Version":"1.0","X-MS-PublicTrafficType":"Email","X-MS-TrafficTypeDiagnostic":"AM9PR04MB8147:EE_|AS8PR04MB7942:EE_","X-MS-Office365-Filtering-Correlation-Id":"e4477b30-3e51-44b9-3c25-08dd9a297392","X-MS-Exchange-SenderADCheck":"1","X-MS-Exchange-AntiSpam-Relay":"0","X-Microsoft-Antispam":"BCL:0;ARA:13230040|1800799024|376014|366016;","X-Microsoft-Antispam-Message-Info":"=?utf-8?q?uLyRJtbhE9tYZKbQ7K8JWIHSM1kN?=\n\t=?utf-8?q?oUxAR1lq8/RAKSyRa9l+1glKVnTjVEQBMioyF3MeWXqTJ5SJ+SHRQ25N?=\n\t=?ut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ZNP34/EZh+nGCfrQFK7bpNAz5r5lm40Fx3qmhAmaF7FeUqzCJg/?=\n\t=?utf-8?q?/Fhp5rXuDCQnNChZCU7UF8qunGvajDdaIWeXMUtMOWS1weq3SKuMOo88?=\n\t=?utf-8?q?P5n08FNlK/uz45EwnhWS93iBJqWoElVhbRgFz73QtzrWJZG3H+h0ouxe?=\n\t=?utf-8?q?ES+AJOUeDJ+0pWr6aonSldrl13/eBqMJn9dQSBZtnDVT0ojTs4QqNKJO?=\n\t=?utf-8?q?yPKrXTPacm0bZjmyHe19CbA0RwL1eZmV8H+ia8MpGz0aVZ6G34CSLLsh?=\n\t=?utf-8?q?67tNAXYkKMURc1/WzGy1pWirDvUTzBFEcsr4trNryW607Z48/S6WtITY?=\n\t=?utf-8?q?KCX3wEpb834/CgHZMxHb/D0aHqx/tiysNx20rj9F3tYcLLOZO9fmNxpD?=\n\t=?utf-8?q?H5syfA7aM9Mc6Xq7IGpNm5/fHgBGIuNWiCKZGtadUhkZGEpxHmijR/LS?=\n\t=?utf-8?q?tO438adcBI5AQVU=3D?=","X-Forefront-Antispam-Report":"CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;\n\tIPV:NLI; SFV:NSPM; H:AM9PR04MB8147.eurprd04.prod.outlook.com; PTR:;\n\tCAT:NONE; \n\tSFS:(13230040)(1800799024)(376014)(366016); DIR:OUT; SFP:1101; ","X-MS-Exchange-AntiSpam-MessageData-ChunkCount":"1","X-MS-Exchange-AntiSpam-MessageData-0":"=?utf-8?q?PiJHLjIJXEsaP2F2icBXXLWMu?=\n\t=?utf-8?q?tRTgj7jxFsc6Ea0GhYUl+eue/m1ajv0w4NwacQUDw3l2oU8cUuupVsDx?=\n\t=?utf-8?q?EzMmjqxWDOnmmsn1K0jstRDtviTkyGcffKJ0g4JHvhOYwFP0w2e9c1+z?=\n\t=?utf-8?q?h4k7IiwlPXt9lT9YDD/lNxoSYwd3xC7UFoVgFjLLHuCPHDz08atgMads?=\n\t=?utf-8?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f-8?q?2JHogKaMHu4vh12L7deMU2c6t9SC3ZcyHexkmVGjai6gspM/DcQ6Bd5T?=\n\t=?utf-8?q?UdzS8K7Xix92gj0/LyAXbwaXkDAB+OTidcMJ/dq932cIsbqI+zTFtjhT?=\n\t=?utf-8?q?SO/WgNo5fU0UE/SH2WuCRC2kMVza9dNhbJy5tEaFu91DU9sYYIRdKy31?=\n\t=?utf-8?q?9Fhym0/ZAFaE3RilMzqhvAvTaQn/WNfQzxcQiUWnWwe/nXAzji7G54xv?=\n\t=?utf-8?q?qTnfA+oB5IrTpYF/LaZkf7+GUIknxQ0g4yBXu9nZhaYQ4IyzhpsDoN9f?=\n\t=?utf-8?q?yIXPcW6vh0ZXrVtLf4x/C4NwCDLov9k+3lx2fwRr8UbpYW7SoaGZaBzB?=\n\t=?utf-8?q?8opBnIsZbn2WP9O/ydqvGwo/KlACXzCTJlM3UuJZMPicT9TZdsyjNM/O?=\n\t=?utf-8?q?9KTgDkmZB960zg86UID9IO/5rudP4Nln7XfebqlmSnSaLIhu2XXKtIOO?=\n\t=?utf-8?q?ViFDrxtrVFLXl54eGiToTIXitOEl3UjEr2sLdAXH42rdSK+Kyf+mNY/j?=\n\t=?utf-8?q?tMQPIgN+PamrJZOesx/ASraxX4XHF+4IQa9aEvlVTn1ZYJQORTOo2Q6s?=\n\t=?utf-8?q?gL0HN9aF+rtVjVg4kTYjEo4a0c2nw=3D=3D?=","X-OriginatorOrg":"nxp.com","X-MS-Exchange-CrossTenant-Network-Message-Id":"e4477b30-3e51-44b9-3c25-08dd9a297392","X-MS-Exchange-CrossTenant-AuthSource":"AM9PR04MB8147.eurprd04.prod.outlook.com","X-MS-Exchange-CrossTenant-AuthAs":"Internal","X-MS-Exchange-CrossTenant-OriginalArrivalTime":"23 May 2025 18:41:38.1240\n\t(UTC)","X-MS-Exchange-CrossTenant-FromEntityHeader":"Hosted","X-MS-Exchange-CrossTenant-Id":"686ea1d3-bc2b-4c6f-a92c-d99c5c301635","X-MS-Exchange-CrossTenant-MailboxType":"HOSTED","X-MS-Exchange-CrossTenant-UserPrincipalName":"tHidennno07DTGrR8U5smfrRh1B3k7jfdIOCfX8Kd3m70cLUPldgnSgSAPjfnhg7Se3ymN0cxoGUOCYA7LkQWjFN8DYGhHw26e6QaNgV43E=","X-MS-Exchange-Transport-CrossTenantHeadersStamped":"AS8PR04MB7942","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>"}},{"id":34354,"web_url":"https://patchwork.libcamera.org/comment/34354/","msgid":"<d69af22a-f7f8-464a-8044-707928499a52@nxp.com>","date":"2025-05-26T17:55:19","subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","submitter":{"id":190,"url":"https://patchwork.libcamera.org/api/people/190/","name":"Julien Vuillaumier","email":"julien.vuillaumier@nxp.com"},"content":"Hi Laurent,\n\nOn 22/05/2025 01:04, Laurent Pinchart wrote:\n> Hi Julien,\n> \n> Thank you for the patch.\n> \n> On Mon, May 19, 2025 at 02:23:52PM +0200, Julien Vuillaumier wrote:\n>> When a child process is started from Process::start(), the file\n>> descriptors inherited from the parent process are closed, except\n>> the ones explicitly listed in the fds[] argument.\n>>\n>> One issue is that the file descriptors for stdin, stdout and stderr\n>> being closed, the subsequent file descriptors created by the child\n>> process will reuse the values 0, 1 and 2 that are now available.\n>> Thus, usage of printf(), assert() or alike may direct its output\n>> to the new resource bound to one of these reused file descriptors.\n>> The other issue is that the child process can no longer log on\n>> the console because stderr has been closed.\n>>\n>> To address the 2 issues, Process:start() is amended as below:\n>> - Child process inherits from parent's stderr fd in order to share\n>> the same logging descriptor\n>> - Child process stdin, stdout and stderr fds are bound to /dev/null\n>> if not inherited from parent. That is to prevent those descriptors\n>> to be reused for any other resource, that could be corrupted by\n>> the presence of printf(), assert() or alike.\n>>\n>> Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>\n>> ---\n>>   src/libcamera/process.cpp | 16 +++++++++++++++-\n>>   1 file changed, 15 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n>> index 68fad327..fa92f58c 100644\n>> --- a/src/libcamera/process.cpp\n>> +++ b/src/libcamera/process.cpp\n>> @@ -259,7 +259,21 @@ int Process::start(const std::string &path,\n>>                if (isolate())\n>>                        _exit(EXIT_FAILURE);\n>>\n>> -             closeAllFdsExcept(fds);\n>> +             std::vector<int> v(fds);\n>> +             v.push_back(STDERR_FILENO);\n> \n> There's still a risk that STDERR_FILENO refers to a different file than\n> stderr. Could you test this patch (with an IPA module running in\n> isolated mode) with pipewire ? If that doesn't cause any issue I'll feel\n> better accepting the risk.\n\nI tested libcamera (v0.5.0 tag) running with vimc isolated IPA, operated \nfrom PipeWire / WirePlumber - both components are run as systemd \nservices. By default, systemd explicitly binds the standard descriptors \nof the services per mapping below:\n- STDIN_FILENO: /dev/null\n- STDOUT_FILENO: journal socket\n- STDERR_FILENO: same as STDOUT\nBut this mapping could be changed in the respective service \nconfiguration files, where standard descriptors may also be associated \nto a dedicated file, kmsg, a socket etc - see `Logging and Standard \nInput/Output` in [1].\n\nThus, when libcamera is invoked from either PipeWire or WirePlumber \nservice, the STDIN/STDOUT/STERR descriptors are already allocated and \nbound to some descriptors relevant for the standard input/output which \nis presumably safe. I suppose that any other configuration (standard \ndescriptors not allocated to standard IO) is unsafe.\n\nI have verified vimc IPA in isolated mode: this change enables the \nisolated IPA to output its log in the PipeWire unit journal \n(`journalctrl --user -u pipewire -f`). The journal daemon socket \ndescriptor mapped onto PipeWire STDERR_FILENO is inherited by the \nisolated IPA as expected.\n\nSide note: using isolated IPA with PW requires commenting out the line \n`RestrictNamespaces=yes` in the pipewire.service file [2].\nNo such issue exists in WirePlumber.\n\n[1]https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html\n[2] \nhttps://github.com/PipeWire/pipewire/blob/master/src/daemon/systemd/user/pipewire.service.in#L23\n\n>> +             closeAllFdsExcept(v);\n>> +\n>> +             const auto tryDevNullLowestFd = [](int expected, int oflag) {\n>> +                     int fd = open(\"/dev/null\", oflag);\n>> +                     if (fd < 0)\n>> +                             exit(EXIT_FAILURE);\n>> +                     if (fd != expected)\n>> +                             close(fd);\n>> +             };\n>> +\n>> +             tryDevNullLowestFd(STDIN_FILENO, O_RDONLY);\n>> +             tryDevNullLowestFd(STDOUT_FILENO, O_WRONLY);\n>> +             tryDevNullLowestFd(STDERR_FILENO, O_WRONLY);\n>>\n>>                const char *file = utils::secure_getenv(\"LIBCAMERA_LOG_FILE\");\n>>                if (file && strcmp(file, \"syslog\"))\n\nThanks,\nJulien","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 64CB4C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 26 May 2025 17:55:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 52860627DA;\n\tMon, 26 May 2025 19:55:25 +0200 (CEST)","from EUR02-AM0-obe.outbound.protection.outlook.com\n\t(mail-am0eur02on20622.outbound.protection.outlook.com\n\t[IPv6:2a01:111:f403:2606::622])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D522627DA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 May 2025 19:55:23 +0200 (CEST)","from AM9PR04MB8147.eurprd04.prod.outlook.com\n\t(2603:10a6:20b:3e0::22)\n\tby VI2PR04MB11172.eurprd04.prod.outlook.com (2603:10a6:800:29a::12)\n\twith Microsoft SMTP Server (version=TLS1_2,\n\tcipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8769.22;\n\tMon, 26 May 2025 17:55:21 +0000","from AM9PR04MB8147.eurprd04.prod.outlook.com\n\t([fe80::eace:e980:28a4:ef8a]) by\n\tAM9PR04MB8147.eurprd04.prod.outlook.com\n\t([fe80::eace:e980:28a4:ef8a%7]) with mapi id 15.20.8722.027;\n\tMon, 26 May 2025 17:55:21 +0000"],"Authentication-Results":["lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=nxp.com header.i=@nxp.com header.b=\"DvjX+YkN\";\n\tdkim-atps=neutral","dkim=none (message not signed)\n\theader.d=none;dmarc=none action=none header.from=nxp.com;"],"ARC-Seal":"i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;\n\tb=PVGvqUsHtLEwyGngfzE0JwyHr1xD91l2MoF3j3lcLrH59k6y3vCRPV0EF1RZN3707SwPL7B3BzSm+Q7rbkavTFq5CyjIxw0Ed2qXXH2/KEGleDi82IYzGRUW7Z8in2AWJK55LTa1rIoQzUb/TJm2n6l09gaDrVcaHFEQ/Mq7DZUjQZc+WOpoy9/WZnapjDeyou2LGmFvUE42z95tQOoM3x8iZVN0qfQnN8AmTxidn0wa2orlM9nASTwI5IMcVdo4l8ns4gbUe8a/sBZErml0QDA1u72a2m/ejt5Nc9xkcnNFpZ3qvnfsPP/wtAn393SnRHy5a8kjbz57MCQ10gLdhQ==","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n\ts=arcselector10001;\n\th=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;\n\tbh=ZHpPBwKaumlxjAgjacKY5i2vw6pITlb6L4ochprpL6A=;\n\tb=JDprEO3J0oDKiG31JIHZJTo29foUuGFE+Xnnpw78kMNQ3QJsiNIgxHLtITArUnbrwngyG+9+hY20NyKzwi7gjVcDCcLeaseA+1gksLVTRidSVfMoizy5zb2SBtBvlaltfFbIdC8/JYjW0L8kyKj7KM42gDa/vD1AxfKzO1QrJIv1vaFpuuOYrVhdBgPOGAqsFah4pKudABKp2qexaNWd0uSdk22xGGJvIS0xjE6LHNUQDh/NaQLAqBd7qTiOO4kuDShPu726Sbsml9GO8eNtTtSdtdYgWXVzg5XS3I924srZM4MbrQJy6yPPqHmMH3uSPJnIBaX4gKR0R7BMyGzU9Q==","ARC-Authentication-Results":"i=1; mx.microsoft.com 1; spf=pass\n\tsmtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com;\n\tdkim=pass header.d=nxp.com; arc=none","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1;\n\th=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n\tbh=ZHpPBwKaumlxjAgjacKY5i2vw6pITlb6L4ochprpL6A=;\n\tb=DvjX+YkNidRQFCSRzbzFHs5cojlU68rDwwKpIOojcOMNYevcRkCGD7WFtB20Shl6AIJw70+q0dyo4hRsSMIL7xo4jeAxIzWjdgdI8Z5Xv6UZY6ILILQq097dvl+NaCwDJg6W4p1eU2an35WbrH5T20aWcmgG1ibM0ENoaXeaNwpnXcgwAqCxYJSpGwgego/lrGNX3Y4nEHemMNsp1OaTN3wClx/HEyl++17jp21y9MHNMcOSJEPDWfLkjp0tAmxlh8x14p6GjoFdztOWe99F51MdpSe9CM7C81ME4p6znbXyocYIf6RK9TOgvGpamAojHrskz18rk0EjoY+pBCRecg==","Message-ID":"<d69af22a-f7f8-464a-8044-707928499a52@nxp.com>","Date":"Mon, 26 May 2025 19:55:19 +0200","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, barnabas.pocze@ideasonboard.com","References":"<20250519122352.1675360-1-julien.vuillaumier@nxp.com>\n\t<20250519122352.1675360-2-julien.vuillaumier@nxp.com>\n\t<20250521230440.GM12514@pendragon.ideasonboard.com>","Content-Language":"en-US","From":"Julien Vuillaumier <julien.vuillaumier@nxp.com>","In-Reply-To":"<20250521230440.GM12514@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-ClientProxiedBy":"AM0PR03CA0028.eurprd03.prod.outlook.com\n\t(2603:10a6:208:14::41) To AM9PR04MB8147.eurprd04.prod.outlook.com\n\t(2603:10a6:20b:3e0::22)","MIME-Version":"1.0","X-MS-PublicTrafficType":"Email","X-MS-TrafficTypeDiagnostic":"AM9PR04MB8147:EE_|VI2PR04MB11172:EE_","X-MS-Office365-Filtering-Correlation-Id":"b90249d4-ef28-47c7-e579-08dd9c7e7baa","X-LD-Processed":"686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr","X-MS-Exchange-SenderADCheck":"1","X-MS-Exchange-AntiSpam-Relay":"0","X-Microsoft-Antispam":"BCL:0;ARA:13230040|1800799024|376014|366016;","X-Microsoft-Antispam-Message-Info":"=?utf-8?q?YGQvfHO16XSGP+ohkG1SQdkT+Zcu?=\n\t=?utf-8?q?zqbyDZKr8pajGxZKcVMSTvK4FB4O7Y0uuLp50I9zy6lP2lDTFegj29En?=\n\t=?utf-8?q?LBDr1OU+e2RZ0LIdzVnIng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zhR/FoquUKlVKrSnXIjqb+RsHwN1FwhP1gN6ej?=\n\t=?utf-8?q?2D1G/FWBhE73Cvhy545tPIKM+QvZRi+EvIhCvpMdrnWD/fDMA9yl2VOB?=\n\t=?utf-8?q?3fwv4P/eRi+qGVSgbYdiDXH5N4LGZHTNfPQeumrJeJZ/KTFTsO2xr3p7?=\n\t=?utf-8?q?1XFQNiQ07gLnEpk6kUDF3+sTj2O9ckM6SagK2HHZ/YjpTxeNXzoqdeRb?=\n\t=?utf-8?q?kimeOKc5oLhpXyJETPEiavZHJ9YTLibRMXfYkaAfec2yS5Ae3WHl+Ryd?=\n\t=?utf-8?q?iTOEVUjgqbm3ql1mZuWihVfc01B3obIc7OKE1F2AMqi+zEkjRKDc2TIW?=\n\t=?utf-8?q?4awWgsnP6g+zPg9Y/1N49scTk5uGsPq+4lUVdHYZ9i5mANduaXMcEWvC?=\n\t=?utf-8?q?TAH2wmQrdDLN/Fj8kmfsL4cKiD+zAcjktPYeEDQilSlGEX2P6vQPSzEg?=\n\t=?utf-8?q?z2u3hMAnH5gaCHY=3D?=","X-Forefront-Antispam-Report":"CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;\n\tIPV:NLI; SFV:NSPM; H:AM9PR04MB8147.eurprd04.prod.outlook.com; PTR:;\n\tCAT:NONE; \n\tSFS:(13230040)(1800799024)(376014)(366016); DIR:OUT; SFP:1101; ","X-MS-Exchange-AntiSpam-MessageData-ChunkCount":"1","X-MS-Exchange-AntiSpam-MessageData-0":"=?utf-8?q?oE3NH1pDDhSijIEYfODJHHAH1?=\n\t=?utf-8?q?16DU2+SdHjzrqSXLG3rA+nn8vicBbSdpveQylF6DCRz1KNVTI7yXVeP1?=\n\t=?utf-8?q?2UqxDI9IT9GtNo9EG4gxnqRR10wdxY3QqQwF6x9kxsuR2OLinQKhMhe/?=\n\t=?utf-8?q?Ev2BeOeXSzhyha3tzUX5AcDSbpmfIWOcHw3lbSeFaNwWS2+M3iiNnNdK?=\n\t=?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qZZwmxh1y1h3AglmiYYj4aADZH7IZcPXK8oUk4UJEw2KoA0i1iF?=\n\t=?utf-8?q?RA5qPh/ttRNXqj2w9xHRwl1iU/qgCfwRTuJudP33jHUqNvTRw7vbR/fF?=\n\t=?utf-8?q?3qhowAZX6QeQ8mG8DAAtitF+W70rfBkmTPaPXySBlPdcdYHe1PBazVGO?=\n\t=?utf-8?q?RUz/3k23l+CjjliU6Umc71TXF3dlvB7hscg3l+TQyYx361nnj1Rvi3Hk?=\n\t=?utf-8?q?xMtgsurjTIl8Dde/YZoTWS005mkqNeaO51oejIku38i8AOgBqac7nYSG?=\n\t=?utf-8?q?Rv1QQY3ZxsUVE+1yBVixgPoe9c0oMQ5TN1d1xM2vUDNcB3/06mIG2wBj?=\n\t=?utf-8?q?CntbZDudmzrdGlzqIcnRp0Mf433Dw5AB2N7v1H//ml8ntxNnHcOfxWD4?=\n\t=?utf-8?q?SBNXNCIoFULkJ4m2upgvEnhYza273RsDij0lTrbyGjDIAO+km8OFsCFe?=\n\t=?utf-8?q?G06zpF6exqzs0tVjAh794k5ykT9FlSqvDbjPoVV820cRRwl1s19ar4R9?=\n\t=?utf-8?q?Mv9OTpGSlVshJXehGMDarIctVbI0pQDqrvcrWpDcxDcpgoMCjW8vOMxX?=\n\t=?utf-8?q?If8P+LmTRkTYGXAnVa+ENyklPuwAw=3D=3D?=","X-OriginatorOrg":"nxp.com","X-MS-Exchange-CrossTenant-Network-Message-Id":"b90249d4-ef28-47c7-e579-08dd9c7e7baa","X-MS-Exchange-CrossTenant-AuthSource":"AM9PR04MB8147.eurprd04.prod.outlook.com","X-MS-Exchange-CrossTenant-AuthAs":"Internal","X-MS-Exchange-CrossTenant-OriginalArrivalTime":"26 May 2025 17:55:21.2386\n\t(UTC)","X-MS-Exchange-CrossTenant-FromEntityHeader":"Hosted","X-MS-Exchange-CrossTenant-Id":"686ea1d3-bc2b-4c6f-a92c-d99c5c301635","X-MS-Exchange-CrossTenant-MailboxType":"HOSTED","X-MS-Exchange-CrossTenant-UserPrincipalName":"2cSE5Kdp97jFxwj3kZq7qim+Y/FC0WpQzC8gtbUX6pHqyNl2u1VfFyfn6CbpYMYVQG4xGzucbdkiJQ/Pd6oOOFz89TaZQOWsgWuzLtW9x9c=","X-MS-Exchange-Transport-CrossTenantHeadersStamped":"VI2PR04MB11172","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>"}},{"id":34358,"web_url":"https://patchwork.libcamera.org/comment/34358/","msgid":"<20250527121801.GO12492@pendragon.ideasonboard.com>","date":"2025-05-27T12:18:01","subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hello Julien,\n\nOn Mon, May 26, 2025 at 07:55:19PM +0200, Julien Vuillaumier wrote:\n> On 22/05/2025 01:04, Laurent Pinchart wrote:\n> > On Mon, May 19, 2025 at 02:23:52PM +0200, Julien Vuillaumier wrote:\n> >> When a child process is started from Process::start(), the file\n> >> descriptors inherited from the parent process are closed, except\n> >> the ones explicitly listed in the fds[] argument.\n> >>\n> >> One issue is that the file descriptors for stdin, stdout and stderr\n> >> being closed, the subsequent file descriptors created by the child\n> >> process will reuse the values 0, 1 and 2 that are now available.\n> >> Thus, usage of printf(), assert() or alike may direct its output\n> >> to the new resource bound to one of these reused file descriptors.\n> >> The other issue is that the child process can no longer log on\n> >> the console because stderr has been closed.\n> >>\n> >> To address the 2 issues, Process:start() is amended as below:\n> >> - Child process inherits from parent's stderr fd in order to share\n> >> the same logging descriptor\n> >> - Child process stdin, stdout and stderr fds are bound to /dev/null\n> >> if not inherited from parent. That is to prevent those descriptors\n> >> to be reused for any other resource, that could be corrupted by\n> >> the presence of printf(), assert() or alike.\n> >>\n> >> Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>\n> >> ---\n> >>   src/libcamera/process.cpp | 16 +++++++++++++++-\n> >>   1 file changed, 15 insertions(+), 1 deletion(-)\n> >>\n> >> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n> >> index 68fad327..fa92f58c 100644\n> >> --- a/src/libcamera/process.cpp\n> >> +++ b/src/libcamera/process.cpp\n> >> @@ -259,7 +259,21 @@ int Process::start(const std::string &path,\n> >>                if (isolate())\n> >>                        _exit(EXIT_FAILURE);\n> >>\n> >> -             closeAllFdsExcept(fds);\n> >> +             std::vector<int> v(fds);\n> >> +             v.push_back(STDERR_FILENO);\n> > \n> > There's still a risk that STDERR_FILENO refers to a different file than\n> > stderr. Could you test this patch (with an IPA module running in\n> > isolated mode) with pipewire ? If that doesn't cause any issue I'll feel\n> > better accepting the risk.\n> \n> I tested libcamera (v0.5.0 tag) running with vimc isolated IPA, operated \n> from PipeWire / WirePlumber - both components are run as systemd \n> services. By default, systemd explicitly binds the standard descriptors \n> of the services per mapping below:\n> - STDIN_FILENO: /dev/null\n> - STDOUT_FILENO: journal socket\n> - STDERR_FILENO: same as STDOUT\n> But this mapping could be changed in the respective service \n> configuration files, where standard descriptors may also be associated \n> to a dedicated file, kmsg, a socket etc - see `Logging and Standard \n> Input/Output` in [1].\n> \n> Thus, when libcamera is invoked from either PipeWire or WirePlumber \n> service, the STDIN/STDOUT/STERR descriptors are already allocated and \n> bound to some descriptors relevant for the standard input/output which \n> is presumably safe. I suppose that any other configuration (standard \n> descriptors not allocated to standard IO) is unsafe.\n> \n> I have verified vimc IPA in isolated mode: this change enables the \n> isolated IPA to output its log in the PipeWire unit journal \n> (`journalctrl --user -u pipewire -f`). The journal daemon socket \n> descriptor mapped onto PipeWire STDERR_FILENO is inherited by the \n> isolated IPA as expected.\n> \n> Side note: using isolated IPA with PW requires commenting out the line \n> `RestrictNamespaces=yes` in the pipewire.service file [2].\n> No such issue exists in WirePlumber.\n> \n> [1] https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html\n> [2] https://github.com/PipeWire/pipewire/blob/master/src/daemon/systemd/user/pipewire.service.in#L23\n\nThank you for the thorough testing. This alleviates my worries. With the\nsmall change requested by Barnabás (switching from exit() to _exit()), I\nthink we're good to go.\n\n> >> +             closeAllFdsExcept(v);\n> >> +\n> >> +             const auto tryDevNullLowestFd = [](int expected, int oflag) {\n> >> +                     int fd = open(\"/dev/null\", oflag);\n> >> +                     if (fd < 0)\n> >> +                             exit(EXIT_FAILURE);\n> >> +                     if (fd != expected)\n> >> +                             close(fd);\n> >> +             };\n> >> +\n> >> +             tryDevNullLowestFd(STDIN_FILENO, O_RDONLY);\n> >> +             tryDevNullLowestFd(STDOUT_FILENO, O_WRONLY);\n> >> +             tryDevNullLowestFd(STDERR_FILENO, O_WRONLY);\n> >>\n> >>                const char *file = utils::secure_getenv(\"LIBCAMERA_LOG_FILE\");\n> >>                if (file && strcmp(file, \"syslog\"))","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 A28D7C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 May 2025 12:19:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0DAF168DA0;\n\tTue, 27 May 2025 14:19:25 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 588B968D94\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 May 2025 14:19:23 +0200 (CEST)","from pendragon.ideasonboard.com (unknown [145.15.244.208])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E1622B3;\n\tTue, 27 May 2025 14:18:57 +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=\"Q4G9ULIj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1748348337;\n\tbh=GrCZsmutdB3oJu+bXRVBbNHN0NQ1lBT/Fs84pjNAGlg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Q4G9ULIjdVs5LB2deJ0Vp9s1E/8yfOL9eqprR3IgjaE/lgOP8cuNk26q+PbpGW+jc\n\t7j6DpWl35geFL902hTw/nQG2QjMxfrsmEsG2a4VQS4VbqeDgNr/MvFBIP5eyZxIRYQ\n\tAc6VhtjzAQopF/Q9xYEVItDJNE9remMcPqJ5ZUao=","Date":"Tue, 27 May 2025 14:18:01 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Julien Vuillaumier <julien.vuillaumier@nxp.com>","Cc":"libcamera-devel@lists.libcamera.org, barnabas.pocze@ideasonboard.com","Subject":"Re: [PATCH v3 1/1] libcamera: process: Pass stderr and reserve stdin\n\tand stdout fds","Message-ID":"<20250527121801.GO12492@pendragon.ideasonboard.com>","References":"<20250519122352.1675360-1-julien.vuillaumier@nxp.com>\n\t<20250519122352.1675360-2-julien.vuillaumier@nxp.com>\n\t<20250521230440.GM12514@pendragon.ideasonboard.com>\n\t<d69af22a-f7f8-464a-8044-707928499a52@nxp.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<d69af22a-f7f8-464a-8044-707928499a52@nxp.com>","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>"}}]