aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie De Brauwer <eliedebrauwer@gmail.com>2013-10-01 20:57:21 +0200
committerElie De Brauwer <eliedebrauwer@gmail.com>2013-10-01 20:57:21 +0200
commit9b2b24a1e88f4e96e431b0292831d13995fbdd7f (patch)
treec4e7bb67e930f5f49eb53407ae4ed45f88183560
parent18ec03543c3731e1ea25182ef72c49ac5ec2d1c7 (diff)
downloadtoybox-9b2b24a1e88f4e96e431b0292831d13995fbdd7f.tar.gz
New toy: reboot/halt/poweroff
-rw-r--r--toys/other/reboot.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/toys/other/reboot.c b/toys/other/reboot.c
new file mode 100644
index 00000000..ae70cf91
--- /dev/null
+++ b/toys/other/reboot.c
@@ -0,0 +1,42 @@
+/* reboot.c - Restart, halt or powerdown the system.
+ *
+ * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com>
+
+USE_REBOOT(NEWTOY(reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
+USE_REBOOT(OLDTOY(halt, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
+USE_REBOOT(OLDTOY(poweroff, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
+
+config REBOOT
+ bool "reboot"
+ default y
+ help
+ usage: reboot/halt/poweroff [-n]
+
+ Restart, halt or powerdown the system.
+
+ -n Don't sync before stopping the system.
+*/
+
+#define FOR_reboot
+#include "toys.h"
+#include <sys/reboot.h>
+
+void reboot_main(void)
+{
+ char c = toys.which->name[0];
+
+ if (!(toys.optflags & FLAG_n))
+ sync();
+
+ switch(c) {
+ case 'p':
+ toys.exitval = reboot(RB_POWER_OFF);
+ break;
+ case 'h':
+ toys.exitval = reboot(RB_HALT_SYSTEM);
+ break;
+ case 'r':
+ default:
+ toys.exitval = reboot(RB_AUTOBOOT);
+ }
+}