[{"id":26750,"web_url":"https://patchwork.libcamera.org/comment/26750/","msgid":"<7894dba1-d4eb-3de3-0203-a24aae813204@ideasonboard.com>","date":"2023-03-27T04:07:02","subject":"Re: [libcamera-devel] [PATCH] libcamera: Open files with O_CLOEXEC","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Laurent,\n\nThank you for the patch\n\nOn 3/26/23 3:31 PM, Laurent Pinchart via libcamera-devel wrote:\n> Files opened internally in libcamera without the O_CLOEXEC file will\n> remain open upon a call to one of the exec(3) functions. As exec()\n> doesn't destroy local or global objects, this can lead to various side\n> effects. Avoid this by opening file descriptors with O_CLOEXEC for all\n> internal files.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> ---\n>   src/ipa/vimc/vimc.cpp                            | 2 +-\n>   src/libcamera/base/file.cpp                      | 5 ++++-\n>   src/libcamera/media_device.cpp                   | 2 +-\n>   src/libcamera/pipeline/raspberrypi/dma_heaps.cpp | 2 +-\n>   4 files changed, 7 insertions(+), 4 deletions(-)\n>\n> diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp\n> index d5fabaf13ec6..2c255778990a 100644\n> --- a/src/ipa/vimc/vimc.cpp\n> +++ b/src/ipa/vimc/vimc.cpp\n> @@ -168,7 +168,7 @@ void IPAVimc::initTrace()\n>   \tif (ret)\n>   \t\treturn;\n>   \n> -\tret = ::open(ipa::vimc::VimcIPAFIFOPath.c_str(), O_WRONLY);\n> +\tret = ::open(ipa::vimc::VimcIPAFIFOPath.c_str(), O_WRONLY | O_CLOEXEC);\n>   \tif (ret < 0) {\n>   \t\tret = errno;\n>   \t\tLOG(IPAVimc, Error) << \"Failed to open vimc IPA test FIFO: \"\n> diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp\n> index fb3e276d6ccd..d1ab1aa57462 100644\n> --- a/src/libcamera/base/file.cpp\n> +++ b/src/libcamera/base/file.cpp\n> @@ -163,6 +163,9 @@ bool File::exists() const\n>    * attempt to create the file with initial permissions set to 0666 (modified by\n>    * the process' umask).\n>    *\n> + * The file is opened with the O_CLOEXEC flag, and will be closed automatically\n> + * when a new binary is executed with one of the exec(3) functions.\n> + *\n>    * The error() status is updated.\n>    *\n>    * \\return True on success, false otherwise\n> @@ -178,7 +181,7 @@ bool File::open(File::OpenMode mode)\n>   \tif (mode & OpenModeFlag::WriteOnly)\n>   \t\tflags |= O_CREAT;\n>   \n> -\tfd_ = UniqueFD(::open(name_.c_str(), flags, 0666));\n> +\tfd_ = UniqueFD(::open(name_.c_str(), flags | O_CLOEXEC, 0666));\n>   \tif (!fd_.isValid()) {\n>   \t\terror_ = -errno;\n>   \t\treturn false;\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 52c8e66e9e99..2949816b4a64 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -477,7 +477,7 @@ int MediaDevice::open()\n>   \t\treturn -EBUSY;\n>   \t}\n>   \n> -\tfd_ = UniqueFD(::open(deviceNode_.c_str(), O_RDWR));\n> +\tfd_ = UniqueFD(::open(deviceNode_.c_str(), O_RDWR | O_CLOEXEC));\n>   \tif (!fd_.isValid()) {\n>   \t\tint ret = -errno;\n>   \t\tLOG(MediaDevice, Error)\n> diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> index 6b644406c90f..317b1fc17161 100644\n> --- a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> @@ -37,7 +37,7 @@ namespace RPi {\n>   DmaHeap::DmaHeap()\n>   {\n>   \tfor (const char *name : heapNames) {\n> -\t\tint ret = ::open(name, O_RDWR, 0);\n> +\t\tint ret = ::open(name, O_RDWR | O_CLOEXEC, 0);\n>   \t\tif (ret < 0) {\n>   \t\t\tret = errno;\n>   \t\t\tLOG(RPI, Debug) << \"Failed to open \" << name << \": \"","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 DE307C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Mar 2023 04:07:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1A2C262722;\n\tMon, 27 Mar 2023 06:07:16 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B48BC61ECB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 06:07:09 +0200 (CEST)","from [IPV6:2401:4900:1c80:ef16:b66d:835:516e:8fe3] (unknown\n\t[IPv6:2401:4900:1c80:ef16:b66d:835:516e:8fe3])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 650626E1;\n\tMon, 27 Mar 2023 06:07:08 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679890036;\n\tbh=SPs+DY4wEZSKs8XMZrJLar4q1sGaOfgSW+0IyKeN8t4=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=sDld7jB384FbcikcMhuUBoHivUWJTeWs0hhWMauAI8rGigoVWtX2YBMhzi7iIRU1R\n\tOFlwly1znmJeIEwrA9C1Hb0wteIB6WaX6vIjAoqLf0Y1NmQeYzhyOLoOU7W3pa49Rj\n\txoZumg3soPgEkWPNBIrMbfYZzWSAzEWRrqwzR7dixHRJUmJRQk514tMqc+Egc0lAnY\n\tDS/WkLnKJnTZB9LQxuUx9iNUAfh9rtcbQUtvMQFw548CBbus+pofWPpBecuTKfTv+T\n\tsjD9by7BgAorq9Bxp6hWf7lDmlYh8TvxMx3MKM2/YW48kVzgnMa0SgVHabCs9FSjHN\n\tmbnp8ZE0kk87w==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1679890029;\n\tbh=SPs+DY4wEZSKs8XMZrJLar4q1sGaOfgSW+0IyKeN8t4=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=lv/ZyBQB3ZZ33mn4m8M7lQ75fs1DxjhZ+lIc+AmhQ44Wk7oq7xj6AD8wC3J4d3BJV\n\tF90WBIj1h0n8qgSS/FaRCRSIyBQNS6KTJncOcXOuQ6SNG79BBN+bHRr5y1OOmI8knC\n\tUq96OzhSVUVZUNpMPJi3268vGwB2RqxgOJkCp1l0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"lv/ZyBQB\"; dkim-atps=neutral","Message-ID":"<7894dba1-d4eb-3de3-0203-a24aae813204@ideasonboard.com>","Date":"Mon, 27 Mar 2023 09:37:02 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101\n\tThunderbird/102.7.1","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20230326100155.7532-1-laurent.pinchart@ideasonboard.com>","Content-Language":"en-US","In-Reply-To":"<20230326100155.7532-1-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Open files with O_CLOEXEC","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>","From":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26777,"web_url":"https://patchwork.libcamera.org/comment/26777/","msgid":"<167993023714.765114.4158558439636994201@Monstersaurus>","date":"2023-03-27T15:17:17","subject":"Re: [libcamera-devel] [PATCH] libcamera: Open files with O_CLOEXEC","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart via libcamera-devel (2023-03-26 11:01:55)\n> Files opened internally in libcamera without the O_CLOEXEC file will\n> remain open upon a call to one of the exec(3) functions. As exec()\n> doesn't destroy local or global objects, this can lead to various side\n> effects. Avoid this by opening file descriptors with O_CLOEXEC for all\n> internal files.\n\nThis seems more prolific than it should be.\n\nIt makes me think we should enforce it with a helper instead but I'm not\nsure if that's much different to adding a checkstyle rule!?\n\nAnyway, this seems reasonable otherwise.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n--\nKieran\n\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/ipa/vimc/vimc.cpp                            | 2 +-\n>  src/libcamera/base/file.cpp                      | 5 ++++-\n>  src/libcamera/media_device.cpp                   | 2 +-\n>  src/libcamera/pipeline/raspberrypi/dma_heaps.cpp | 2 +-\n>  4 files changed, 7 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp\n> index d5fabaf13ec6..2c255778990a 100644\n> --- a/src/ipa/vimc/vimc.cpp\n> +++ b/src/ipa/vimc/vimc.cpp\n> @@ -168,7 +168,7 @@ void IPAVimc::initTrace()\n>         if (ret)\n>                 return;\n>  \n> -       ret = ::open(ipa::vimc::VimcIPAFIFOPath.c_str(), O_WRONLY);\n> +       ret = ::open(ipa::vimc::VimcIPAFIFOPath.c_str(), O_WRONLY | O_CLOEXEC);\n>         if (ret < 0) {\n>                 ret = errno;\n>                 LOG(IPAVimc, Error) << \"Failed to open vimc IPA test FIFO: \"\n> diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp\n> index fb3e276d6ccd..d1ab1aa57462 100644\n> --- a/src/libcamera/base/file.cpp\n> +++ b/src/libcamera/base/file.cpp\n> @@ -163,6 +163,9 @@ bool File::exists() const\n>   * attempt to create the file with initial permissions set to 0666 (modified by\n>   * the process' umask).\n>   *\n> + * The file is opened with the O_CLOEXEC flag, and will be closed automatically\n> + * when a new binary is executed with one of the exec(3) functions.\n> + *\n>   * The error() status is updated.\n>   *\n>   * \\return True on success, false otherwise\n> @@ -178,7 +181,7 @@ bool File::open(File::OpenMode mode)\n>         if (mode & OpenModeFlag::WriteOnly)\n>                 flags |= O_CREAT;\n>  \n> -       fd_ = UniqueFD(::open(name_.c_str(), flags, 0666));\n> +       fd_ = UniqueFD(::open(name_.c_str(), flags | O_CLOEXEC, 0666));\n>         if (!fd_.isValid()) {\n>                 error_ = -errno;\n>                 return false;\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 52c8e66e9e99..2949816b4a64 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -477,7 +477,7 @@ int MediaDevice::open()\n>                 return -EBUSY;\n>         }\n>  \n> -       fd_ = UniqueFD(::open(deviceNode_.c_str(), O_RDWR));\n> +       fd_ = UniqueFD(::open(deviceNode_.c_str(), O_RDWR | O_CLOEXEC));\n>         if (!fd_.isValid()) {\n>                 int ret = -errno;\n>                 LOG(MediaDevice, Error)\n> diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> index 6b644406c90f..317b1fc17161 100644\n> --- a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> @@ -37,7 +37,7 @@ namespace RPi {\n>  DmaHeap::DmaHeap()\n>  {\n>         for (const char *name : heapNames) {\n> -               int ret = ::open(name, O_RDWR, 0);\n> +               int ret = ::open(name, O_RDWR | O_CLOEXEC, 0);\n>                 if (ret < 0) {\n>                         ret = errno;\n>                         LOG(RPI, Debug) << \"Failed to open \" << name << \": \"\n> -- \n> Regards,\n> \n> Laurent Pinchart\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 AC139BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Mar 2023 15:17:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ADCA662722;\n\tMon, 27 Mar 2023 17:17: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 51883626D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 17:17:20 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D936BAEC;\n\tMon, 27 Mar 2023 17:17:19 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679930241;\n\tbh=+w3Yym4N/vj7TYQlMzTabYupYPVizovw0QBZ05xrEPQ=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=zTDnv5I7s9x20d8RGChZ4PNJPhvn4PLV9Fc0chXeRW3Cn8GMLgrmJghve/jLO3xEj\n\tIWxAgVFfBcQV4J/ve9WPHbt0POhaqY3X8KQleS1Uy0LNYDfIXE7oac/xSjwLfZ5UGu\n\tadoSWopEWviO8tAfHJKmog9Le/uwwYfC1CfNapOPgfl4P2AQ92+Fz+bO4SLE0nvse/\n\tVKlnD6WsK5alc1kEwMoVfjEGY5XTs+yUrFJQVC689im0PaTrcjhTy5TM4oPdQ8LZM0\n\tKkU7OGrdqqmMzjZ5xz7ZvY7emanKxrRUXrkcq6IBHR7pCCx7qp9WOBtFMMCfdUuwND\n\tnhZQoCJgmvYMg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1679930240;\n\tbh=+w3Yym4N/vj7TYQlMzTabYupYPVizovw0QBZ05xrEPQ=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=Go0PJ62zzAhkS8qikubvfCKHcBFLsf2Lt6HFqbHm9LlD8xSkjLHopeuai3XtkAkb2\n\tTjnivrgf+n3oOI5Un40bbkgJsBvU//doIsCqvaERmYELAjHI8pfL3Ev2UnvcTfXIHt\n\tcxi9Ry1BtSaoxazaaF5DfARTD5NnPxI/bieuDL14="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Go0PJ62z\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230326100155.7532-1-laurent.pinchart@ideasonboard.com>","References":"<20230326100155.7532-1-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 27 Mar 2023 16:17:17 +0100","Message-ID":"<167993023714.765114.4158558439636994201@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Open files with O_CLOEXEC","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26849,"web_url":"https://patchwork.libcamera.org/comment/26849/","msgid":"<20230405041941.GN9915@pendragon.ideasonboard.com>","date":"2023-04-05T04:19:41","subject":"Re: [libcamera-devel] [PATCH] libcamera: Open files with O_CLOEXEC","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Mon, Mar 27, 2023 at 04:17:17PM +0100, Kieran Bingham wrote:\n> Quoting Laurent Pinchart via libcamera-devel (2023-03-26 11:01:55)\n> > Files opened internally in libcamera without the O_CLOEXEC file will\n> > remain open upon a call to one of the exec(3) functions. As exec()\n> > doesn't destroy local or global objects, this can lead to various side\n> > effects. Avoid this by opening file descriptors with O_CLOEXEC for all\n> > internal files.\n> \n> This seems more prolific than it should be.\n> \n> It makes me think we should enforce it with a helper instead but I'm not\n> sure if that's much different to adding a checkstyle rule!?\n\nWider usage of the File class may help.\n\n> Anyway, this seems reasonable otherwise.\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/ipa/vimc/vimc.cpp                            | 2 +-\n> >  src/libcamera/base/file.cpp                      | 5 ++++-\n> >  src/libcamera/media_device.cpp                   | 2 +-\n> >  src/libcamera/pipeline/raspberrypi/dma_heaps.cpp | 2 +-\n> >  4 files changed, 7 insertions(+), 4 deletions(-)\n> > \n> > diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp\n> > index d5fabaf13ec6..2c255778990a 100644\n> > --- a/src/ipa/vimc/vimc.cpp\n> > +++ b/src/ipa/vimc/vimc.cpp\n> > @@ -168,7 +168,7 @@ void IPAVimc::initTrace()\n> >         if (ret)\n> >                 return;\n> >  \n> > -       ret = ::open(ipa::vimc::VimcIPAFIFOPath.c_str(), O_WRONLY);\n> > +       ret = ::open(ipa::vimc::VimcIPAFIFOPath.c_str(), O_WRONLY | O_CLOEXEC);\n> >         if (ret < 0) {\n> >                 ret = errno;\n> >                 LOG(IPAVimc, Error) << \"Failed to open vimc IPA test FIFO: \"\n> > diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp\n> > index fb3e276d6ccd..d1ab1aa57462 100644\n> > --- a/src/libcamera/base/file.cpp\n> > +++ b/src/libcamera/base/file.cpp\n> > @@ -163,6 +163,9 @@ bool File::exists() const\n> >   * attempt to create the file with initial permissions set to 0666 (modified by\n> >   * the process' umask).\n> >   *\n> > + * The file is opened with the O_CLOEXEC flag, and will be closed automatically\n> > + * when a new binary is executed with one of the exec(3) functions.\n> > + *\n> >   * The error() status is updated.\n> >   *\n> >   * \\return True on success, false otherwise\n> > @@ -178,7 +181,7 @@ bool File::open(File::OpenMode mode)\n> >         if (mode & OpenModeFlag::WriteOnly)\n> >                 flags |= O_CREAT;\n> >  \n> > -       fd_ = UniqueFD(::open(name_.c_str(), flags, 0666));\n> > +       fd_ = UniqueFD(::open(name_.c_str(), flags | O_CLOEXEC, 0666));\n> >         if (!fd_.isValid()) {\n> >                 error_ = -errno;\n> >                 return false;\n> > diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> > index 52c8e66e9e99..2949816b4a64 100644\n> > --- a/src/libcamera/media_device.cpp\n> > +++ b/src/libcamera/media_device.cpp\n> > @@ -477,7 +477,7 @@ int MediaDevice::open()\n> >                 return -EBUSY;\n> >         }\n> >  \n> > -       fd_ = UniqueFD(::open(deviceNode_.c_str(), O_RDWR));\n> > +       fd_ = UniqueFD(::open(deviceNode_.c_str(), O_RDWR | O_CLOEXEC));\n> >         if (!fd_.isValid()) {\n> >                 int ret = -errno;\n> >                 LOG(MediaDevice, Error)\n> > diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> > index 6b644406c90f..317b1fc17161 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> > @@ -37,7 +37,7 @@ namespace RPi {\n> >  DmaHeap::DmaHeap()\n> >  {\n> >         for (const char *name : heapNames) {\n> > -               int ret = ::open(name, O_RDWR, 0);\n> > +               int ret = ::open(name, O_RDWR | O_CLOEXEC, 0);\n> >                 if (ret < 0) {\n> >                         ret = errno;\n> >                         LOG(RPI, Debug) << \"Failed to open \" << name << \": \"","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 E2B30C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Apr 2023 04:19:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3ED976274B;\n\tWed,  5 Apr 2023 06:19:37 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EF1A61EC2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Apr 2023 06:19:35 +0200 (CEST)","from pendragon.ideasonboard.com (fp76f193f3.tkyc206.ap.nuro.jp\n\t[118.241.147.243])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8CD6F905;\n\tWed,  5 Apr 2023 06:19:33 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680668377;\n\tbh=JqT4sI8/f1pCqkSbULaz0EDU9FwJjwaNkRuhcelgPoQ=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=Z3CGYcbyMbY820ds6plLEWldSYkRIQ/orY+Vzs7apCa5NBhJsuxB+FgLJCW1g2uar\n\tEnzArY4GfSy3tD+Ul4UKtVJZDUt5Z81A8RpG7EONYqg0squBsVK7hbbW6KI56vo2oJ\n\tC/b3nYu+2NAX9qOJXj5zWPPgDSVysCMTLxpnweBA4JoBVdAQjJekuqr5rn0FeAD3yv\n\tVEU/3+Gdw4yjKwDrZ4yHZnfDPbmiR18qAMkUu9a0rLyFvrRxniiMP37Wgiqv/O5bmu\n\td6VIFsZzHxFxW9NvsLgugvKMphZrIAIcRvbGbl+WGYGf/16DKqvEbX4LEsWfXQ7RAw\n\t2z63qeFwP+SFQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1680668374;\n\tbh=JqT4sI8/f1pCqkSbULaz0EDU9FwJjwaNkRuhcelgPoQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=cQVTRq8IzoxvHTSQKx3L0IRpfmngrTx7U7mHyRSeGkhOebtXbBtTIkiYxNcbEN6Jd\n\t8du7Qv/GTWRDj1JKS+1SkTXd1ks1JS6+wv6PtdR+amiOrJN664pEk92D4Jz9nsMzQn\n\tQaRboT2b0ajHyIn7XTPAB0aTxZ+DH3JrcgHB8UpM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"cQVTRq8I\"; dkim-atps=neutral","Date":"Wed, 5 Apr 2023 07:19:41 +0300","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20230405041941.GN9915@pendragon.ideasonboard.com>","References":"<20230326100155.7532-1-laurent.pinchart@ideasonboard.com>\n\t<167993023714.765114.4158558439636994201@Monstersaurus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<167993023714.765114.4158558439636994201@Monstersaurus>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Open files with O_CLOEXEC","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]