Address style comments for pause.c

Run clang-format on the C files and capitalize error messages.
This commit is contained in:
Lee Verberne 2016-11-22 23:13:03 +00:00
parent 81d27aa239
commit c1520e15ff
2 changed files with 32 additions and 28 deletions

View File

@ -22,11 +22,12 @@ limitations under the License.
int main() { int main() {
pid_t pid; pid_t pid;
pid = fork(); pid = fork();
if ( pid == 0 ) { if (pid == 0) {
while ( getppid() > 1 ); while (getppid() > 1)
;
printf("Child exiting: pid=%d ppid=%d\n", getpid(), getppid()); printf("Child exiting: pid=%d ppid=%d\n", getpid(), getppid());
return 0; return 0;
} else if ( pid > 0 ) { } else if (pid > 0) {
printf("Parent exiting: pid=%d ppid=%d\n", getpid(), getppid()); printf("Parent exiting: pid=%d ppid=%d\n", getpid(), getppid());
return 0; return 0;
} }

View File

@ -22,28 +22,31 @@ limitations under the License.
#include <unistd.h> #include <unistd.h>
static void sigdown(int signo) { static void sigdown(int signo) {
psignal(signo, "shutting down, got signal"); psignal(signo, "Shutting down, got signal");
exit(0); exit(0);
} }
static void sigreap(int signo) { static void sigreap(int signo) {
while (waitpid(-1, NULL, WNOHANG) > 0); while (waitpid(-1, NULL, WNOHANG) > 0)
;
} }
int main() { int main() {
if (getpid() != 1) { if (getpid() != 1)
fprintf(stderr, "Warning: pause should be the first process in a pod\n"); fprintf(stderr, "Warning: pause should be the first process in a pod\n");
}
if (sigaction(SIGINT, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0) if (sigaction(SIGINT, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0)
return 1; return 1;
if (sigaction(SIGTERM, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0) if (sigaction(SIGTERM, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0)
return 2; return 2;
if (sigaction(SIGCHLD, &(struct sigaction){.sa_handler = sigreap, .sa_flags = SA_NOCLDSTOP}, NULL) < 0) if (sigaction(SIGCHLD, &(struct sigaction){.sa_handler = sigreap,
.sa_flags = SA_NOCLDSTOP},
NULL) < 0)
return 3; return 3;
sigaction(SIGKILL, &(struct sigaction){.sa_handler = sigdown}, NULL); sigaction(SIGKILL, &(struct sigaction){.sa_handler = sigdown}, NULL);
for (;;) pause(); for (;;)
fprintf(stderr, "error: infinite loop terminated\n"); pause();
fprintf(stderr, "Error: infinite loop terminated\n");
return 42; return 42;
} }