Remove ability to pass commands to bootloader

This commit is contained in:
Erik van der Kouwe 2012-11-22 17:30:22 +01:00
parent 4a711bea63
commit 57c748b968
14 changed files with 35 additions and 123 deletions

View file

@ -29,12 +29,11 @@ void usage( void );
int main( int argc, char *argv[] ); int main( int argc, char *argv[] );
char *prog; char *prog;
char *reboot_code = "delay; boot";
void void
usage() usage()
{ {
fprintf(stderr, "Usage: %s [-hrRfpd] [-x reboot-code]\n", prog); fprintf(stderr, "Usage: %s [-hrRfpd]\n", prog);
exit(1); exit(1);
} }
@ -47,7 +46,6 @@ char **argv;
int fast = 0; /* fast halt/reboot, don't bother being nice. */ int fast = 0; /* fast halt/reboot, don't bother being nice. */
int i; int i;
struct stat dummy; struct stat dummy;
char *monitor_code = "";
pid_t pid; pid_t pid;
if ((prog = strrchr(argv[0],'/')) == NULL) prog = argv[0]; else prog++; if ((prog = strrchr(argv[0],'/')) == NULL) prog = argv[0]; else prog++;
@ -68,15 +66,6 @@ char **argv;
case 'd': flag = RBT_DEFAULT; break; case 'd': flag = RBT_DEFAULT; break;
case 'p': flag = RBT_POWEROFF; break; case 'p': flag = RBT_POWEROFF; break;
case 'f': fast = 1; break; case 'f': fast = 1; break;
case 'x':
flag = RBT_MONITOR;
if (*opt == 0) {
if (i == argc) usage();
opt = argv[i++];
}
monitor_code = opt;
opt = "";
break;
default: default:
usage(); usage();
} }
@ -89,11 +78,6 @@ char **argv;
exit(1); exit(1);
} }
if (flag == RBT_REBOOT) {
flag = RBT_MONITOR; /* set monitor code for reboot */
monitor_code = reboot_code;
}
if (stat("/usr/bin", &dummy) < 0) { if (stat("/usr/bin", &dummy) < 0) {
/* It seems that /usr isn't present, let's assume "-f." */ /* It seems that /usr isn't present, let's assume "-f." */
fast = 1; fast = 1;
@ -135,7 +119,7 @@ char **argv;
sync(); sync();
reboot(flag, monitor_code, strlen(monitor_code)); reboot(flag);
fprintf(stderr, "%s: reboot(): %s\n", prog, strerror(errno)); fprintf(stderr, "%s: reboot(): %s\n", prog, strerror(errno));
return 1; return 1;
} }

View file

