From patchwork Thu Apr 24 11:21:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23245 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 A8A4DC331E for ; Thu, 24 Apr 2025 11:22:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0425368ADC; Thu, 24 Apr 2025 13:22:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MyJ9SB/k"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 98B6168AC5 for ; Thu, 24 Apr 2025 13:22:07 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8480F1230; Thu, 24 Apr 2025 13:22:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745493725; bh=fGC17eG1S/Jqp91DikygXMfnrbPJeAFxslQBqhJeatE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MyJ9SB/ksKBWltDXpDa5GO/SaKqvqtwFPGYG35q3Grw2vZvI1zCa0X6Oo6XHBPTO4 Pl3M7OQxv40Quqzv9UWm5gd3+ldcS2pQYwoGsFQdCwhMmPPtS/S1JBfxkUSyaP9TA+ xRXWwVInkFPa49rH9TjraFY0Rw3UxN9sDoxwjQ+o= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [RFC PATCH v4 3/9] libcamera: process: Use `pid_` member to decide if running Date: Thu, 24 Apr 2025 13:21:56 +0200 Message-ID: <20250424112203.445351-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424112203.445351-1-barnabas.pocze@ideasonboard.com> References: <20250424112203.445351-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 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" Instead of using a separate member variable, use `pid_ > 0` to determine if the process is still running. Previously the value of `pid_` was not reset to -1 when the process terminated, but since it is only meaningful while the process is running, reset it to -1 in `Process::died()`. Neither `pid_` nor `running_` are exposed, so this change has no effect on the public interface or observable behaviour. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/process.h | 1 - src/libcamera/process.cpp | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h index 6c34aef2f..891e78947 100644 --- a/include/libcamera/internal/process.h +++ b/include/libcamera/internal/process.h @@ -50,7 +50,6 @@ private: void died(int wstatus); pid_t pid_; - bool running_; enum ExitStatus exitStatus_; int exitCode_; diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index 0990b4bdd..c22c9af5d 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -208,7 +208,7 @@ const struct sigaction &ProcessManager::oldsa() const */ Process::Process() - : pid_(-1), running_(false), exitStatus_(NotExited), exitCode_(0) + : pid_(-1), exitStatus_(NotExited), exitCode_(0) { } @@ -240,7 +240,7 @@ int Process::start(const std::string &path, { int ret; - if (running_) + if (pid_ > 0) return 0; int childPid = fork(); @@ -252,8 +252,6 @@ int Process::start(const std::string &path, pid_ = childPid; ProcessManager::instance()->registerProcess(this); - running_ = true; - return 0; } else { if (isolate()) @@ -327,7 +325,7 @@ int Process::isolate() */ void Process::died(int wstatus) { - running_ = false; + pid_ = -1; exitStatus_ = WIFEXITED(wstatus) ? NormalExit : SignalExit; exitCode_ = exitStatus_ == NormalExit ? WEXITSTATUS(wstatus) : -1;