未验证 提交 8aafc45d 编写于 作者: T Tom Deseyn 提交者: GitHub

Process.Unix: reap all processes when running as pid 1. (#65061)

* Process.Unix: reap all processes when running as pid 1.

pid 1 (the init daemon) is responsible for reaping orphaned children.
Because containers usually don't have an init daemon .NET may be pid 1.

* pal_signal: also use g_pid when raising signal.
上级 aa4b8ee7
......@@ -38,6 +38,8 @@ static volatile bool* g_hasPosixSignalRegistrations;
static int g_signalPipe[2] = {-1, -1}; // Pipe used between signal handler and worker
static pid_t g_pid;
static int GetSignalMax() // Returns the highest usable signal number.
{
#ifdef SIGRTMAX
......@@ -294,7 +296,7 @@ void SystemNative_HandleNonCanceledPosixSignal(int32_t signalCode)
#ifdef HAS_CONSOLE_SIGNALS
UninitializeTerminal();
#endif
kill(getpid(), signalCode);
kill(g_pid, signalCode);
break;
}
}
......@@ -341,9 +343,15 @@ static void* SignalHandlerLoop(void* arg)
bool usePosixSignalHandler = g_hasPosixSignalRegistrations[signalCode - 1];
if (signalCode == SIGCHLD)
{
// When the original disposition is SIG_IGN, children that terminated did not become zombies.
// Since we overwrote the disposition, we have become responsible for reaping those processes.
bool reapAll = IsSigIgn(OrigActionFor(signalCode));
// By default we only reap managed processes started using the 'Process' class.
// This allows other code to start processes without .NET reaping them.
//
// In two cases we reap all processes (and may inadvertently reap non-managed processes):
// - When the original disposition is SIG_IGN, children that terminated did not become zombies.
// Because overwrote the disposition, we have become responsible for reaping those processes.
// - pid 1 (the init daemon) is responsible for reaping orphaned children.
// Because containers usually don't have an init daemon .NET may be pid 1.
bool reapAll = g_pid == 1 || IsSigIgn(OrigActionFor(signalCode));
SigChldCallback callback = g_sigChldCallback;
// double-checked locking
......@@ -552,6 +560,8 @@ int32_t InitializeSignalHandlingCore()
return 0;
}
g_pid = getpid();
// Create a pipe we'll use to communicate with our worker
// thread. We can't do anything interesting in the signal handler,
// so we instead send a message to another thread that'll do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册