diff options
-rw-r--r-- | instr-daemon.c | 33 |
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; } |