internal/outcome/shim: move signal constants
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m7s
Test / Sandbox (race detector) (push) Successful in 4m9s
Test / Hpkg (push) Successful in 4m8s
Test / Hakurei (race detector) (push) Successful in 4m55s
Test / Flake checks (push) Successful in 1m31s
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m7s
Test / Sandbox (race detector) (push) Successful in 4m9s
Test / Hpkg (push) Successful in 4m8s
Test / Hakurei (race detector) (push) Successful in 4m55s
Test / Flake checks (push) Successful in 1m31s
The magic numbers hurt readability. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
3f9f331501
commit
4ee9b5bb84
@ -8,35 +8,32 @@
|
|||||||
static pid_t hakurei_shim_param_ppid = -1;
|
static pid_t hakurei_shim_param_ppid = -1;
|
||||||
static int hakurei_shim_fd = -1;
|
static int hakurei_shim_fd = -1;
|
||||||
|
|
||||||
static ssize_t hakurei_shim_write(const void *buf, size_t count) {
|
static inline ssize_t hakurei_shim_write(hakurei_shim_msg msg) {
|
||||||
int savedErrno = errno;
|
int savedErrno = errno;
|
||||||
ssize_t ret = write(hakurei_shim_fd, buf, count);
|
unsigned char buf = (unsigned char)msg;
|
||||||
|
ssize_t ret = write(hakurei_shim_fd, &buf, 1);
|
||||||
if (ret == -1 && errno != EAGAIN)
|
if (ret == -1 && errno != EAGAIN)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
errno = savedErrno;
|
errno = savedErrno;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see shim_linux.go for handling of the value */
|
/* see shim.go for handling of the value */
|
||||||
static void hakurei_shim_sigaction(int sig, siginfo_t *si, void *ucontext) {
|
static void hakurei_shim_sigaction(int sig, siginfo_t *si, void *ucontext) {
|
||||||
if (sig != SIGCONT || si == NULL) {
|
if (sig != SIGCONT || si == NULL) {
|
||||||
/* unreachable */
|
hakurei_shim_write(HAKUREI_SHIM_INVALID);
|
||||||
hakurei_shim_write("\2", 1);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (si->si_pid == hakurei_shim_param_ppid) {
|
if (si->si_pid == hakurei_shim_param_ppid) {
|
||||||
/* monitor requests shim exit */
|
hakurei_shim_write(HAKUREI_SHIM_EXIT_REQUESTED);
|
||||||
hakurei_shim_write("\0", 1);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unexpected si_pid */
|
hakurei_shim_write(HAKUREI_SHIM_BAD_PID);
|
||||||
hakurei_shim_write("\3", 1);
|
|
||||||
|
|
||||||
if (getppid() != hakurei_shim_param_ppid)
|
if (getppid() != hakurei_shim_param_ppid)
|
||||||
/* shim orphaned before monitor delivers a signal */
|
hakurei_shim_write(HAKUREI_SHIM_ORPHAN);
|
||||||
hakurei_shim_write("\1", 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hakurei_shim_setup_cont_signal(pid_t ppid, int fd) {
|
void hakurei_shim_setup_cont_signal(pid_t ppid, int fd) {
|
||||||
|
|||||||
@ -1,3 +1,14 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
/* hakurei requests shim exit */
|
||||||
|
HAKUREI_SHIM_EXIT_REQUESTED,
|
||||||
|
/* shim orphaned before hakurei delivers a signal */
|
||||||
|
HAKUREI_SHIM_ORPHAN,
|
||||||
|
/* unreachable */
|
||||||
|
HAKUREI_SHIM_INVALID,
|
||||||
|
/* unexpected si_pid */
|
||||||
|
HAKUREI_SHIM_BAD_PID,
|
||||||
|
} hakurei_shim_msg;
|
||||||
|
|
||||||
void hakurei_shim_setup_cont_signal(pid_t ppid, int fd);
|
void hakurei_shim_setup_cont_signal(pid_t ppid, int fd);
|
||||||
|
|||||||
@ -161,7 +161,7 @@ func shimEntrypoint(k syscallDispatcher) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch buf[0] {
|
switch buf[0] {
|
||||||
case 0: // got SIGCONT from monitor: shim exit requested
|
case C.HAKUREI_SHIM_EXIT_REQUESTED: // got SIGCONT from hakurei: shim exit requested
|
||||||
if fp := cancelContainer.Load(); stateParams.params.ForwardCancel && fp != nil && *fp != nil {
|
if fp := cancelContainer.Load(); stateParams.params.ForwardCancel && fp != nil && *fp != nil {
|
||||||
(*fp)()
|
(*fp)()
|
||||||
// shim now bound by ShimWaitDelay, implemented below
|
// shim now bound by ShimWaitDelay, implemented below
|
||||||
@ -171,13 +171,13 @@ func shimEntrypoint(k syscallDispatcher) {
|
|||||||
// setup has not completed, terminate immediately
|
// setup has not completed, terminate immediately
|
||||||
k.exit(hst.ExitRequest)
|
k.exit(hst.ExitRequest)
|
||||||
|
|
||||||
case 1: // got SIGCONT via pdeath_signal: monitor died before delivering signal
|
case C.HAKUREI_SHIM_ORPHAN: // got SIGCONT after orphaned: hakurei died before delivering signal
|
||||||
k.exit(hst.ExitOrphan)
|
k.exit(hst.ExitOrphan)
|
||||||
|
|
||||||
case 2: // unreachable
|
case C.HAKUREI_SHIM_INVALID: // unreachable
|
||||||
msg.Verbose("sa_sigaction got invalid siginfo")
|
msg.Verbose("sa_sigaction got invalid siginfo")
|
||||||
|
|
||||||
case 3: // got SIGCONT from unexpected process: hopefully the terminal driver
|
case C.HAKUREI_SHIM_BAD_PID: // got SIGCONT from unexpected process: hopefully the terminal driver
|
||||||
msg.Verbose("got SIGCONT from unexpected process")
|
msg.Verbose("got SIGCONT from unexpected process")
|
||||||
|
|
||||||
default: // unreachable
|
default: // unreachable
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user