reboot; add a polite (when possible) shutdown command
authorAlan Cox <alan@linux.intel.com>
Sat, 1 Sep 2018 21:15:15 +0000 (22:15 +0100)
committerAlan Cox <alan@linux.intel.com>
Sat, 1 Sep 2018 21:15:15 +0000 (22:15 +0100)
Applications/util/fuzix-util.pkg
Applications/util/reboot.c

index f56fa9e..ae885ce 100644 (file)
@@ -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
index 6cff3eb..e61bd66 100644 (file)
@@ -5,6 +5,16 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
+
+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