@ -18,7 +18,6 @@
New Minix options: New Minix options:
-C: crash check, i.e. is the last wtmp entry a shutdown entry? -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 -R: reset the system
-d: default CTRL-ALT-DEL shutdown for current bootloader -d: default CTRL-ALT-DEL shutdown for current bootloader
*/ */
@ -63,7 +62,6 @@ long wait_time=0L;
char message[1024]; char message[1024];
char info[80]; char info[80];
int reboot_flag='h'; /* default is halt */ int reboot_flag='h'; /* default is halt */
char *reboot_code=""; /* optional monitor code */
int info_min, info_hour; int info_min, info_hour;
char *prog; char *prog;
@ -132,7 +130,7 @@ char *argv[];
char *opt; char *opt;
int tty; int tty;
static char HALT1[] = "-?"; static char HALT1[] = "-?";
static char *HALT[] = { "shutdown", HALT1, NULL, NULL }; static char *HALT[] = { "shutdown", HALT1, NULL };
/* Parse options. */ /* Parse options. */
for (i = 1; i < argc && argv[i][0] == '-'; i++) { for (i = 1; i < argc && argv[i][0] == '-'; i++) {
@ -149,23 +147,9 @@ char *argv[];
case 'h': case 'h':
case 'r': case 'r':
case 'p': case 'p':
case 'x':
case 'd': case 'd':
reboot_flag = *opt;
if (reboot_flag == 'x') {
if (*++opt == 0) {
if (++i == argc) {
fprintf (stderr,"shutdown: option '-x' requires an argument\n");
usage();
}
opt=argv[i];
}
reboot_code=opt;
opt+=strlen(opt)-1;
}
break;
case 'R': case 'R':
reboot_flag = 'R'; reboot_flag = *opt;
break; break;
case 'm': case 'm':
want_message = 1; want_message = 1;
@ -256,7 +240,6 @@ char *argv[];
unlink(NOLOGIN); unlink(NOLOGIN);
HALT[1][1] = reboot_flag; HALT[1][1] = reboot_flag;
if (reboot_flag == 'x') HALT[2] = reboot_code;
#if __minix_vmd #if __minix_vmd
execv("/usr/sbin/halt", HALT); execv("/usr/sbin/halt", HALT);
#else #else
@ -274,16 +257,14 @@ char *argv[];
void usage() void usage()
{ {
fputs("Usage: shutdown [-hrRpmkd] [-x code] [time [message]]\n", stderr); fputs("Usage: shutdown [-hrRpmkd] [time [message]]\n", stderr);
fputs(" -h -> halt system after shutdown\n", stderr); fputs(" -h -> halt system after shutdown\n", stderr);
fputs(" -r -> reboot system after shutdown\n", stderr); fputs(" -r -> reboot system after shutdown\n", stderr);
fputs(" -R -> reset system after shutdown\n", stderr); fputs(" -R -> reset system after shutdown\n", stderr);
fputs(" -p -> power system off after shutdown\n", stderr); fputs(" -p -> power system off 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(" -d -> default CTRL-ALT-DEL shutdown for current bootloader\n", stderr);
fputs(" -m -> read a shutdown message from standard input\n", stderr); fputs(" -m -> read a shutdown message from standard input\n", stderr);
fputs(" -k -> stop an already running shutdown\n", stderr); fputs(" -k -> stop an already running shutdown\n", stderr);
fputs(" code -> boot monitor code to be executed\n", stderr);
fputs(" time -> keyword ``now'', minutes before shutdown ``+5'',\n", stderr); fputs(" time -> keyword ``now'', minutes before shutdown ``+5'',\n", stderr);
fputs(" or absolute time specification ``11:20''\n", stderr); fputs(" or absolute time specification ``11:20''\n", stderr);
fputs(" message -> short shutdown message\n", stderr); fputs(" message -> short shutdown message\n", stderr);

View file

@ -420,9 +420,6 @@
/* Field names for SYS_ABORT. */ /* Field names for SYS_ABORT. */
#define ABRT_HOW m1_i1 /* RBT_REBOOT, RBT_HALT, etc. */ #define ABRT_HOW m1_i1 /* RBT_REBOOT, RBT_HALT, etc. */
#define ABRT_MON_ENDPT m1_i2 /* process where monitor params are */
#define ABRT_MON_LEN m1_i3 /* length of monitor params */
#define ABRT_MON_ADDR m1_p1 /* virtual address of monitor params */
/* Field names for SYS_IOPENABLE. */ /* Field names for SYS_IOPENABLE. */
#define IOP_ENDPT m2_l1 /* target endpoint */ #define IOP_ENDPT m2_l1 /* target endpoint */

View file

@ -33,7 +33,7 @@ struct rs_pci;
int _taskcall(endpoint_t who, int syscallnr, message *msgptr); int _taskcall(endpoint_t who, int syscallnr, message *msgptr);
int _kernel_call(int syscallnr, message *msgptr); int _kernel_call(int syscallnr, message *msgptr);
int sys_abort(int how, ...); int sys_abort(int how);
int sys_enable_iop(endpoint_t proc_ep); int sys_enable_iop(endpoint_t proc_ep);
int sys_exec(endpoint_t proc_ep, char *ptr, char *aout, vir_bytes int sys_exec(endpoint_t proc_ep, char *ptr, char *aout, vir_bytes
initpc); initpc);

View file

@ -5,10 +5,9 @@
#define RBT_HALT 0 /* shutdown and return to monitor */ #define RBT_HALT 0 /* shutdown and return to monitor */
#define RBT_REBOOT 1 /* reboot the system through the monitor */ #define RBT_REBOOT 1 /* reboot the system through the monitor */
#define RBT_PANIC 2 /* a server panics */ #define RBT_PANIC 2 /* a server panics */
#define RBT_MONITOR 3 /* let the monitor do this */ #define RBT_POWEROFF 3 /* power off, reset if not possible */
#define RBT_RESET 4 /* hard reset the system */ #define RBT_RESET 4 /* hard reset the system */
#define RBT_DEFAULT 5 /* return to monitor, reset if not possible */ #define RBT_DEFAULT 5 /* return to monitor, reset if not possible */
#define RBT_POWEROFF 6 /* power off, reset if not possible */ #define RBT_INVALID 6 /* first invalid reboot flag */
#define RBT_INVALID 7 /* first invalid reboot flag */
#endif #endif

View file

@ -356,7 +356,7 @@ void psignal(int, const char *);
#endif /* __PSIGNAL_DECLARED */ #endif /* __PSIGNAL_DECLARED */
int rcmd(char **, int, const char *, const char *, const char *, int *); int rcmd(char **, int, const char *, const char *, const char *, int *);
#ifdef __minix #ifdef __minix
int reboot(int, ...); int reboot(int);
#else #else
int reboot(int, char *); int reboot(int, char *);
#endif #endif

View file

@ -118,10 +118,6 @@ __dead void arch_shutdown(int how)
reset(); reset();
} }
if (how == RBT_DEFAULT) {
how = RBT_RESET;
}
switch (how) { switch (how) {
case RBT_HALT: case RBT_HALT:
/* Stop */ /* Stop */
@ -133,7 +129,8 @@ __dead void arch_shutdown(int how)
poweroff(); poweroff();
NOT_REACHABLE; NOT_REACHABLE;
default: default:
case RBT_DEFAULT:
case RBT_REBOOT: case RBT_REBOOT:
case RBT_RESET: case RBT_RESET:
/* Reset the system by forcing a processor shutdown. /* Reset the system by forcing a processor shutdown.

View file

@ -349,7 +349,7 @@ void minix_shutdown(timer_t *tp)
{ {
/* This function is called from prepare_shutdown or stop_sequence to bring /* This function is called from prepare_shutdown or stop_sequence to bring
* down MINIX. How to shutdown is in the argument: RBT_HALT (return to the * down MINIX. How to shutdown is in the argument: RBT_HALT (return to the
* monitor), RBT_MONITOR (execute given code), RBT_RESET (hard reset). * monitor), RBT_RESET (hard reset).
*/ */
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
/* /*

View file

@ -3,9 +3,6 @@
* *
* The parameters for this kernel call are: * The parameters for this kernel call are:
* m1_i1: ABRT_HOW (how to abort, possibly fetch monitor params) * m1_i1: ABRT_HOW (how to abort, possibly fetch monitor params)
* m1_i2: ABRT_MON_ENDPT (proc nr to get monitor params from)
* m1_i3: ABRT_MON_LEN (length of monitor params)
* m1_p1: ABRT_MON_ADDR (virtual address of params)
*/ */
#include "kernel/system.h" #include "kernel/system.h"
@ -23,20 +20,6 @@ int do_abort(struct proc * caller, message * m_ptr)
*/ */
int how = m_ptr->ABRT_HOW; int how = m_ptr->ABRT_HOW;
/* See if the monitor is to run the specified instructions. */
if (how == RBT_MONITOR) {
int p;
static char paramsbuffer[512];
int len;
len = MIN(m_ptr->ABRT_MON_LEN, sizeof(paramsbuffer)-1);
if((p=data_copy(m_ptr->ABRT_MON_ENDPT, (vir_bytes) m_ptr->ABRT_MON_ADDR,
KERNEL, (vir_bytes) paramsbuffer, len)) != OK) {
return p;
}
paramsbuffer[len] = '\0';
}
/* Now prepare to shutdown MINIX. */ /* Now prepare to shutdown MINIX. */
prepare_shutdown(how); prepare_shutdown(how);
return(OK); /* pro-forma (really EDISASTER) */ return(OK); /* pro-forma (really EDISASTER) */

View file

@ -11,17 +11,10 @@
#include <sys/reboot.h> #include <sys/reboot.h>
#include <stdarg.h> #include <stdarg.h>
int reboot(int how, ...) int reboot(int how)
{ {
message m; message m;
va_list ap;
va_start(ap, how);
if ((m.m1_i1 = how) == RBT_MONITOR) {
m.m1_p1 = va_arg(ap, char *);
m.m1_i2 = va_arg(ap, size_t);
}
va_end(ap);
m.m1_i1 = how;
return _syscall(PM_PROC_NR, REBOOT, &m); return _syscall(PM_PROC_NR, REBOOT, &m);
} }

View file

@ -2,20 +2,12 @@
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
int sys_abort(int how, ...) int sys_abort(int how)
{ {
/* Something awful has happened. Abandon ship. */ /* Something awful has happened. Abandon ship. */
message m; message m;
va_list ap;
va_start(ap, how);
if ((m.ABRT_HOW = how) == RBT_MONITOR) {
m.ABRT_MON_ENDPT = va_arg(ap, int);
m.ABRT_MON_ADDR = va_arg(ap, char *);
m.ABRT_MON_LEN = va_arg(ap, size_t);
}
va_end(ap);
m.ABRT_HOW = how;
return(_kernel_call(SYS_ABORT, &m)); return(_kernel_call(SYS_ABORT, &m));
} }

View file

@ -8,7 +8,7 @@ reboot \- close down the system or reboot
#include <unistd.h> #include <unistd.h>
int reboot(int \fIhow\fP, ...) int reboot(int \fIhow\fP)
.fi .fi
.ft P .ft P
.SH DESCRIPTION .SH DESCRIPTION
@ -18,11 +18,12 @@ down depending on
.IR how : .IR how :
.PP .PP
.TP 5 .TP 5
.BI "reboot(RBT_HALT)" .BI "reboot(RBT_DEFAULT)"
Halt the system and return to the monitor prompt. Default shut-down action, the same as used when CTRL+ALT+DEL is pressed
on the keyboard.
.TP .TP
.BI "reboot(RBT_REBOOT)" .BI "reboot(RBT_HALT)"
Reboot the system by letting the monitor execute the "boot" command. Halt the system.
.TP .TP
.BI "reboot(RBT_PANIC)" .BI "reboot(RBT_PANIC)"
Cause a system panic. This is not normally done from user mode, but by Cause a system panic. This is not normally done from user mode, but by
@ -30,16 +31,12 @@ servers using the
.B sys_abort() .B sys_abort()
kernel call. kernel call.
.TP .TP
.BI "reboot(RBT_MONITOR" ", code, length" ")" .BI "reboot(RBT_POWEROFF)"
Halt the system and let the monitor execute the given code of the given Power off the system if possible, reset otherwise.
length. .TP
.RI ( code .BI "reboot(RBT_REBOOT)"
is of type Reboot the system with a software reset (currently not supported, so
.B "char *" a hardware reset is used).
and
.I length
of type
.BR size_t .)
.TP .TP
.BI "reboot(RBT_RESET)" .BI "reboot(RBT_RESET)"
Reboot the system with a hardware reset. Reboot the system with a hardware reset.
@ -55,8 +52,5 @@ the return value is -1 and an error is indicated by
.BR reboot (8), .BR reboot (8),
.BR halt (8), .BR halt (8),
.BR sync (2). .BR sync (2).
.SH NOTES
MINIX 3 can not return to the monitor if running in real mode. This means
that most of the reboot functions will change to a system reset.
.SH AUTHOR .SH AUTHOR
Edvard Tuinder (v892231@si.hhs.NL) Edvard Tuinder (v892231@si.hhs.NL)

View file

@ -3,9 +3,7 @@
shutdown \- graciously close the system down shutdown \- graciously close the system down
.SH SYNOPSIS .SH SYNOPSIS
.B shutdown .B shutdown
.RB [ \-hrRmkd ] .RB [ \-hrRmkpd ]
.RB [ \-x
.IR code ]
.RI [ time-specification .RI [ time-specification
.RI [ message ]] .RI [ message ]]
.SH DESCRIPTION .SH DESCRIPTION
@ -55,20 +53,16 @@ system can now be powered off. This is the default.
This flag indicates that the system should reboot after shutting down. This flag indicates that the system should reboot after shutting down.
.TP .TP
.B \-R .B \-R
Reboot the system by resetting it. Normally the kernel will try to return Reboot the system by resetting it. With
to the Boot Monitor. With
.B \-R .B \-R
the system will receive a hardware reset. the system will receive a hardware reset.
.TP .TP
.B \-d .B \-p
Default CTRL-ALT-DEL shutdown for current bootloader; drops to the boot Attempt to power off the machine after shutting down; reset if that
monitor is possible and resets otherwise. is not possible on the current hardware.
.TP .TP
.BI \-x " code" .B \-d
Halt the system and let the Monitor execute the given code as if typed at Default CTRL-ALT-DEL shutdown.
the monitor prompt. You can for instance use
.B "\-x 'boot hd0'"
as a very fast way to reboot "from the top."
.TP .TP
.B \-m .B \-m
Allows the operator to type a shutdown message on standard input, that will Allows the operator to type a shutdown message on standard input, that will

View file

@ -27,8 +27,6 @@
#define sig_how m2_i1 #define sig_how m2_i1
#define sig_context m2_p1 #define sig_context m2_p1
#define reboot_flag m1_i1 #define reboot_flag m1_i1
#define reboot_code m1_p1
#define reboot_strlen m1_i2
#define svrctl_req m2_i1 #define svrctl_req m2_i1
#define svrctl_argp m2_p1 #define svrctl_argp m2_p1
#define stime m2_l1 #define stime m2_l1