void
usage()
{
- fprintf(stderr, "Usage: %s [-hrRf] [-x reboot-code]\n", prog);
+ fprintf(stderr, "Usage: %s [-hrRfd] [-x reboot-code]\n", prog);
exit(1);
}
case 'h': flag = RBT_HALT; break;
case 'r': flag = RBT_REBOOT; break;
case 'R': flag = RBT_RESET; break;
+ case 'd': flag = RBT_DEFAULT; break;
case 'f': fast = 1; break;
case 'x':
flag = RBT_MONITOR;
-C: crash check, i.e. is the last wtmp entry a shutdown entry?
-x: let the monitor execute the given code
-R: reset the system
+ -d: default CTRL-ALT-DEL shutdown for current bootloader
*/
#define _POSIX_SOURCE 1
case 'h':
case 'r':
case 'x':
+ case 'd':
reboot_flag = *opt;
if (reboot_flag == 'x') {
if (*++opt == 0) {
void usage()
{
- fputs("Usage: shutdown [-hrRmk] [-x code] [time [message]]\n", stderr);
+ fputs("Usage: shutdown [-hrRmkd] [-x code] [time [message]]\n", stderr);
fputs(" -h -> halt system after shutdown\n", stderr);
fputs(" -r -> reboot system after shutdown\n", stderr);
fputs(" -R -> reset system after shutdown\n", stderr);
fputs(" -x -> return to the monitor doing...\n", stderr);
+ fputs(" -d -> default CTRL-ALT-DEL shutdown for current bootloader\n", stderr);
fputs(" -m -> read a shutdown message from standard input\n", stderr);
fputs(" -k -> stop an already running shutdown\n", stderr);
fputs(" code -> boot monitor code to be executed\n", stderr);
{
if (++CAD_count == 3) {
cons_stop();
- sys_abort(RBT_HALT);
+ sys_abort(RBT_DEFAULT);
}
sys_kill(INIT_PROC_NR, SIGABRT);
rebooting = 1;
#define RBT_PANIC 2 /* a server panics */
#define RBT_MONITOR 3 /* let the monitor do this */
#define RBT_RESET 4 /* hard reset the system */
-#define RBT_INVALID 5 /* first invalid reboot flag */
+#define RBT_DEFAULT 5 /* return to monitor, reset if not possible */
+#define RBT_INVALID 6 /* first invalid reboot flag */
#define _PM_SEG_FLAG (1L << 30) /* for read() and write() to FS by PM */
#endif
PUBLIC int cpu_has_tsc;
-PUBLIC __dead void arch_shutdown(const int how)
+PUBLIC __dead void arch_shutdown(int how)
{
static char mybuffer[sizeof(params_buffer)];
+ u16_t magic;
vm_stop();
/* Mask all interrupts, including the clock. */
}
}
+ if (how == RBT_DEFAULT) {
+ how = mon_return ? RBT_HALT : RBT_RESET;
+ }
+
if(how != RBT_RESET) {
/* return to boot monitor */
}
if (mon_return)
arch_monitor();
- else {
+
+ /* monitor command with no monitor: reset or poweroff
+ * depending on the parameters
+ */
+ if (how == RBT_MONITOR) {
mybuffer[0] = '\0';
- arch_get_params(mybuffer,sizeof(mybuffer));
+ arch_get_params(mybuffer, sizeof(mybuffer));
if (strstr(mybuffer, "boot") ||
strstr(mybuffer, "menu") ||
strstr(mybuffer, "reset"))
- reset();
- else
- arch_bios_poweroff();
+ how = RBT_RESET;
+ else
+ how = RBT_HALT;
}
- } else {
- /* Reset the system by forcing a processor shutdown. First stop
- * the BIOS memory test by setting a soft reset flag.
- */
- u16_t magic = STOP_MEM_CHECK;
- phys_copy(vir2phys(&magic), SOFT_RESET_FLAG_ADDR,
- SOFT_RESET_FLAG_SIZE);
- reset();
+ }
+
+ switch (how) {
+ case RBT_REBOOT:
+ case RBT_RESET:
+ /* Reset the system by forcing a processor shutdown.
+ * First stop the BIOS memory test by setting a soft
+ * reset flag.
+ */
+ magic = STOP_MEM_CHECK;
+ phys_copy(vir2phys(&magic), SOFT_RESET_FLAG_ADDR,
+ SOFT_RESET_FLAG_SIZE);
+ reset();
+ NOT_REACHABLE;
+
+ case RBT_HALT:
+ /* Poweroff without boot monitor */
+ arch_bios_poweroff();
+ NOT_REACHABLE;
+
+ case RBT_PANIC:
+ /* Allow user to read panic message */
+ for (; ; ) halt_cpu();
+ NOT_REACHABLE;
+
+ default:
+ /* Not possible! trigger panic */
+ assert(how != RBT_MONITOR);
+ assert(how != RBT_DEFAULT);
+ assert(how < RBT_INVALID);
+ panic("unexpected value for how: %d", how);
+ NOT_REACHABLE;
}
NOT_REACHABLE;
shutdown \- graciously close the system down
.SH SYNOPSIS
.B shutdown
-.RB [ \-hrRmk ]
+.RB [ \-hrRmkd ]
.RB [ \-x
.IR code ]
.RI [ time-specification
.B \-R
the system will receive a hardware reset.
.TP
+.B \-d
+Default CTRL-ALT-DEL shutdown for current bootloader; drops to the boot
+monitor is possible and resets otherwise.
+.TP
.BI \-x " code"
Halt the system and let the Monitor execute the given code as if typed at
the monitor prompt. You can for instance use
#include <utmp.h>
/* Command to execute as a response to the three finger salute. */
-char *REBOOT_CMD[] = { "shutdown", "now", "CTRL-ALT-DEL", NULL };
+char *REBOOT_CMD[] = { "shutdown", "-d", "now", "CTRL-ALT-DEL", NULL };
/* Associated fake ttytab entry. */
struct ttyent TT_REBOOT = { "console", "-", REBOOT_CMD, NULL };