# HG changeset patch
# User Elie De Brauwer <eliedebrauwer@gmail.com>
# Date 1380653841 -7200
# Node ID 75708f4fc9c1f53aba516690aec833b59b237cce
# Parent  565eba9b549ecc813a1237c115e48c843d380e4f
New toy: reboot/halt/poweroff

diff -r 565eba9b549e -r 75708f4fc9c1 toys/other/reboot.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/other/reboot.c	Tue Oct 01 20:57:21 2013 +0200
@@ -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);
+  }
+}
