summaryrefslogtreecommitdiff
path: root/usr.bin/reboot
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-19 17:43:17 +0000
committerIan Moffett <ian@osmora.org>2025-08-19 17:45:31 +0000
commit0d0435966d88c7c2918d07d01a70db85ba4bc1a6 (patch)
tree4dbbdd429769feb8b8149eb6edf6ba6c27c76715 /usr.bin/reboot
parent47cc65d2231dbd9acaedbe1ee0542ef4293aeddb (diff)
usr: reboot: Add method flags
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin/reboot')
-rw-r--r--usr.bin/reboot/reboot.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/usr.bin/reboot/reboot.c b/usr.bin/reboot/reboot.c
index 08580d5..0fed0d2 100644
--- a/usr.bin/reboot/reboot.c
+++ b/usr.bin/reboot/reboot.c
@@ -29,10 +29,50 @@
#include <sys/reboot.h>
#include <stdio.h>
+#include <unistd.h>
+
+#define REBOOT_FLAGS "rh"
+#define REBOOT_FLAG_RB 'r' /* Reboot */
+#define REBOOT_FLAG_HLT 'h' /* Halt */
+
+static void
+help(void)
+{
+ printf(
+ "reboot: usage: reboot [flags]\n"
+ "flags:\n"
+ " [-r] Reboot\n"
+ " [-h] Halt\n"
+ );
+}
int
-main(void)
+main(int argc, char **argv)
{
- cpu_reboot(REBOOT_RESET);
+ int c;
+
+ if (argc < 2) {
+ help();
+ return -1;
+ }
+
+ /*
+ * Now we parse the args. Every case is a fall through
+ * as if one fails (indicated by us returning), another
+ * method is attempted.
+ */
+ while ((c = getopt(argc, argv, REBOOT_FLAGS)) != -1) {
+ switch (c) {
+ case REBOOT_FLAG_RB:
+ cpu_reboot(REBOOT_RESET);
+ printf("REBOOT failed\n");
+ /* Fall through */
+ case REBOOT_FLAG_HLT:
+ cpu_reboot(REBOOT_FLAG_HLT);
+ printf("HALT failed\n");
+ /* Fall through */
+ }
+ }
+
return 0;
}