From 988be480644b7a1ba2073b233120b985193c099a Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 19 May 2025 13:14:16 -0400 Subject: usr: osh: Add "reboot" and "shutdown" commands Signed-off-by: Ian Moffett --- usr.bin/osh/osh.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'usr.bin') 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 #include +#include #include #include #include @@ -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]~ " @@ -71,6 +74,18 @@ cmd_exit(int fd, int argc, char *argv[]) running = 0; } +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[]) { @@ -154,6 +169,8 @@ struct command cmds[] = { {"help", cmd_help}, {"echo", cmd_echo}, {"exit", cmd_exit}, + {"reboot", cmd_reboot}, + {"shutdown", cmd_shutdown}, {NULL, NULL} }; -- cgit v1.2.3