diff --git a/elks/arch/i86/kernel/system.c b/elks/arch/i86/kernel/system.c index 7923ba8de..ad0bffc89 100644 --- a/elks/arch/i86/kernel/system.c +++ b/elks/arch/i86/kernel/system.c @@ -9,6 +9,7 @@ #include #include +#include #include seg_t membase, memend; /* start and end segment of available main memory */ @@ -83,6 +84,15 @@ unsigned int INITPROC setup_arch(void) * The following routines may need porting on non-IBM PC architectures */ +/* + * This function gets called by the keyboard interrupt handler. + * As it's called within an interrupt, it may NOT sync. + */ +void ctrl_alt_del(void) +{ + hard_reset_now(); +} + void hard_reset_now(void) { #ifdef CONFIG_ARCH_IBMPC diff --git a/elks/include/arch/system.h b/elks/include/arch/system.h index 444b8454f..ff29b22eb 100644 --- a/elks/include/arch/system.h +++ b/elks/include/arch/system.h @@ -1,6 +1,12 @@ #ifndef __ARCH_8086_SYSTEM_H #define __ARCH_8086_SYSTEM_H +/* sys_reboot flag parameter */ +#define RB_REBOOT 0x0123 /* hard reset */ +#define RB_SHUTDOWN 0x6789 /* halt system */ +#define RB_POWEROFF 0xDEAD /* call BIOS APM */ + +#ifdef __KERNEL__ #include #include @@ -8,8 +14,10 @@ extern byte_t sys_caps; /* system capabilities bits*/ extern seg_t membase; /* start and end segment of available main memory */ extern seg_t memend; -extern unsigned int INITPROC setup_arch(void); -extern void hard_reset_now(void); -extern void apm_shutdown_now(void); +unsigned int INITPROC setup_arch(void); +void ctrl_alt_del(void); +void hard_reset_now(void); +void apm_shutdown_now(void); +#endif #endif diff --git a/elks/include/linuxmt/signal.h b/elks/include/linuxmt/signal.h index 92cfba78f..db0a18343 100644 --- a/elks/include/linuxmt/signal.h +++ b/elks/include/linuxmt/signal.h @@ -221,8 +221,6 @@ typedef unsigned char __sigdisposition_t; #define SIGDISP_CUSTOM ((__sigdisposition_t) 2) #endif -/*@end@*/ - struct __kern_sigaction_struct { __sigdisposition_t sa_dispose; #if UNUSED @@ -234,11 +232,9 @@ struct __kern_sigaction_struct { #ifdef __KERNEL__ struct task_struct; -extern int send_sig(sig_t,struct task_struct *,int); -extern void arch_setup_sighandler_stack(register struct task_struct *, - __kern_sighandler_t,unsigned); -extern void ctrl_alt_del(void); -extern int sys_kill(pid_t, sig_t); +int send_sig(sig_t,struct task_struct *,int); +void arch_setup_sighandler_stack(struct task_struct *, __kern_sighandler_t,unsigned); +int sys_kill(pid_t, sig_t); #endif /* __KERNEL__*/ #endif diff --git a/elks/kernel/sys.c b/elks/kernel/sys.c index 9e8067337..948d2eee8 100644 --- a/elks/kernel/sys.c +++ b/elks/kernel/sys.c @@ -17,79 +17,42 @@ #include #include +#include #include /* - * Indicates whether you can reboot with ctrl-alt-del: the default is yes - */ - -static int C_A_D = 1; - -/* - * Reboot system call: for obvious reasons only root may call it, and even - * root needs to set up some magic numbers in the registers so that some - * mistake won't make this reboot the whole machine. - * - * You can also set the meaning of the ctrl-alt-del-key here. - * * reboot doesn't sync: do that yourself before calling this. */ - int sys_reboot(unsigned int magic, unsigned int magic_too, int flag) { if (!suser()) - return -EPERM; + return -EPERM; - if (magic == 0x1D1E && magic_too == 0xC0DE) { - switch(flag) { - case 0x4567: - flag = 1; - /* fall through*/ - case 0: - C_A_D = flag; - return 0; - case 0x0123: /* reboot*/ -#ifdef CONFIG_BLK_DEV_BHD - bios_disk_park_all(); -#endif - hard_reset_now(); - printk("Reboot failed\n"); - /* fall through*/ - case 0x6789: /* shutdown*/ - sys_kill(1, SIGKILL); - sys_kill(-1, SIGKILL); #ifdef CONFIG_BLK_DEV_BHD - bios_disk_park_all(); + bios_disk_park_all(); #endif - printk("System halted\n"); - do_exit(0); - /* no return*/ - case 0xDEAD: /* poweroff*/ -#ifdef CONFIG_BLK_DEV_BHD - bios_disk_park_all(); -#endif - apm_shutdown_now(); - printk("APM shutdown failed\n"); - } + switch(flag) { + case RB_REBOOT: + hard_reset_now(); + printk("Reboot failed\n"); + /* fall through */ + + case RB_SHUTDOWN: +shutdown: + sys_kill(1, SIGKILL); + sys_kill(-1, SIGKILL); + printk("System halted\n"); + do_exit(0); + /* no return*/ + + case RB_POWEROFF: + apm_shutdown_now(); + printk("Poweroff failed\n"); + goto shutdown; } - return -EINVAL; } -/* - * This function gets called by ctrl-alt-del - ie the keyboard interrupt. - * As it's called within an interrupt, it may NOT sync: the only choice - * is whether to reboot at once, or just ignore the ctrl-alt-del. - */ - -void ctrl_alt_del(void) -{ - if (C_A_D) - hard_reset_now(); - - kill_process(1, (sig_t) SIGINT, 1); -} - /* * This function returns the version number associated with this kernel. */ diff --git a/elkscmd/Applications b/elkscmd/Applications index 92cf8df44..dc3bda54b 100644 --- a/elkscmd/Applications +++ b/elkscmd/Applications @@ -87,13 +87,13 @@ sys_utils/chmem :sysutil :720k sys_utils/kill :sysutil :360c :720k sys_utils/ps :sash :sysutil :360k :128k :nocomp sys_utils/ps :::uptime :sysutil :128k :1440k -sys_utils/reboot :sysutil :360k :128k sys_utils/makeboot :sysutil :360k sys_utils/man :sysutil :1200k sys_utils/meminfo :sash :sysutil :360k :128k sys_utils/mouse :sysutil :1200c :1440k sys_utils/passwd :sysutil :1200k -sys_utils/poweroff :sysutil :720k +sys_utils/shutdown :::reboot :sysutil :720k :128k +sys_utils/shutdown :::poweroff :sysutil :720k sys_utils/sercat :sysutil :1400c sys_utils/console :sysutil :1200k #sys_utils/who :sysutil :1200k diff --git a/elkscmd/man/man2/reboot.2 b/elkscmd/man/man2/reboot.2 index eee86c9b4..b77abb91c 100644 --- a/elkscmd/man/man2/reboot.2 +++ b/elkscmd/man/man2/reboot.2 @@ -4,11 +4,11 @@ reboot \- close down the system or reboot .SH SYNTAX .ft B .nf -#define _MINIX_SOURCE 1 -#include +#include +#include -int reboot(int \fIhow\fP) +int reboot(int \fImagic1\fP, int \fImagic2\fP, int \fIhow\fP) .fi .ft P .SH DESCRIPTION @@ -18,27 +18,13 @@ down depending on .IR how : .PP .TP 5 -.BI "reboot(RBT_DEFAULT)" -Default shut-down action, the same as used when CTRL+ALT+DEL is pressed -on the keyboard. -.TP -.BI "reboot(RBT_HALT)" +.BI "reboot(0, 0, RB_SHUTDOWN)" Halt the system. .TP -.BI "reboot(RBT_PANIC)" -Cause a system panic. This is not normally done from user mode, but by -servers using the -.B sys_abort() -kernel call. -.TP -.BI "reboot(RBT_POWEROFF)" +.BI "reboot(0, 0, RB_POWEROFF)" Power off the system if possible, reset otherwise. .TP -.BI "reboot(RBT_REBOOT)" -Reboot the system with a software reset (currently not supported, so -a hardware reset is used). -.TP -.BI "reboot(RBT_RESET)" +.BI "reboot(0, 0, RBT_REBOOT)" Reboot the system with a hardware reset. .PP .B Reboot() @@ -50,7 +36,5 @@ the return value is -1 and an error is indicated by .SH SEE ALSO .BR shutdown (8), .BR reboot (8), -.BR halt (8), +.BR poweroff (8), .BR sync (2). -.SH AUTHOR -Edvard Tuinder (v892231@si.hhs.NL) diff --git a/elkscmd/man/man8/poweroff.8 b/elkscmd/man/man8/poweroff.8 index bfc5db060..e8753bc9f 100644 --- a/elkscmd/man/man8/poweroff.8 +++ b/elkscmd/man/man8/poweroff.8 @@ -3,19 +3,24 @@ poweroff \- power off the system immediately .SH SYNOPSIS .B poweroff +.RB [ -f ] +.SS OPTIONS +.TP 5 +.B \-f +Force poweroff even if root volume cannot be remounted read-only. .SH DESCRIPTION .B Poweroff is a program that allows the superuser to power off the system immediately. A .B sync -and unmount of the root filesystem are performed, and after 3 seconds -have elapsed, the system is powered off. +and unmount of the root filesystem and all other mounted filesystems +are performed, and after 3 seconds have elapsed, the system is powered off. .SH BUGS Not all systems support powering off, in which case the system will remain on but halted. .SH "SEE ALSO" .BR sync (1), .BR unmount (1), -.BR reboot (1), -.BR shutdown (1), +.BR reboot (8), +.BR shutdown (8), .BR reboot (2). diff --git a/elkscmd/man/man8/reboot.8 b/elkscmd/man/man8/reboot.8 index 4008e0229..02262d5d1 100644 --- a/elkscmd/man/man8/reboot.8 +++ b/elkscmd/man/man8/reboot.8 @@ -13,11 +13,11 @@ Force reboot even if root volume cannot be remounted read-only. is a program that allows the superuser to shut down and reboot the system immediately. A .B sync -and unmount of the root filesystem are performed, and if successful, after 3 seconds -have elapsed, the system is rebooted. +and unmount of the root filesystem and all other mounted filesystems +are performed, and after 3 seconds have elapsed, the system is rebooted. .SH "SEE ALSO" .BR sync (1), .BR unmount (1), -.BR shutdown (1), -.BR poweroff (1), +.BR shutdown (8), +.BR poweroff (8), .BR reboot (2). diff --git a/elkscmd/man/man8/shutdown.8 b/elkscmd/man/man8/shutdown.8 index 814351ec5..8dcfde235 100644 --- a/elkscmd/man/man8/shutdown.8 +++ b/elkscmd/man/man8/shutdown.8 @@ -3,16 +3,21 @@ shutdown \- shut down the system quickly .SH SYNOPSIS .B shutdown +.RB [ -f ] +.SS OPTIONS +.TP 5 +.B \-f +Force shutdown even if root volume cannot be remounted read-only. .SH DESCRIPTION .B Shutdown is a program that allows the superuser to shut down the system immediately. A .B sync -and unmount of the root filesystem are performed, and after 3 seconds -have elapsed, the system is halted. +and unmount of the root filesystem and all other mounted filesystems +are performed, and after 3 seconds have elapsed, the system is halted. .SH "SEE ALSO" .BR sync (1), .BR unmount (1), -.BR reboot (1), -.BR poweroff (1), +.BR reboot (8), +.BR poweroff (8), .BR reboot (2). diff --git a/elkscmd/sys_utils/.gitignore b/elkscmd/sys_utils/.gitignore index 88ff861d9..6948e3a80 100644 --- a/elkscmd/sys_utils/.gitignore +++ b/elkscmd/sys_utils/.gitignore @@ -17,9 +17,7 @@ min_init mouse mount passwd -poweroff ps -reboot sercat shutdown sysctl diff --git a/elkscmd/sys_utils/Makefile b/elkscmd/sys_utils/Makefile index 6b09adb8b..8ec593c2c 100644 --- a/elkscmd/sys_utils/Makefile +++ b/elkscmd/sys_utils/Makefile @@ -24,13 +24,11 @@ PRGS = \ mount \ umount \ passwd \ - reboot \ shutdown \ ps \ meminfo \ who \ man \ - poweroff \ chmem \ clock \ unreal16 \ @@ -75,9 +73,6 @@ umount: umount.o passwd: passwd.o $(LD) $(LDFLAGS) -o passwd passwd.o $(LDLIBS) -reboot: reboot.o - $(LD) $(LDFLAGS) -o reboot reboot.o $(LDLIBS) - shutdown: shutdown.o $(LD) $(LDFLAGS) -o shutdown shutdown.o $(LDLIBS) @@ -102,9 +97,6 @@ knl: knl.o man: man.o $(LD) $(LDFLAGS) -o man man.o $(LDLIBS) -poweroff: poweroff.o - $(LD) $(LDFLAGS) -o poweroff poweroff.o $(LDLIBS) - chmem: chmem.o $(TINYPRINTF) $(LD) $(LDFLAGS) -o chmem chmem.o $(TINYPRINTF) $(LDLIBS) diff --git a/elkscmd/sys_utils/poweroff.c b/elkscmd/sys_utils/poweroff.c deleted file mode 100644 index c140fcb48..000000000 --- a/elkscmd/sys_utils/poweroff.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * shutdown.c - * - * Derived from reboot.c by: - * Copyright 2000 Alistair Riddoch - * ajr@ecs.soton.ac.uk - * - * This file may be distributed under the terms of the GNU General Public - * License v2, or at your option any later version. - */ - -/* - * This is a small version of shutdown for use in the ELKS project. - */ - -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - sync(); - if (umount("/")) { - perror("umount"); - return 1; - } - sleep(3); - if (reboot(0x1D1E,0xC0DE,0xDEAD)) { - perror("poweroff"); - return 1; - } - return 0; -} diff --git a/elkscmd/sys_utils/reboot.c b/elkscmd/sys_utils/reboot.c deleted file mode 100644 index 1fbbee2fc..000000000 --- a/elkscmd/sys_utils/reboot.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * reboot.c - * - * Copyright 2000 Alistair Riddoch - * ajr@ecs.soton.ac.uk - * - * This file may be distributed under the terms of the GNU General Public - * License v2, or at your option any later version. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -int try_unmount(dev_t dev) -{ - struct statfs statfs; - if (ustatfs(dev, &statfs, UF_NOFREESPACE) < 0) { - return 0; - } - if (umount(statfs.f_mntonname)) { - perror("umount"); - return 1; - } - return 0; -} - -int main(int argc, char **argv) -{ - int i, ret; - int force = 1; - if (argc < 2 || argv[1][0] != '-' || argv[1][1] != 'f') - force = 0; - - sync(); - for (i = NR_SUPER - 1; i >= 0; --i) { - ret = try_unmount(i); - /* -f forces reboot even if mount fails */ - if (ret && !force) return 1; - } - sleep(3); - if (reboot(0x1D1E,0xC0DE,0x0123)) { - perror("reboot"); - return 1; - } - return 0; -} diff --git a/elkscmd/sys_utils/shutdown.c b/elkscmd/sys_utils/shutdown.c index a8565511a..6d6f7fc58 100644 --- a/elkscmd/sys_utils/shutdown.c +++ b/elkscmd/sys_utils/shutdown.c @@ -1,7 +1,7 @@ /* - * shutdown.c + * reboot/shutdown/poweroff * - * Derived from reboot.c by: + * Original version from * Copyright 2000 Alistair Riddoch * ajr@ecs.soton.ac.uk * @@ -9,42 +9,50 @@ * License v2, or at your option any later version. */ -/* - * This is a small version of shutdown for use in the ELKS project. - */ - #include -#include #include -#include +#include #include #include +#include -int try_unmount(dev_t dev) +static int try_unmount(dev_t dev) { - struct statfs statfs; - if (ustatfs(dev, &statfs, UF_NOFREESPACE) < 0) { - return 0; - } - if (umount(statfs.f_mntonname)) { - perror("umount"); - return 1; - } - return 0; + struct statfs statfs; + + if (ustatfs(dev, &statfs, UF_NOFREESPACE) < 0) { + return 0; + } + if (umount(statfs.f_mntonname)) { + perror("umount"); + return 1; + } + return 0; } int main(int argc, char **argv) { - int i, ret; - sync(); - for (i = NR_SUPER - 1; i >= 0; --i) { - ret = try_unmount(i); - if (ret) return 1; - } - sleep(3); - if (reboot(0x1D1E,0xC0DE,0x6789)) { - perror("shutdown"); - return 1; - } - return 0; + int i, force, flag, ret; + char *progname; + + force = (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 'f'); + if ((progname = strrchr(argv[0], '/')) != NULL) + progname++; + else progname = argv[0]; + flag = !strcmp(progname, "reboot")? RB_REBOOT : + !strcmp(progname, "poweroff")? RB_POWEROFF: + RB_SHUTDOWN; + + sync(); + for (i = NR_SUPER - 1; i >= 0; --i) { + ret = try_unmount(i); + if (ret && !force) /* -f forces reboot even if mount fails */ + return 1; + } + sleep(2); + if (reboot(0, 0, flag)) { + perror(progname); + return 1; + } + return 0; } diff --git a/libc/include/sys/mount.h b/libc/include/sys/mount.h index 1f01ad1d3..5989a1538 100644 --- a/libc/include/sys/mount.h +++ b/libc/include/sys/mount.h @@ -24,6 +24,6 @@ int umount(const char *dir); int ustatfs(dev_t dev, struct statfs *statfs, int flags); -int reboot(int magic1, int magic2, int magic3); +int reboot(int magic1, int magic2, int how); #endif