aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README5
-rw-r--r--src/kill_everyone_and_reboot.cc35
2 files changed, 38 insertions, 2 deletions
diff --git a/README b/README
index e69de29..ab4478f 100644
--- a/README
+++ b/README
@@ -0,0 +1,5 @@
+Annie says "This is named after my good friend Annie, with whom I had the good
+fortune of living in my final year at Glasgow University. She is a lovely
+lovely person who I adore greatly (and she has great boobs!)."
+
+Uh, I needed a name, and she couldn't think of one.
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;
}