supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* Re: runit SIGPWR support
@ 2020-04-14 16:57 Maxim Vetsalo
  0 siblings, 0 replies; 64+ messages in thread
From: Maxim Vetsalo @ 2020-04-14 16:57 UTC (permalink / raw)
  To: supervision

[-- Attachment #1: Type: text/plain, Size: 229 bytes --]

I patched runit-2.1.2 (ALTLinux build) to handle SIGPWR on systems which support it.
SIGPWR cause immediate system shutdown just like SIGCONT with executable /etc/runit/stopit present in system.
It works with LXD for me.

mx
---

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bod-0001-enable-immediate-shutdown-on-pwr-signal.diff --]
[-- Type: text/x-diff; name="bod-0001-enable-immediate-shutdown-on-pwr-signal.diff", Size: 6981 bytes --]

diff -Naur --new-file a/runit-2.1.2/man/runit.8 b/runit-2.1.2/man/runit.8
--- a/runit-2.1.2/man/runit.8	2020-03-13 23:11:44.080623026 +0300
+++ b/runit-2.1.2/man/runit.8	2020-03-13 23:21:48.188070643 +0300
@@ -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 start shutdown process immediately.
+.P
 if
 .B runit
 receives an INT signal, a ctrl-alt-del keyboard request is triggered.
diff -Naur --new-file a/runit-2.1.2/src/Makefile b/runit-2.1.2/src/Makefile
--- a/runit-2.1.2/src/Makefile	2020-03-13 23:11:44.099622788 +0300
+++ b/runit-2.1.2/src/Makefile	2020-03-13 23:13:44.983111536 +0300
@@ -226,6 +226,9 @@
 hasmkffo.h: choose compile hasmkffo.h1 hasmkffo.h2 load trymkffo.c
 	./choose cl trymkffo hasmkffo.h1 hasmkffo.h2 > hasmkffo.h
 
+hassgpwr.h: choose compile hassgpwr.h1 hassgpwr.h2 load trysgpwr.c
+	./choose cl trysgpwr hassgpwr.h1 hassgpwr.h2 > hassgpwr.h
+
 hassgact.h: choose compile hassgact.h1 hassgact.h2 load trysgact.c
 	./choose cl trysgact hassgact.h1 hassgact.h2 > hassgact.h
 
@@ -311,7 +314,7 @@
 sgetopt.o: buffer.h compile sgetopt.c sgetopt.h subgetopt.h
 	./compile sgetopt.c
 
-sig.o: compile sig.c sig.h
+sig.o: compile sig.c sig.h hassgpwr.h
 	./compile sig.c
 
 sig_block.o: compile hassgprm.h sig.h sig_block.c
@@ -373,12 +376,13 @@
 
 sysdeps: compile direntry.h hasflock.h hasmkffo.h hassgact.h \
 hassgprm.h hasshsgr.h haswaitp.h iopause.h load select.h systype \
-uint64.h reboot_system.h uw_tmp.h socket.lib
+uint64.h reboot_system.h uw_tmp.h socket.lib hassgpwr.h
 	rm -f sysdeps
 	cat systype compile load socket.lib >>sysdeps
 	grep sysdep direntry.h >>sysdeps
 	grep sysdep haswaitp.h >>sysdeps
 	grep sysdep hassgact.h >>sysdeps
+	grep sysdep hassgpwr.h >>sysdeps
 	grep sysdep hassgprm.h >>sysdeps
 	grep sysdep select.h >>sysdeps
 	grep sysdep uint64.h >>sysdeps
diff -Naur --new-file a/runit-2.1.2/src/TARGETS b/runit-2.1.2/src/TARGETS
--- a/runit-2.1.2/src/TARGETS	2018-10-18 12:34:41.000000000 +0300
+++ b/runit-2.1.2/src/TARGETS	2020-03-13 23:13:44.985111511 +0300
@@ -68,6 +68,7 @@
 hasmkffo.h
 hassgact.h
 hassgprm.h
+hassgpwr.h
 hasshsgr.h
 haswaitp.h
 iopause.h
diff -Naur --new-file a/runit-2.1.2/src/hassgpwr.h1 b/runit-2.1.2/src/hassgpwr.h1
--- a/runit-2.1.2/src/hassgpwr.h1	1970-01-01 03:00:00.000000000 +0300
+++ b/runit-2.1.2/src/hassgpwr.h1	2020-03-13 23:13:44.986111499 +0300
@@ -0,0 +1,3 @@
+/* Public domain. */
+
+/* sysdep: -sigpwr */
diff -Naur --new-file a/runit-2.1.2/src/hassgpwr.h2 b/runit-2.1.2/src/hassgpwr.h2
--- a/runit-2.1.2/src/hassgpwr.h2	1970-01-01 03:00:00.000000000 +0300
+++ b/runit-2.1.2/src/hassgpwr.h2	2020-03-13 23:13:44.988111474 +0300
@@ -0,0 +1,4 @@
+/* Public domain. */
+
+/* sysdep: +sigpwr */
+#define HASSIGPWR 1
diff -Naur --new-file a/runit-2.1.2/src/runit.c b/runit-2.1.2/src/runit.c
--- a/runit-2.1.2/src/runit.c	2020-03-13 23:11:44.050623401 +0300
+++ b/runit-2.1.2/src/runit.c	2020-03-13 23:13:44.990111449 +0300
@@ -5,6 +5,7 @@
 #include <signal.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include "hassgpwr.h"
 #include "runit.h"
 #include "sig.h"
 #include "strerr.h"
