{"id":11940,"url":"https://patchwork.libcamera.org/api/patches/11940/?format=json","web_url":"https://patchwork.libcamera.org/patch/11940/","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":"<20210415083843.3399502-4-hiroh@chromium.org>","date":"2021-04-15T08:38:37","name":"[libcamera-devel,RFC,04/10] libcamera: Process: Manage pipe fds by ScopedFD","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"b0ba7ad9ec2810019fb819c84191e76350f2a75c","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11940/mbox/","series":[{"id":1933,"url":"https://patchwork.libcamera.org/api/series/1933/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1933","date":"2021-04-15T08:38:35","name":null,"version":1,"mbox":"https://patchwork.libcamera.org/series/1933/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11940/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11940/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 E1844BD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 15 Apr 2021 08:38:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A09D568817;\n\tThu, 15 Apr 2021 10:38:57 +0200 (CEST)","from mail-pg1-x534.google.com (mail-pg1-x534.google.com\n\t[IPv6:2607:f8b0:4864:20::534])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E89DD68818\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Apr 2021 10:38:54 +0200 (CEST)","by mail-pg1-x534.google.com with SMTP id p2so955693pgh.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Apr 2021 01:38:54 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:84f5:7981:dfbe:8f02])\n\tby smtp.gmail.com with ESMTPSA id\n\t205sm1520258pfc.201.2021.04.15.01.38.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 15 Apr 2021 01:38:52 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"bZ7DyiSv\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=GwHyTdrZ7Hgaje7MCYsALSU4WjeRmENQdCEzaaNFQZs=;\n\tb=bZ7DyiSvPw8wr4pSwBP073Wj/UXM62nDUZWebkwRzQaNKSAQxrlJRexlw5H9UOlWsF\n\tSK5M4aiS56CgGzr1Dg0NZvxjqzBkadehZp5iHEl1zcc5iNKE0z2a7xzkqDmGYeZ5mpiO\n\tXdvblQrRQV2Shixg1KD0Bb1zhZCIuNhw8fJtQ=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=GwHyTdrZ7Hgaje7MCYsALSU4WjeRmENQdCEzaaNFQZs=;\n\tb=l5J/vq5Sb1rBRZRaQ9sU8bf8IP18ycJPRjXvmLdB3EZuvcF7Mb5Kez2yGgpbFt6+cG\n\t3j4ef2edsrUFB+7yvioVmJTTi0npWGyaLL7KI2emkvHnSRXIvElYb0Fwfdn6Ih2Nfej4\n\tZsZwQdD7EkDDu0X8pd/oG3FGQk/WHbdDGdBhmRXbY3ptvkM6eUii4i4rRODzseLFNRci\n\tUTIDmfHHKcCj8g6veUNkf40hN7RdPIF3t3ozaPZlGMrEGk5Ga5ncIRjN0fe+6e2yVCmg\n\tMPpeNu+qEiTEMvxLBg9HEHYJXYUp1wkk2Uug+qF4DwGW6GbZiRfq7hmzTroBP326cwhh\n\t0z+w==","X-Gm-Message-State":"AOAM531a8Wv+Oq/zUhjtlqcFKInOJ5XGvNnDhS1X8SAxQ7CC10ptoL8G\n\tncUNIhIiJmL1zP89KOfiSjT+ftJfgailQw==","X-Google-Smtp-Source":"ABdhPJy0k2INyRxVvAwkU0ng+5HBLInxvF3ZbU26EqH/wK36ckcabggQvQYTbE+oowlX7mqvZEs0Sg==","X-Received":"by 2002:a62:d417:0:b029:258:4e8a:ad06 with SMTP id\n\ta23-20020a62d4170000b02902584e8aad06mr721066pfh.68.1618475933243; \n\tThu, 15 Apr 2021 01:38:53 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 15 Apr 2021 17:38:37 +0900","Message-Id":"<20210415083843.3399502-4-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.368.gbe11c130af-goog","In-Reply-To":"<20210415083843.3399502-1-hiroh@chromium.org>","References":"<20210415083843.3399502-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [RFC PATCH 04/10] libcamera: Process: Manage pipe\n\tfds by ScopedFD","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Process owns the file descriptors for pipe. They should be\nmanaged by ScopedFDs to avoid the leakage.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/internal/process.h |  4 +++-\n src/libcamera/process.cpp            | 16 ++++++++++------\n 2 files changed, 13 insertions(+), 7 deletions(-)","diff":"diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h\nindex 254cda85..b3bb24df 100644\n--- a/include/libcamera/internal/process.h\n+++ b/include/libcamera/internal/process.h\n@@ -11,6 +11,7 @@\n #include <string>\n #include <vector>\n \n+#include <libcamera/scoped_file_descriptor.h>\n #include <libcamera/signal.h>\n \n namespace libcamera {\n@@ -75,8 +76,9 @@ private:\n \tstd::list<Process *> processes_;\n \n \tstruct sigaction oldsa_;\n+\n \tEventNotifier *sigEvent_;\n-\tint pipe_[2];\n+\tScopedFD pipe_[2];\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\nindex 40a434a6..bb51d73b 100644\n--- a/src/libcamera/process.cpp\n+++ b/src/libcamera/process.cpp\n@@ -69,7 +69,7 @@ void sigact(int signal, siginfo_t *info, void *ucontext)\n void ProcessManager::sighandler([[maybe_unused]] EventNotifier *notifier)\n {\n \tchar data;\n-\tssize_t ret = read(pipe_[0], &data, sizeof(data));\n+\tssize_t ret = read(pipe_[0].get(), &data, sizeof(data));\n \tif (ret < 0) {\n \t\tLOG(Process, Error)\n \t\t\t<< \"Failed to read byte from signal handler pipe\";\n@@ -129,10 +129,15 @@ ProcessManager::ProcessManager()\n \n \tsigaction(SIGCHLD, &sa, NULL);\n \n-\tif (pipe2(pipe_, O_CLOEXEC | O_DIRECT | O_NONBLOCK))\n+\tint pipe[2];\n+\tif (pipe2(pipe, O_CLOEXEC | O_DIRECT | O_NONBLOCK))\n \t\tLOG(Process, Fatal)\n \t\t\t<< \"Failed to initialize pipe for signal handling\";\n-\tsigEvent_ = new EventNotifier(pipe_[0], EventNotifier::Read);\n+\n+\tpipe_[0] = ScopedFD(pipe[0]);\n+\tpipe_[1] = ScopedFD(pipe[1]);\n+\n+\tsigEvent_ = new EventNotifier(pipe_[0].get(), EventNotifier::Read);\n \tsigEvent_->activated.connect(this, &ProcessManager::sighandler);\n \n \tself_ = this;\n@@ -141,9 +146,8 @@ ProcessManager::ProcessManager()\n ProcessManager::~ProcessManager()\n {\n \tsigaction(SIGCHLD, &oldsa_, NULL);\n+\n \tdelete sigEvent_;\n-\tclose(pipe_[0]);\n-\tclose(pipe_[1]);\n \n \tself_ = nullptr;\n }\n@@ -170,7 +174,7 @@ ProcessManager *ProcessManager::instance()\n  */\n int ProcessManager::writePipe() const\n {\n-\treturn pipe_[1];\n+\treturn pipe_[1].get();\n }\n \n /**\n","prefixes":["libcamera-devel","RFC","04/10"]}