aboutsummaryrefslogtreecommitdiff
path: root/core/powerctl.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-02-08 13:19:56 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2023-02-08 13:19:56 +0100
commitd7229970f8910aa756d299f8bdceee7f4d1fbfbc (patch)
treea95ff2e6bd50578d34d6449c9fde173acc0ef59c /core/powerctl.c
parente947b1459f93f11ad91f3e920676fe1b828281e7 (diff)
add env and make smash be able to parse files with comments
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;
+}