From ffe14640c54887d5daf4c1e76547c171e7b644e8 Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Tue, 25 Mar 2025 17:33:05 -0700 Subject: Update return codes for service commands to provide more information to the caller --- src/zen/cmds/service_cmd.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/zen/cmds/service_cmd.cpp b/src/zen/cmds/service_cmd.cpp index 386046e66..fd4d3895e 100644 --- a/src/zen/cmds/service_cmd.cpp +++ b/src/zen/cmds/service_cmd.cpp @@ -92,6 +92,7 @@ namespace { else { ZEN_CONSOLE("Failed to run elevated, operation did not complete."); + ReturnCode = DWORD(-1); } return (int)ReturnCode; } @@ -272,6 +273,14 @@ FmtServiceInfo(const ServiceInfo& Info, std::string_view Prefix) return Result; } +enum class ServiceStatusReturnCode +{ + Running = 0, // successful return indicates proper installation and everything running smoothly + NotInstalled, + NotRunning, + UnknownError +}; + int ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { @@ -304,12 +313,17 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) if (Ec) { ZEN_CONSOLE("Can't get information about service '{}'. Reason: '{}'", m_ServiceName, Ec.message()); - return 1; + return gsl::narrow(ServiceStatusReturnCode::UnknownError); } if (Info.Status == ServiceStatus::NotInstalled) { ZEN_CONSOLE("Service '{}' is not installed", m_ServiceName); - return 0; + return gsl::narrow(ServiceStatusReturnCode::NotInstalled); + } + else if (Info.Status != ServiceStatus::Running) + { + ZEN_CONSOLE("Service '{}' is not running", m_ServiceName); + return gsl::narrow(ServiceStatusReturnCode::NotRunning); } else { -- cgit v1.2.3