From d7229970f8910aa756d299f8bdceee7f4d1fbfbc Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 8 Feb 2023 13:19:56 +0100 Subject: add env and make smash be able to parse files with comments --- core/powerctl.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core/powerctl.c (limited to 'core/powerctl.c') 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; +} -- cgit v1.2.3-70-g09d2