From fc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0 Mon Sep 17 00:00:00 2001 From: B Stack Date: Sat, 18 Apr 2020 12:59:51 -0400 Subject: add upstream 10.23 --- zen/shutdown.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'zen/shutdown.cpp') diff --git a/zen/shutdown.cpp b/zen/shutdown.cpp index 89da55ee..21e24527 100644 --- a/zen/shutdown.cpp +++ b/zen/shutdown.cpp @@ -15,19 +15,31 @@ using namespace zen; void zen::shutdownSystem() //throw FileError { - //https://linux.die.net/man/2/reboot => needs admin rights! - - //"systemctl" should work without admin rights: - shellExecute("systemctl poweroff", ExecutionType::sync, false/*hideConsole*/); //throw FileError - + try + { + //https://linux.die.net/man/2/reboot => needs admin rights! + //"systemctl" should work without admin rights: + const auto [exitCode, output] = consoleExecute("systemctl poweroff", std::nullopt /*timeoutMs*/); //throw SysError, (SysErrorTimeOut) + if (!trimCpy(output).empty()) //see comment in suspendSystem() + throw SysError(output); + + } + catch (const SysError& e) { throw FileError(_("Unable to shut down the system."), e.toString()); } } void zen::suspendSystem() //throw FileError { - //"systemctl" should work without admin rights: - shellExecute("systemctl suspend", ExecutionType::sync, false/*hideConsole*/); //throw FileError - + try + { + //"systemctl" should work without admin rights: + const auto [exitCode, output] = consoleExecute("systemctl suspend", std::nullopt /*timeoutMs*/); //throw SysError, (SysErrorTimeOut) + //why does "systemctl suspend" return exit code 1 despite apparent success!?? + if (!trimCpy(output).empty()) //at least we can assume "no output" on success + throw SysError(output); + + } + catch (const SysError& e) { throw FileError(_("Unable to shut down the system."), e.toString()); } } -- cgit