From 6bd6855b589112e3368339e4d82cf0c0a82990ef Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 4 Sep 2024 22:03:03 -0600 Subject: [PATCH] Create hard links of reboot and poweroff to shutdown --- elkscmd/Applications | 4 +-- elkscmd/sys_utils/.gitignore | 2 -- elkscmd/sys_utils/Makefile | 8 ----- elkscmd/sys_utils/poweroff.c | 35 ------------------- elkscmd/sys_utils/reboot.c | 58 ------------------------------ elkscmd/sys_utils/shutdown.c | 68 ++++++++++++++++++++---------------- 6 files changed, 40 insertions(+), 135 deletions(-) delete mode 100644 elkscmd/sys_utils/poweroff.c delete mode 100644 elkscmd/sys_utils/reboot.c diff --git a/elkscmd/Applications b/elkscmd/Applications index 92cf8df44..66ec2f42b 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 :360k :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/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 6d6f7fc58..000000000 --- a/elkscmd/sys_utils/reboot.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * reboot/shutdown/poweroff - * - * Original version from - * 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 - -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; -} - -int main(int argc, char **argv) -{ - 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/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; }