Skip to content

Commit

Permalink
Create hard links of reboot and poweroff to shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Sep 5, 2024
1 parent 400df2c commit 6bd6855
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 135 deletions.
4 changes: 2 additions & 2 deletions elkscmd/Applications
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions elkscmd/sys_utils/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ min_init
mouse
mount
passwd
poweroff
ps
reboot
sercat
shutdown
sysctl
Expand Down
8 changes: 0 additions & 8 deletions elkscmd/sys_utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ PRGS = \
mount \
umount \
passwd \
reboot \
shutdown \
ps \
meminfo \
who \
man \
poweroff \
chmem \
clock \
unreal16 \
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
35 changes: 0 additions & 35 deletions elkscmd/sys_utils/poweroff.c

This file was deleted.

58 changes: 0 additions & 58 deletions elkscmd/sys_utils/reboot.c

This file was deleted.

68 changes: 38 additions & 30 deletions elkscmd/sys_utils/shutdown.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
/*
* shutdown.c
* reboot/shutdown/poweroff
*
* Derived from reboot.c by:
* Original version from
* Copyright 2000 Alistair Riddoch
* [email protected]
*
* 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/mount.h>
#include <linuxmt/limits.h>
#include <arch/system.h>

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;
}

0 comments on commit 6bd6855

Please sign in to comment.