From patchwork Thu Jun 10 07:50:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12537 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 5F275BD78E for ; Thu, 10 Jun 2021 07:50:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1C61868933; Thu, 10 Jun 2021 09:50:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ieiBDvEo"; dkim-atps=neutral Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 72B826892C for ; Thu, 10 Jun 2021 09:50:41 +0200 (CEST) Received: by mail-pl1-x62c.google.com with SMTP id 69so544513plc.5 for ; Thu, 10 Jun 2021 00:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6gV/JFiuoSpUYo+CBAqmrodOMqb0XKCJlOoRjDzT+TQ=; b=ieiBDvEobR8/U+OkkNbcKnKcQkg8ZzxPyfGG5vkg1wdkiy8ZYac2qcnBEIisNulBOC Q6ko3/eqfH8038H1i+bksR/6tqc047SvbKb+BlvUsvij/v0Sbh6i5T+cGLAnOcN7y67e oyqzpN79fvzj1+3zwkmmuKtn8jB2ORZOWdBFY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6gV/JFiuoSpUYo+CBAqmrodOMqb0XKCJlOoRjDzT+TQ=; b=aBY9ZgNpbgELSOqafGTERRm8rusSMrbsbBVbtwHogKWeYMUEhGzjkucGAJq4Ma6VII hxKTe0T8AJsNJyCpXuTbDWIC2RYG4hBjiuk2Ru8UIZQOpDaiv+0pqWZ8Qx2mbx98CG9H mXfFzLV4JraI5K/UWpj3Ka1udrEhItnlsogxPvLJkE/CQk2HSya5NiJ9vBS9r/XMz8Ju 6mzF8yWNJiq3TW0j2U5vNeRSP3nLU7KJ9edxFCpRC69YVr/oeaIkj7hsMB+3tZFw9z5p zqsYZMi9xb/idP5TDpqBw6C7mbfV6y9zAmfrO9Nb9tuS1gOiJYmbzEsy+V+BVfhZL2k6 lZ1w== X-Gm-Message-State: AOAM533VGuf5JfN8QW80T/RXR0+15zKAPYyD0byMqM1GJE6oRr6+OWMi /EiUj1nV9CZnpLuL29rRX39pWURMoEVong== X-Google-Smtp-Source: ABdhPJx9T2puFhKU15M3drUUYLTjnfXQWkrcYebYMSmJdk7F9ML7fbQyslMgvnhE+BZtIYU5EvjmZw== X-Received: by 2002:a17:902:d64e:b029:ef:8b85:d299 with SMTP id y14-20020a170902d64eb02900ef8b85d299mr3713709plh.27.1623311439821; Thu, 10 Jun 2021 00:50:39 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:98e0:b356:1c8a:25d4]) by smtp.gmail.com with ESMTPSA id d66sm1565161pfa.32.2021.06.10.00.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 00:50:39 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 10 Jun 2021 16:50:21 +0900 Message-Id: <20210610075027.523672-5-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog In-Reply-To: <20210610075027.523672-1-hiroh@chromium.org> References: <20210610075027.523672-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/10] libcamera: Process: Manage pipe fds by ScopedFD 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" Manages the file descriptors owned by Process for pipe by ScopedFDs. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- 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 254cda85..027bb7da 100644 --- a/include/libcamera/internal/process.h +++ b/include/libcamera/internal/process.h @@ -11,6 +11,7 @@ #include #include +#include #include namespace libcamera { @@ -75,8 +76,9 @@ private: std::list processes_; struct sigaction oldsa_; + EventNotifier *sigEvent_; - int pipe_[2]; + ScopedFD pipe_[2]; }; } /* namespace libcamera */ diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index 40a434a6..bb51d73b 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([[maybe_unused]] EventNotifier *notifier) { 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] = ScopedFD(pipe[0]); + pipe_[1] = ScopedFD(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(); } /**