aboutsummaryrefslogtreecommitdiff
path: root/src/kill_everyone_and_reboot.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/kill_everyone_and_reboot.cc')
-rw-r--r--src/kill_everyone_and_reboot.cc35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/kill_everyone_and_reboot.cc b/src/kill_everyone_and_reboot.cc
index a849c25..2823734 100644
--- a/src/kill_everyone_and_reboot.cc
+++ b/src/kill_everyone_and_reboot.cc
@@ -63,6 +63,16 @@ namespace
sync();
}
+ void do_reboot()
+ {
+ std::cerr << "Rebooting" << std::endl;
+ if (0 != reboot(RB_AUTOBOOT))
+ {
+ std::cerr << "Couldn't call reboot syscall" << strerror(errno) << std::endl;
+ exit(EXIT_FAILURE);
+ }
+ }
+
void power_off()
{
std::cerr << "Power off" << std::endl;
@@ -74,15 +84,36 @@ namespace
}
}
-int main(int, char *[])
+int main(int argc, char * argv[])
{
+ bool reboot(false);
+ if (argc != 2)
+ {
+ std::cerr << "Usage: " << argv[0] << " (--reboot or --poweroff)" << std::endl;
+ exit(EXIT_FAILURE);
+ }
+
+ std::string cmd(argv[1]);
+ if (cmd == "--reboot")
+ reboot = true;
+ else if (cmd == "--poweroff")
+ ;
+ else
+ {
+ std::cerr << "Usage: " << argv[0] << " (--reboot or --poweroff)" << std::endl;
+ exit(EXIT_FAILURE);
+ }
+
kill_everybody(SIGTERM);
sleep(1);
kill_everybody(SIGKILL);
sleep(1);
remount_root_ro();
sync_filesystems();
- power_off();
+ if (reboot)
+ do_reboot();
+ else
+ power_off();
return EXIT_SUCCESS;
}