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 From ff3ecc0632fbe0671f000595604e7c1de77f33dc Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Thu, 4 Oct 2012 08:06:25 -0400 Subject: astyle fixes --- instr-daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'instr-daemon.c') diff --git a/instr-daemon.c b/instr-daemon.c index da396bc..f2b9ca2 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -334,7 +334,7 @@ static gboolean periodic_poll (void) write(trgfd, "s\n", 2); // poweroff - system ("/usr/bin/systemctl poweroff -f"); + system ("/usr/bin/systemctl poweroff -f"); } Menu_Check_Buttons (); -- cgit From a0f966ce43e7286d7e033d0b17ab00d6ff6609b5 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Oct 2012 08:28:15 -0400 Subject: wrap flash writes and shutdown sequence in flags --- instr-daemon.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'instr-daemon.c') diff --git a/instr-daemon.c b/instr-daemon.c index f2b9ca2..021eb62 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -317,6 +317,12 @@ static gboolean periodic_poll (void) { if (bus_getpin (POWER_FAIL)) { + globals.Flags.shutdown_started = TRUE; + + while (globals.Flags.flash_write_in_progress) { + g_usleep(1000); + } + LCD_clear(); LCD_write(0,0,"Power failed. Shutdown."); -- cgit