summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-05-19 13:14:16 -0400
committerIan Moffett <ian@osmora.org>2025-05-19 13:14:16 -0400
commit988be480644b7a1ba2073b233120b985193c099a (patch)
treee5d58c9d49d1f1c7b3522aeb9a45d6f2fcb3acd5
parent6f5c02a9472d288bd190f71597e24d86e4ffd23e (diff)
usr: osh: Add "reboot" and "shutdown" commandsmain
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--usr.bin/osh/osh.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index 2f592ad..c45d9c8 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sys/cdefs.h>
+#include <sys/reboot.h>
#include <fcntl.h>
#include <stddef.h>
#include <unistd.h>
@@ -44,9 +45,11 @@
#define HELP \
"Default commands:\n" \
- "help - Display this help message\n" \
- "echo - Print the arguments to the console\n" \
- "exit - Exit the shell\n"
+ "help - Display this help message\n" \
+ "echo - Print the arguments to the console\n" \
+ "reboot - Reboot the machine\n" \
+ "shutdown - Power off the machine\n" \
+ "exit - Exit the shell\n"
#define PROMPT "[root::osmora]~ "
@@ -72,6 +75,18 @@ cmd_exit(int fd, int argc, char *argv[])
}
void
+cmd_reboot(int fd, int argc, char *argv[])
+{
+ cpu_reboot(REBOOT_RESET);
+}
+
+void
+cmd_shutdown(int fd, int argc, char *argv[])
+{
+ cpu_reboot(REBOOT_POWEROFF | REBOOT_HALT);
+}
+
+void
cmd_echo(int fd, int argc, char *argv[])
{
for (i = 1; i < argc; i++) {
@@ -154,6 +169,8 @@ struct command cmds[] = {
{"help", cmd_help},
{"echo", cmd_echo},
{"exit", cmd_exit},
+ {"reboot", cmd_reboot},
+ {"shutdown", cmd_shutdown},
{NULL, NULL}
};