From a1a57a68ffd92e6828932f69e04c7117a76c0f46 Mon Sep 17 00:00:00 2001 From: "J.T. Conklin" Date: Fri, 18 Aug 2023 07:57:04 -0700 Subject: [PATCH] Add folly::Subprocess::ProcessReturnCode::succeeded() Summary: This diff adds folly::Subprocess::ProcessReturnCode::succeeded(), a convenience method for determining whether a subprocess exited normally with a zero exit status. This is equivalent to Rust's std::process::ExitStatus::success(), but using a slightly different name to align with existing methods (e.g. exited(), killed(), coreDumped(), etc.). Reviewed By: jdonald, ot, luciang Differential Revision: D48333616 fbshipit-source-id: 71232bbdb6824f876d456c35d71ed898d4397c85 --- folly/Subprocess.cpp | 4 ++++ folly/Subprocess.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/folly/Subprocess.cpp b/folly/Subprocess.cpp index d11d88548f2..6e2793bb213 100644 --- a/folly/Subprocess.cpp +++ b/folly/Subprocess.cpp @@ -113,6 +113,10 @@ bool ProcessReturnCode::coreDumped() const { return WCOREDUMP(rawStatus_); } +bool ProcessReturnCode::succeeded() const { + return exited() && exitStatus() == 0; +} + std::string ProcessReturnCode::str() const { switch (state()) { case NOT_STARTED: diff --git a/folly/Subprocess.h b/folly/Subprocess.h index 8d3c2490a67..e23f3720a2a 100644 --- a/folly/Subprocess.h +++ b/folly/Subprocess.h @@ -194,6 +194,11 @@ class ProcessReturnCode { */ bool coreDumped() const; + /** + * Process exited normally with a zero exit status + */ + bool succeeded() const; + /** * String representation; one of * "not started"