diff --git a/elks/include/arch/system.h b/elks/include/arch/system.h index cec2ebcab..ff29b22eb 100644 --- a/elks/include/arch/system.h +++ b/elks/include/arch/system.h @@ -1,14 +1,15 @@ #ifndef __ARCH_8086_SYSTEM_H #define __ARCH_8086_SYSTEM_H -#include -#include - /* 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 + extern byte_t sys_caps; /* system capabilities bits*/ extern seg_t membase; /* start and end segment of available main memory */ extern seg_t memend; @@ -17,5 +18,6 @@ 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/elkscmd/sys_utils/reboot.c b/elkscmd/sys_utils/reboot.c index 1fbbee2fc..6d6f7fc58 100644 --- a/elkscmd/sys_utils/reboot.c +++ b/elkscmd/sys_utils/reboot.c @@ -1,6 +1,7 @@ /* - * reboot.c + * reboot/shutdown/poweroff * + * Original version from * Copyright 2000 Alistair Riddoch * ajr@ecs.soton.ac.uk * @@ -9,44 +10,49 @@ */ #include -#include #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; - int force = 1; - if (argc < 2 || argv[1][0] != '-' || argv[1][1] != 'f') - force = 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); - /* -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; + 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; }