Skip to content

Commit

Permalink
Use custom shutdown program to safely shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nyxkrage committed Dec 16, 2022
1 parent de6f783 commit 0ad63a8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tmp/

rootfs
rootfs_mnt/
shutdown/shutdown
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ $ make install
$ popd
```

# Shutdown and Reboot utilities

``` shellsession
$ pushd shutdown
$ gcc -static shutdown.c -o shutdown
$ popd
```

# Finishing steps

``` shellsession
Expand Down
2 changes: 1 addition & 1 deletion make_emacs_rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mke2fs $ROOTFS
mkdir -p $ROOTFS_MNT
sudo mount -o loop $ROOTFS $ROOTFS_MNT

rfs_mkdir bin/ boot/ dev/ etc/ lib/ proc/ run/ sbin/ tmp/
rfs_mkdir bin/ boot/ dev/ etc/ lib/ proc/ run/ sbin/ sys/ tmp/
sudo ln -s . "$ROOTFS_MNT/usr"
sudo mknod -m 600 "$ROOTFS_MNT/dev/console" c 5 1
sudo mknod -m 666 "$ROOTFS_MNT/dev/null" c 1 3
3 changes: 3 additions & 0 deletions setup_emacs_rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ sudo ln "$ROOTFS_MNT/bin/busybox" "$ROOTFS_MNT/sbin/getty"
sudo ln -s ../bin/busybox "$ROOTFS_MNT/sbin/mount"
sudo ln -s ../bin/busybox "$ROOTFS_MNT/sbin/umount"
sudo cp -r ncurses/build/share/terminfo/ "$ROOTFS_MNT/share/"
sudo cp -r .emacs.d "$ROOTFS_MNT/"
sudo cp shutdown/shutdown "$ROOTFS_MNT/sbin/shutdown"
sudo ln -s shutdown "$ROOTFS_MNT/sbin/reboot"
14 changes: 14 additions & 0 deletions shutdown/shutdown.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <sys/reboot.h>
#include <string.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
if (strcmp(argv[0], "/sbin/shutdown") == 0) {
reboot(RB_POWER_OFF);
return 0;
} else if (strcmp(argv[0], "/sbin/reboot") == 0) {
reboot(RB_AUTOBOOT);
return 0;
}
return 1;
}

0 comments on commit 0ad63a8

Please sign in to comment.