summaryrefslogtreecommitdiff
path: root/instr-daemon.c
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2012-10-04 04:43:58 +0900
committerdaniel <danieruru@gmail.com>2012-10-04 04:43:58 +0900
commitdb682a18e8c7b1711f101d655a4f12e53c71b73d (patch)
tree270152e11d0e78a48226869940228446f4d98f3a /instr-daemon.c
parent69d7ac58e532e5e51cf65c7d127fafddb812167d (diff)
use sysrq to do an emergency shutdown
Diffstat (limited to 'instr-daemon.c')
-rw-r--r--instr-daemon.c18
1 files changed, 16 insertions, 2 deletions
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 <ctype.h>
#include <glib.h>
#include <unistd.h>
+#include <fcntl.h>
#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 ();