Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper shutdown and restart on linux #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions es-core/src/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
#include <boost/filesystem.hpp>
#include <iostream>

#ifdef WIN32
#include <codecvt>
#if defined(WIN32)
#include <codecvt>
#elif define(__linux__)
#include <unistd.h>
#include <sys/reboot.h>
#endif

std::string getHomePath()
Expand Down Expand Up @@ -41,18 +44,24 @@ std::string getHomePath()

int runShutdownCommand()
{
#ifdef WIN32 // windows
#if defined(WIN32)
return system("shutdown -s -t 0");
#else // osx / linux
#elif defined(__linux__)
sync();
return reboot(RB_POWER_OFF);
#else
return system("sudo shutdown -h now");
#endif
}

int runRestartCommand()
{
#ifdef WIN32 // windows
#if defined(WIN32)
return system("shutdown -r -t 0");
#else // osx / linux
#elif defined(__linux__)
sync();
return reboot(RB_AUTOBOOT);
#else
return system("sudo shutdown -r now");
#endif
}
Expand All @@ -69,4 +78,4 @@ int runSystemCommand(const std::string& cmd_utf8)
#else
return system(cmd_utf8.c_str());
#endif
}
}