From db682a18e8c7b1711f101d655a4f12e53c71b73d Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 4 Oct 2012 04:43:58 +0900 Subject: use sysrq to do an emergency shutdown --- instr-daemon.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'instr-daemon.c') diff --git a/instr-daemon.c b/instr-daemon.c index 5f764ed..40a65b2 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -15,6 +15,7 @@ #include #include #include +#include #define STDIN_BUF_SIZE 1024 @@ -316,8 +317,21 @@ int main(int argc, char **argv) static gboolean periodic_poll (void) { if (bus_getpin (POWER_FAIL)) { - sync(); - system ("/usr/bin/systemctl poweroff"); + //system ("/usr/bin/systemctl poweroff"); + + // 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); + } Menu_Check_Buttons (); -- cgit