summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 19:00:43 -0500
committerroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 19:00:43 -0500
commit66696abd489b055407c70fe71e03340aa4115da7 (patch)
tree265e2302288c25172453558dc6435307cbdf18ef
parent58b03f6b9bd96fb6de58e9a75b9af5fab7e3fab0 (diff)
super-fast magic sysrq shutdown
-rw-r--r--instr-daemon.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/instr-daemon.c b/instr-daemon.c
index 24c6132..da396bc 100644
--- a/instr-daemon.c
+++ b/instr-daemon.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <glib.h>
+#include <fcntl.h>
#define STDIN_BUF_SIZE 1024
@@ -315,7 +316,25 @@ int main(int argc, char **argv)
static gboolean periodic_poll (void)
{
if (bus_getpin (POWER_FAIL)) {
- system ("/usr/bin/systemctl poweroff");
+
+ LCD_clear();
+ LCD_write(0,0,"Power failed. Shutdown.");
+
+ // use plain old open to avoid any buffering etc
+ int enablefd = open("/proc/sys/kernel/sysrq", O_SYNC, O_RDWR);
+ int trgfd = open("/proc/sysrq-trigger", O_SYNC, O_RDWR);
+
+ // enable sysrq
+ write(enablefd, "1\n", 2);
+
+ // remount ro
+ write(trgfd, "u\n", 2);
+
+ // sync disks
+ write(trgfd, "s\n", 2);
+
+ // poweroff
+ system ("/usr/bin/systemctl poweroff -f");
}
Menu_Check_Buttons ();
@@ -326,12 +345,12 @@ static gboolean periodic_poll (void)
// is crashing due to non-functional bus
GPIB_check_for_device_clear_signal();
if (GPIB_check_for_messages(globals.Registers.gpib_buffer)) {
- if (GPIB_handle_new_input(globals.Registers.gpib_buffer)) {
- // FIXME check_for_ctrl_mode_changes();
- Parser_main(globals.Registers.gpib_buffer, 0, NULL, NULL);
- }
- }
- GPIB_check_for_device_clear_signal();
+ if (GPIB_handle_new_input(globals.Registers.gpib_buffer)) {
+ // FIXME check_for_ctrl_mode_changes();
+ Parser_main(globals.Registers.gpib_buffer, 0, NULL, NULL);
+ }
+ }
+ GPIB_check_for_device_clear_signal();
return TRUE;
}