Address style comments for pause.c
Run clang-format on the C files and capitalize error messages.
This commit is contained in:
parent
81d27aa239
commit
c1520e15ff
@ -20,16 +20,17 @@ limitations under the License.
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
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());
|
;
|
||||||
return 0;
|
printf("Child exiting: pid=%d ppid=%d\n", getpid(), getppid());
|
||||||
} else if ( pid > 0 ) {
|
return 0;
|
||||||
printf("Parent exiting: pid=%d ppid=%d\n", getpid(), getppid());
|
} else if (pid > 0) {
|
||||||
return 0;
|
printf("Parent exiting: pid=%d ppid=%d\n", getpid(), getppid());
|
||||||
}
|
return 0;
|
||||||
perror("Could not create child");
|
}
|
||||||
return 1;
|
perror("Could not create child");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
return 3;
|
.sa_flags = SA_NOCLDSTOP},
|
||||||
sigaction(SIGKILL, &(struct sigaction){.sa_handler = sigdown}, NULL);
|
NULL) < 0)
|
||||||
|
return 3;
|
||||||
|
sigaction(SIGKILL, &(struct sigaction){.sa_handler = sigdown}, NULL);
|
||||||
|
|
||||||
for (;;) pause();
|
for (;;)
|
||||||
fprintf(stderr, "error: infinite loop terminated\n");
|
pause();
|
||||||
return 42;
|
fprintf(stderr, "Error: infinite loop terminated\n");
|
||||||
|
return 42;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user