aboutsummaryrefslogtreecommitdiff
path: root/core/powerctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/powerctl.c')
-rw-r--r--core/powerctl.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/powerctl.c b/core/powerctl.c
new file mode 100644
index 0000000..cf887bf
--- /dev/null
+++ b/core/powerctl.c
@@ -0,0 +1,29 @@
+#include "../lib/sys/reboot.h"
+#include "../lib/cstr/cstr.h"
+#include "../lib/io/io.h"
+#include "../lib/sys/sync.h"
+
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ wf(STDERR_FD, "powerctl [poweroff|reboot|halt|hard-reset|suspend]\n");
+ return -1;
+ }
+
+ char *command = argv[1];
+
+ sync();
+
+ if (cstr_compare(command, "poweroff")) {
+ reboot(REBOOT_POWEROFF);
+ } else if (cstr_compare(command, "reboot")) {
+ reboot(REBOOT_RESTART);
+ } else if (cstr_compare(command, "halt")) {
+ reboot(REBOOT_HALT_SYSTEM);
+ } else if (cstr_compare(command, "hard-reset")) {
+ reboot(REBOOT_HARD_RESET);
+ } else if (cstr_compare(command, "suspend")) {
+ reboot(REBOOT_SUSPEND);
+ }
+
+ return -1;
+}