1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
From: Dmitry Bogatov <KAction@debian.org>
Date: Tue, 12 Mar 2019 19:13:48 +0000
Forwarded: <no>
Subject: Shutdown when runit-init receices SIGPWR
Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%23923924
---
runit-2.2.0/man/runit.8 | 6 ++++++
runit-2.2.0/src/runit.c | 17 +++++++++++++----
runit-2.2.0/src/sig.c | 5 +++++
runit-2.2.0/src/sig.h | 1 +
4 files changed, 25 insertions(+), 4 deletions(-)
--- a/runit-2.2.0/man/runit.8
+++ b/runit-2.2.0/man/runit.8
@@ -75,6 +75,12 @@
.B runit
is told to shutdown the system.
.P
+If
+.B runit
+receives a PWR signal,
+.B runit
+is told to shutdown the system.
+.P
if
.B runit
receives an INT signal, a ctrl-alt-del keyboard request is triggered.
--- a/runit-2.2.0/src/runit.c
+++ b/runit-2.2.0/src/runit.c
@@ -30,6 +30,7 @@
int selfpipe[2];
int sigc =0;
int sigi =0;
+int sigp =0;
void sig_cont_handler (void) {
sigc++;
@@ -39,6 +40,10 @@
sigi++;
write(selfpipe[1], "", 1);
}
+void sig_pwr_handler (void) {
+ sigp++;
+ write(selfpipe[1], "", 1);
+}
void sig_child_handler (void) { write(selfpipe[1], "", 1); }
void sync_if_needed() {
@@ -71,6 +76,8 @@
sig_block(sig_hangup);
sig_block(sig_int);
sig_catch(sig_int, sig_int_handler);
+ sig_block(sig_pwr);
+ sig_catch(sig_pwr, sig_pwr_handler);
sig_block(sig_pipe);
sig_block(sig_term);
@@ -150,6 +157,7 @@
sig_unblock(sig_child);
sig_unblock(sig_cont);
sig_unblock(sig_int);
+ sig_unblock(sig_pwr);
#ifdef IOPAUSE_POLL
poll(&x, 1, 14000);
#else
@@ -161,6 +169,7 @@
sig_block(sig_cont);
sig_block(sig_child);
sig_block(sig_int);
+ sig_block(sig_pwr);
while (read(selfpipe[0], &ch, 1) == 1) {}
while ((child =wait_nohang(&wstat)) > 0)
@@ -211,7 +220,7 @@
}
/* sig? */
- if (!sigc && !sigi) {
+ if (!sigc && !sigi && !sigp) {
#ifdef DEBUG
strerr_warn2(WARNING, "poll: ", &strerr_sys);
#endif
@@ -219,7 +228,7 @@
}
if (st != 1) {
strerr_warn2(WARNING, "signals only work in stage 2.", 0);
- sigc =sigi =0;
+ sigc =sigi =sigp =0;
continue;
}
if (sigi && (stat(CTRLALTDEL, &s) != -1) && (s.st_mode & S_IXUSR)) {
@@ -244,7 +253,7 @@
sigi =0;
sigc++;
}
- if (sigc && (stat(STOPIT, &s) != -1) && (s.st_mode & S_IXUSR)) {
+ if ((sigp) || (sigc && (stat(STOPIT, &s) != -1) && (s.st_mode & S_IXUSR))) {
int i;
/* unlink(STOPIT); */
chmod(STOPIT, 0);
@@ -286,7 +295,7 @@
/* enter stage 3 */
break;
}
- sigc =sigi =0;
+ sigc =sigi =sigp =0;
#ifdef DEBUG
strerr_warn2(WARNING, "no request.", 0);
#endif
@@ -308,7 +317,7 @@
switch (pid) {
case 0:
case -1:
- if ((stat(REBOOT, &s) != -1) && (s.st_mode & S_IXUSR)) {
+ if ((!sigp) && ((stat(REBOOT, &s) != -1) && (s.st_mode & S_IXUSR))) {
strerr_warn2(INFO, "system reboot.", 0);
sync_if_needed();
reboot_system(RB_AUTOBOOT);
--- a/runit-2.2.0/src/sig.c
+++ b/runit-2.2.0/src/sig.c
@@ -3,12 +3,17 @@
#include <signal.h>
#include "sig.h"
+#ifndef SIGPWR
+#define SIGPWR SIGUSR2 /* as in sysvinit */
+#endif
+
int sig_alarm = SIGALRM;
int sig_child = SIGCHLD;
int sig_cont = SIGCONT;
int sig_hangup = SIGHUP;
int sig_int = SIGINT;
int sig_pipe = SIGPIPE;
+int sig_pwr = SIGPWR;
int sig_term = SIGTERM;
void (*sig_defaulthandler)() = SIG_DFL;
--- a/runit-2.2.0/src/sig.h
+++ b/runit-2.2.0/src/sig.h
@@ -9,6 +9,7 @@
extern int sig_hangup;
extern int sig_int;
extern int sig_pipe;
+extern int sig_pwr;
extern int sig_term;
extern void (*sig_defaulthandler)();
|