@@ -30,6 +31,7 @@
 int selfpipe[2];
 int sigc =0;
 int sigi =0;
+int sigp =0;
 
 void sig_cont_handler (void) {
   sigc++;
@@ -39,6 +41,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() {
@@ -73,6 +79,11 @@
   sig_catch(sig_int, sig_int_handler);
   sig_block(sig_pipe);
   sig_block(sig_term);
+#ifdef HASSIGPWR
+  sig_block(sig_pwr);
+  sig_catch(sig_pwr, sig_pwr_handler);
+#endif
+
 
   /* console */
   if ((ttyfd =open_write("/dev/console")) != -1) {
@@ -136,6 +147,10 @@
       sig_uncatch(sig_int);
       sig_unblock(sig_pipe);
       sig_unblock(sig_term);
+#ifdef HASSIGPWR
+      sig_unblock(sig_pwr);
+      sig_ignore(sig_pwr);
+#endif
             
       strerr_warn3(INFO, "enter stage: ", stage[st], 0);
       execve(*prog, (char *const *)prog, envp);
@@ -150,6 +165,9 @@
       sig_unblock(sig_child);
       sig_unblock(sig_cont);
       sig_unblock(sig_int);
+#ifdef HASSIGPWR
+      sig_unblock(sig_pwr);
+#endif
 #ifdef IOPAUSE_POLL
       poll(&x, 1, 14000);
 #else
@@ -161,6 +179,9 @@
       sig_block(sig_cont);
       sig_block(sig_child);
       sig_block(sig_int);
+#ifdef HASSIGPWR
+      sig_block(sig_pwr);
+#endif
       
       while (read(selfpipe[0], &ch, 1) == 1) {}
       while ((child =wait_nohang(&wstat)) > 0)
@@ -211,7 +232,7 @@
       }
 
       /* sig? */
-      if (!sigc  && !sigi) {
+      if (!sigc  && !sigi && !sigp) {
 #ifdef DEBUG
         strerr_warn2(WARNING, "poll: ", &strerr_sys);
 #endif
@@ -219,7 +240,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 +265,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);
@@ -280,13 +301,13 @@
           if (wait_pid(&wstat, pid) == -1)
             strerr_warn2(WARNING, "wait_pid: ", &strerr_sys);
         }
-        sigc =0;
+        sigc =sigp =0;
         strerr_warn3(INFO, "leave stage: ", stage[st], 0);
 
         /* enter stage 3 */
         break;
       }
-      sigc =sigi =0;
+      sigc =sigi =sigp =0;
 #ifdef DEBUG
       strerr_warn2(WARNING, "no request.", 0);
 #endif
diff -Naur --new-file a/runit-2.1.2/src/sig.c b/runit-2.1.2/src/sig.c
--- a/runit-2.1.2/src/sig.c	2018-10-18 12:34:41.000000000 +0300
+++ b/runit-2.1.2/src/sig.c	2020-03-13 23:13:44.991111436 +0300
@@ -1,6 +1,7 @@
 /* Public domain. */
 
 #include <signal.h>
+#include "hassgpwr.h"
 #include "sig.h"
 
 int sig_alarm = SIGALRM;
@@ -11,5 +12,9 @@
 int sig_pipe = SIGPIPE;
 int sig_term = SIGTERM;
 
+#ifdef HASSIGPWR
+int sig_pwr = SIGPWR;
+#endif
+
 void (*sig_defaulthandler)() = SIG_DFL;
 void (*sig_ignorehandler)() = SIG_IGN;
diff -Naur --new-file a/runit-2.1.2/src/sig.h b/runit-2.1.2/src/sig.h
--- a/runit-2.1.2/src/sig.h	2018-10-18 12:34:41.000000000 +0300
+++ b/runit-2.1.2/src/sig.h	2020-03-13 23:13:44.993111411 +0300
@@ -11,6 +11,10 @@
 extern int sig_pipe;
 extern int sig_term;
 
+#ifdef HASSIGPWR
+extern int sig_pwr;
+#endif
+
 extern void (*sig_defaulthandler)();
 extern void (*sig_ignorehandler)();
 
diff -Naur --new-file a/runit-2.1.2/src/trysgpwr.c b/runit-2.1.2/src/trysgpwr.c
--- a/runit-2.1.2/src/trysgpwr.c	1970-01-01 03:00:00.000000000 +0300
+++ b/runit-2.1.2/src/trysgpwr.c	2020-03-13 23:13:44.994111399 +0300
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include <signal.h>
+
+main()
+{
+    int sg = SIGPWR;
+}

^ permalink raw reply	[flat|nested] 64+ messages in thread
* runit SIGPWR support
@ 2020-01-23 20:44 innerspacepilot
  2020-01-31  4:39 ` Colin Booth
  0 siblings, 1 reply; 64+ messages in thread
From: innerspacepilot @ 2020-01-23 20:44 UTC (permalink / raw)
  To: supervision

Hello!

Would you please implement handling of SIGPWR in runit's init to make
LXD containers shut down properly.
More info here https://github.com/lxc/lxd/issues/1183


Thank you.




^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2020-04-14 16:57 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1beb6e35-d4be-60b8-fc52-af666c4fffe3@gmx.com>
2020-02-12 14:25 ` runit SIGPWR support innerspacepilot
2020-02-12 21:54   ` Colin Booth
2020-02-12 22:16     ` Dewayne Geraghty
2020-02-14  9:38     ` Jeff
2020-02-14 12:38       ` Steve Litt
2020-02-15 10:47       ` fungal-net
2020-02-14 10:08     ` Jeff
2020-02-14 10:46     ` Jeff
2020-02-14 12:29       ` innerspacepilot
2020-02-14 12:45         ` Steve Litt
     [not found]           ` <CALZWFRLvtofWfP4kzxJ8_8_K3nzebPjCR-NsJ2MU22cSuaOLng@mail.gmail.com>
     [not found]             ` <20200214182241.15614126@mydesk.domain.cxm>
2020-02-17 19:46               ` Cameron Nemo
2020-02-23 16:11                 ` Jeff
2020-02-17 14:39         ` Jeff
2020-02-14 14:02       ` Casper Ti. Vector
2020-02-17 14:45     ` Jeff
2020-02-17 14:50       ` Jeff
2020-02-14 13:15   ` Casper Ti. Vector
2020-02-14 13:39     ` innerspacepilot
2020-02-14 13:57       ` Casper Ti. Vector
2020-02-14 14:06         ` innerspacepilot
2020-02-14 14:25           ` Casper Ti. Vector
2020-02-14 18:30       ` Laurent Bercot
2020-02-17 10:00         ` innerspacepilot
2020-02-17 15:13           ` Jeff
2020-02-18  9:39             ` Laurent Bercot
2020-02-20 20:39               ` Serge E. Hallyn
2020-02-23 16:51               ` Jeff
2020-02-23 23:53                 ` Laurent Bercot
2020-02-24  6:31                   ` innerspacepilot
2020-02-24 10:23                     ` Laurent Bercot
2020-02-24 13:00                       ` Jeff
2020-02-24 19:53                         ` Laurent Bercot
2020-02-24 13:12                       ` innerspacepilot
2020-02-24 15:26                         ` Serge E. Hallyn
2020-02-26  8:07                           ` innerspacepilot
2020-02-28  6:39                             ` Jan Braun
2020-02-28  9:45                               ` Alex Suykov
2020-02-28 23:50                                 ` fungal-net
2020-02-29 13:44                                 ` Jonathan de Boyne Pollard
2020-02-29 18:20                             ` Guillermo
2020-03-06 20:07                               ` innerspacepilot
2020-03-06 20:09                               ` innerspacepilot
2020-02-25  8:39                       ` Jonathan de Boyne Pollard
2020-02-24 21:13                   ` Guillermo
2020-02-24 22:25                     ` Laurent Bercot
2020-02-24 22:49                       ` Laurent Bercot
2020-02-24 23:08                         ` Guillermo
2020-02-25  1:48                           ` Laurent Bercot
2020-02-25  9:08                             ` Jonathan de Boyne Pollard
2020-02-25 18:38                               ` Guillermo
2020-03-16 12:49                               ` Jeff
2020-03-16 17:13                               ` Jeff
2020-02-24 23:03                       ` Guillermo
2020-03-16 12:31                       ` Jeff
2020-03-16 18:03                         ` Laurent Bercot
2020-02-23 17:31               ` Jeff
2020-02-24  0:33                 ` Laurent Bercot
2020-02-14 19:08   ` John W Higgins
2020-02-14 23:18     ` Laurent Bercot
2020-02-14 23:38       ` John W Higgins
2020-02-15  2:15         ` Laurent Bercot
2020-04-14 16:57 Maxim Vetsalo
  -- strict thread matches above, loose matches on Subject: below --
2020-01-23 20:44 innerspacepilot
2020-01-31  4:39 ` Colin Booth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).