summaryrefslogtreecommitdiff
path: root/zen/shutdown.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-04-18 12:59:51 -0400
committerB Stack <bgstack15@gmail.com>2020-04-18 12:59:51 -0400
commitfc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0 (patch)
tree8cfcea5441be72ad92095a3887ded84d38f9ba11 /zen/shutdown.cpp
parentMerge branch '10.22' into 'master' (diff)
downloadFreeFileSync-fc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0.tar.gz
FreeFileSync-fc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0.tar.bz2
FreeFileSync-fc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0.zip
add upstream 10.23
Diffstat (limited to 'zen/shutdown.cpp')
-rw-r--r--zen/shutdown.cpp28
1 files changed, 20 insertions, 8 deletions
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()); }
}
bgstack15