Commit c1520e15 authored by Lee Verberne's avatar Lee Verberne

Address style comments for pause.c

Run clang-format on the C files and capitalize error messages.
parent 81d27aa2
......@@ -20,16 +20,17 @@ limitations under the License.
#include <unistd.h>
int main() {
pid_t pid;
pid = fork();
if ( pid == 0 ) {
while ( getppid() > 1 );
printf("Child exiting: pid=%d ppid=%d\n", getpid(), getppid());
return 0;
} else if ( pid > 0 ) {
printf("Parent exiting: pid=%d ppid=%d\n", getpid(), getppid());
return 0;
}
perror("Could not create child");
return 1;
pid_t pid;
pid = fork();
if (pid == 0) {
while (getppid() > 1)
;
printf("Child exiting: pid=%d ppid=%d\n", getpid(), getppid());
return 0;
} else if (pid > 0) {
printf("Parent exiting: pid=%d ppid=%d\n", getpid(), getppid());
return 0;
}
perror("Could not create child");
return 1;
}
......@@ -22,28 +22,31 @@ limitations under the License.
#include <unistd.h>
static void sigdown(int signo) {
psignal(signo, "shutting down, got signal");
exit(0);
psignal(signo, "Shutting down, got signal");
exit(0);
}
static void sigreap(int signo) {
while (waitpid(-1, NULL, WNOHANG) > 0);
while (waitpid(-1, NULL, WNOHANG) > 0)
;
}
int main() {
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 (sigaction(SIGTERM, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0)
return 2;
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;
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 (sigaction(SIGTERM, &(struct sigaction){.sa_handler = sigdown}, NULL) < 0)
return 2;
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment