diff options
Diffstat (limited to 'instr-daemon.c')
-rw-r--r-- | instr-daemon.c | 18 |
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 (); |