From 66696abd489b055407c70fe71e03340aa4115da7 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 31 Dec 1999 19:00:43 -0500 Subject: super-fast magic sysrq shutdown --- instr-daemon.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'instr-daemon.c') 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 #include #include +#include #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; } -- cgit