From ad17a7b43803793a18ad181dc30763a089acdec8 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 1 Sep 2018 22:15:15 +0100 Subject: [PATCH] reboot; add a polite (when possible) shutdown command --- Applications/util/fuzix-util.pkg | 1 + Applications/util/reboot.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Applications/util/fuzix-util.pkg b/Applications/util/fuzix-util.pkg index f56fa9e8..ae885ce6 100644 --- a/Applications/util/fuzix-util.pkg +++ b/Applications/util/fuzix-util.pkg @@ -88,6 +88,7 @@ f 0755 /bin/passwd passwd f 0755 /bin/prtroot prtroot f 0755 /bin/reboot reboot l /bin/reboot /bin/halt +l /bin/reboot /bin/shutdown f 0755 /bin/sed sed f 0755 /bin/seq seq f 0755 /bin/setdate setdate diff --git a/Applications/util/reboot.c b/Applications/util/reboot.c index 6cff3eb7..e61bd668 100644 --- a/Applications/util/reboot.c +++ b/Applications/util/reboot.c @@ -5,6 +5,16 @@ #include #include #include +#include + +static int telinit6(void) +{ + int fd = open("/var/run/initctl", O_WRONLY|O_TRUNC|O_CREAT, 0600); + if (fd < 0 || write(fd, "\006", 1) != 1 || close(fd) == -1 || + kill(1, SIGUSR1) < 0) + return 0; + return 1; +} int main(int argc, char *argv[]) { @@ -22,7 +32,12 @@ int main(int argc, char *argv[]) write(2, "unexpected argument.\n", 21); exit(1); } - + /* shutdown does a polite shutdown */ + if (strcmp(p, "shutdown") == 0) { + if (telinit6()) + exit(0); + write(2, "unable to talk to init.\n", 24); + } if (strcmp(p, "halt") == 0) uadmin(A_SHUTDOWN, pv, 0); else -- 2.34.1