summaryrefslogtreecommitdiff
path: root/zen/shutdown.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-04-18 17:00:42 +0000
committerB Stack <bgstack15@gmail.com>2020-04-18 17:00:42 +0000
commitb4ecf755bad016b0d7fbb277106887f405f6b600 (patch)
tree8cfcea5441be72ad92095a3887ded84d38f9ba11 /zen/shutdown.cpp
parentMerge branch '10.22' into 'master' (diff)
parentadd upstream 10.23 (diff)
downloadFreeFileSync-b4ecf755bad016b0d7fbb277106887f405f6b600.tar.gz
FreeFileSync-b4ecf755bad016b0d7fbb277106887f405f6b600.tar.bz2
FreeFileSync-b4ecf755bad016b0d7fbb277106887f405f6b600.zip
Merge branch '10.23' into 'master'10.23
add upstream 10.23 See merge request opensource-tracking/FreeFileSync!20
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