mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 03:08:15 +00:00
Add SIGCHLD handler to pause container
This allows pause to reap zombies in the upcoming Shared PID namespace (#1615). Uses the better defined sigaction() instead of signal() for all signals both for consistency (SIGCHLD handler avoids SA_RESTART) and to avoid the implicit signal()->sigaction() translation of various libc versions. Also makes warnings errors and includes a tool to make orphaned zombies for manual testing.
This commit is contained in:
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void sigdown(int signo) {
|
||||
@@ -24,12 +26,23 @@ static void sigdown(int signo) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void sigreap(int signo) {
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (signal(SIGINT, sigdown) == SIG_ERR)
|
||||
if (getpid() != 1) {
|
||||
fprintf(stderr, "Warning: pause should be the first process in a pod\n");
|
||||
}
|
||||
|
||||
if (sigaction(SIGINT, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0)
|
||||
return 1;
|
||||
if (signal(SIGTERM, sigdown) == SIG_ERR)
|
||||
if (sigaction(SIGTERM, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0)
|
||||
return 2;
|
||||
signal(SIGKILL, sigdown);
|
||||
if (sigaction(SIGCHLD, &(struct sigaction){.sa_handler = sigreap, .sa_flags = SA_NOCLDSTOP}, NULL) < 0)
|
||||
return 3;
|
||||
sigaction(SIGKILL, &(struct sigaction){.sa_handler = sigdown}, NULL);
|
||||
|
||||
for (;;) pause();
|
||||
fprintf(stderr, "error: infinite loop terminated\n");
|
||||
return 42;
|
||||
|
||||
Reference in New Issue
Block a user