Commit 763c8ead authored by David Johnson's avatar David Johnson

Add systemd sigrtmin3/container compat to runit; customize pkg versions.

systemd has a behavior that is very nice for containers.  If you send it
SIGRTMIN+3 (37 on some Linux systems), it will halt the machine (see
https://www.freedesktop.org/software/systemd/man/systemd.html).
Further, if the env var "container" is set, systemd will actually exit.

9001-systemd-sigrtmin3-compat.diff adds this functionality to runit.
Prior to this, runit would of course just sit and spin after entering
stage 3 (its halt/shutdown/reboot target).  Now if the env var
"container" is set, runit will exit.  Plus runit can be signaled by
Docker (or whatever container manager) to shutdown immediately via
SIGRTMIN+3.

(Also, this commit adds the custom "emulab" bit into the package version
strings.)
parent 77442216
runit (2.1.2-5emulab1) unstable; urgency=medium
* Add systemd sigrtmin3/container compatibility.
-- David M. Johnson <johnsond@flux.utah.edu> Mon, 1 May 2016 16:24:24 +0800
runit (2.1.2-4) unstable; urgency=medium
* New maintainer
......
diff -Nurb a/runit-2.1.2/src/runit.c b/runit-2.1.2/src/runit.c
--- a/runit-2.1.2/src/runit.c 2017-05-01 13:20:59.791113954 -0600
+++ b/runit-2.1.2/src/runit.c 2017-05-01 16:04:47.640637143 -0600
@@ -5,6 +5,7 @@
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
+#include <string.h>
#include "runit.h"
#include "sig.h"
#include "strerr.h"
@@ -30,6 +31,14 @@
int selfpipe[2];
int sigc =0;
int sigi =0;
+extern int sig_rtmin3;
+int sigrt3 =0;
+int incontainer =0;
+
+void sig_rtmin3_handler (void) {
+ sigrt3++;
+ write(selfpipe[1], "", 1);
+}
void sig_cont_handler (void) {
sigc++;
@@ -59,6 +68,16 @@
char ch;
int ttyfd;
struct stat s;
+ char * const *chptr;
+
+ chptr = envp;
+ while (chptr != NULL && *chptr) {
+ if (*chptr && strncmp("container",*chptr,strlen("container")) == 0) {
+ incontainer = 1;
+ break;
+ }
+ ++chptr;
+ }
if (getpid() != 1) strerr_die2x(111, FATAL, "must be run as process no 1.");
setsid();
@@ -73,6 +92,9 @@
sig_catch(sig_int, sig_int_handler);
sig_block(sig_pipe);
sig_block(sig_term);
+ sig_rtmin3 = SIGRTMIN + 3;
+ sig_block(sig_rtmin3);
+ sig_catch(sig_rtmin3, sig_rtmin3_handler);
/* console */
if ((ttyfd =open_write("/dev/console")) != -1) {
@@ -136,6 +158,8 @@
sig_uncatch(sig_int);
sig_unblock(sig_pipe);
sig_unblock(sig_term);
+ sig_unblock(sig_rtmin3);
+ sig_ignore(sig_rtmin3);
strerr_warn3(INFO, "enter stage: ", stage[st], 0);
execve(*prog, (char *const *)prog, envp);
@@ -150,6 +174,7 @@
sig_unblock(sig_child);
sig_unblock(sig_cont);
sig_unblock(sig_int);
+ sig_unblock(sig_rtmin3);
#ifdef IOPAUSE_POLL
poll(&x, 1, 14000);
#else
@@ -161,6 +186,7 @@
sig_block(sig_cont);
sig_block(sig_child);
sig_block(sig_int);
+ sig_block(sig_rtmin3);
while (read(selfpipe[0], &ch, 1) == 1) {}
while ((child =wait_nohang(&wstat)) > 0)
@@ -211,7 +237,7 @@
}
/* sig? */
- if (!sigc && !sigi) {
+ if (!sigc && !sigi && !sigrt3) {
#ifdef DEBUG
strerr_warn2(WARNING, "poll: ", &strerr_sys);
#endif
@@ -219,7 +245,7 @@
}
if (st != 1) {
strerr_warn2(WARNING, "signals only work in stage 2.", 0);
- sigc =sigi =0;
+ sigc =sigi =sigrt3 =0;
continue;
}
if (sigi && (stat(CTRLALTDEL, &s) != -1) && (s.st_mode & S_IXUSR)) {
@@ -244,9 +270,10 @@
sigi =0;
sigc++;
}
- if (sigc && (stat(STOPIT, &s) != -1) && (s.st_mode & S_IXUSR)) {
+ if (sigrt3 || (sigc && (stat(STOPIT, &s) != -1) && (s.st_mode & S_IXUSR))) {
int i;
/* unlink(STOPIT); */
+ if (sigc)
chmod(STOPIT, 0);
/* kill stage 2 */
@@ -344,8 +371,8 @@
}
#endif
- for (;;) sig_pause();
- /* not reached */
+ if (!incontainer) for (;;) sig_pause();
+ /* not reached (unless container) */
strerr_die2x(0, INFO, "exit.");
return(0);
}
diff -Nurb a/runit-2.1.2/src/sig.c b/runit-2.1.2/src/sig.c
--- a/runit-2.1.2/src/sig.c 2014-08-10 12:22:34.000000000 -0600
+++ b/runit-2.1.2/src/sig.c 2017-05-01 13:30:28.014086386 -0600
@@ -10,6 +10,7 @@
int sig_int = SIGINT;
int sig_pipe = SIGPIPE;
int sig_term = SIGTERM;
+int sig_rtmin3;
void (*sig_defaulthandler)() = SIG_DFL;
void (*sig_ignorehandler)() = SIG_IGN;
diff -Nurb a/runit-2.1.2/src/sig.h b/runit-2.1.2/src/sig.h
--- a/runit-2.1.2/src/sig.h 2014-08-10 12:22:35.000000000 -0600
+++ b/runit-2.1.2/src/sig.h 2017-05-01 13:30:35.918086002 -0600
@@ -10,6 +10,7 @@
extern int sig_int;
extern int sig_pipe;
extern int sig_term;
+extern int sig_rtmin3;
extern void (*sig_defaulthandler)();
extern void (*sig_ignorehandler)();
......@@ -6,6 +6,8 @@
## This package understands the following switches:
## --with dietlibc ... statically links against dietlibc
%define dist emulab1
Name: runit
Version: 2.1.2
Release: 1%{?_with_dietlibc:diet}%{?dist}
......@@ -25,6 +27,7 @@ Patch: 0001-default-directory-for-services-on-Debian-is-etc-servi.diff
Patch1: 0002-support-etc-runit-nosync-file-to-make-sync-on-shutdow.diff
Patch2: 0003-utmpset.c-mixes-int32_t-and-time_t.diff
Patch3: 0004-src-Makefile-don-t-use-static-to-link-runit-runit-ini.diff
Patch9001: 9001-systemd-sigrtmin3-compat.diff
Obsoletes: runit <= %{version}-%{release}
Provides: runit = %{version}-%{release}
......@@ -64,6 +67,7 @@ popd
%patch1 -p2
%patch2 -p2
%patch3 -p2
%patch9001 -p2
%build
sh package/compile
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment