From patchwork Tue Nov 30 03:38:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 14866 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 D0385BF415 for ; Tue, 30 Nov 2021 03:39:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8243D605C2; Tue, 30 Nov 2021 04:39:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hoD2yPQs"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 01B4E605A3 for ; Tue, 30 Nov 2021 04:38:54 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 847028F0; Tue, 30 Nov 2021 04:38:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1638243533; bh=87NwiFNikiBaMpO8XkCjgfTu6j+Wt/IonCSqtM951Vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hoD2yPQs/wFUJhk4nqLg7WaJCwbnKttOl0cUEIcBrT4lwCwuofu37q4Ih0VjDy8+m MwduXHzjCLnAeLAMXPVF2QK6n+ZNki7EQ2rZju8fbMWyD6sZD5u29wvChEsfZE3lNC yqEZalBoCbQNIATzPnRdWSQBjJtIX3pHo6NkQGrE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 05:38:10 +0200 Message-Id: <20211130033820.18235-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211130033820.18235-1-laurent.pinchart@ideasonboard.com> References: <20211130033820.18235-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 12/22] libcamera: process: Manage pipe fds by UniqueFD 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" From: Hirokazu Honda Manages the file descriptors owned by Process for pipe by UniqueFDs. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- include/libcamera/internal/process.h | 4 +++- src/libcamera/process.cpp | 16 ++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h index 96748a3676e4..95e67e105a92 100644 --- a/include/libcamera/internal/process.h +++ b/include/libcamera/internal/process.h @@ -12,6 +12,7 @@ #include #include +#include namespace libcamera { @@ -75,8 +76,9 @@ private: std::list processes_; struct sigaction oldsa_; + EventNotifier *sigEvent_; - int pipe_[2]; + UniqueFD pipe_[2]; }; } /* namespace libcamera */ diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index eca1b30039b8..0e6b4e1dde58 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -69,7 +69,7 @@ void sigact(int signal, siginfo_t *info, void *ucontext) void ProcessManager::sighandler() { char data; - ssize_t ret = read(pipe_[0], &data, sizeof(data)); + ssize_t ret = read(pipe_[0].get(), &data, sizeof(data)); if (ret < 0) { LOG(Process, Error) << "Failed to read byte from signal handler pipe"; @@ -129,10 +129,15 @@ ProcessManager::ProcessManager() sigaction(SIGCHLD, &sa, NULL); - if (pipe2(pipe_, O_CLOEXEC | O_DIRECT | O_NONBLOCK)) + int pipe[2]; + if (pipe2(pipe, O_CLOEXEC | O_DIRECT | O_NONBLOCK)) LOG(Process, Fatal) << "Failed to initialize pipe for signal handling"; - sigEvent_ = new EventNotifier(pipe_[0], EventNotifier::Read); + + pipe_[0] = UniqueFD(pipe[0]); + pipe_[1] = UniqueFD(pipe[1]); + + sigEvent_ = new EventNotifier(pipe_[0].get(), EventNotifier::Read); sigEvent_->activated.connect(this, &ProcessManager::sighandler); self_ = this; @@ -141,9 +146,8 @@ ProcessManager::ProcessManager() ProcessManager::~ProcessManager() { sigaction(SIGCHLD, &oldsa_, NULL); + delete sigEvent_; - close(pipe_[0]); - close(pipe_[1]); self_ = nullptr; } @@ -170,7 +174,7 @@ ProcessManager *ProcessManager::instance() */ int ProcessManager::writePipe() const { - return pipe_[1]; + return pipe_[1].get(); } /**