2014-08-13 00:21:39 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2014-08-13 00:21:39 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-04-20 21:07:06 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-11-14 11:30:33 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2016-04-20 21:07:06 +00:00
|
|
|
#include <unistd.h>
|
2014-07-19 07:09:43 +00:00
|
|
|
|
2016-04-20 21:07:06 +00:00
|
|
|
static void sigdown(int signo) {
|
|
|
|
psignal(signo, "shutting down, got signal");
|
|
|
|
exit(0);
|
|
|
|
}
|
2014-10-03 15:36:08 +00:00
|
|
|
|
2016-11-14 11:30:33 +00:00
|
|
|
static void sigreap(int signo) {
|
|
|
|
while (waitpid(-1, NULL, WNOHANG) > 0);
|
|
|
|
}
|
|
|
|
|
2016-04-20 21:07:06 +00:00
|
|
|
int main() {
|
2016-11-14 11:30:33 +00:00
|
|
|
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)
|
2016-04-20 21:07:06 +00:00
|
|
|
return 1;
|
2016-11-14 11:30:33 +00:00
|
|
|
if (sigaction(SIGTERM, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0)
|
2016-04-20 21:07:06 +00:00
|
|
|
return 2;
|
2016-11-14 11:30:33 +00:00
|
|
|
if (sigaction(SIGCHLD, &(struct sigaction){.sa_handler = sigreap, .sa_flags = SA_NOCLDSTOP}, NULL) < 0)
|
|
|
|
return 3;
|
|
|
|
sigaction(SIGKILL, &(struct sigaction){.sa_handler = sigdown}, NULL);
|
|
|
|
|
2016-04-20 21:07:06 +00:00
|
|
|
for (;;) pause();
|
|
|
|
fprintf(stderr, "error: infinite loop terminated\n");
|
|
|
|
return 42;
|
2014-07-19 07:09:43 +00:00
|
|
|
}
|