diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2026-06-10 14:49:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-10 14:49:33 +0200 |
| commit | f8aad020f7c0be604da8981663b6d815f94ffaa4 (patch) | |
| tree | e1c7bdeff275778b4dd324d26e826c861d143b48 /config_test | |
| parent | 47b1b2d754d4809006f6dc1aa13ba9c80405975c (diff) | |
| download | monitoring-plugins-f8aad020f7c0be604da8981663b6d815f94ffaa4.tar.gz | |
Run clang-format on everything once again (#2275)
Co-authored-by: Lorenz Kästle <lorenz.kaestle@netways.de>
Diffstat (limited to 'config_test')
| -rw-r--r-- | config_test/child_test.c | 116 |
1 files changed, 59 insertions, 57 deletions
diff --git a/config_test/child_test.c b/config_test/child_test.c index 2add3bcf..21439330 100644 --- a/config_test/child_test.c +++ b/config_test/child_test.c | |||
| @@ -5,73 +5,75 @@ | |||
| 5 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <sys/types.h> | 6 | #include <sys/types.h> |
| 7 | #include <signal.h> | 7 | #include <signal.h> |
| 8 | void popen_sigchld_handler (int); | 8 | void popen_sigchld_handler(int); |
| 9 | int childtermd; | 9 | int childtermd; |
| 10 | 10 | ||
| 11 | int main(){ | 11 | int main() { |
| 12 | char str[1024]; | 12 | char str[1024]; |
| 13 | int pipefd[2]; | 13 | int pipefd[2]; |
| 14 | pid_t pid; | 14 | pid_t pid; |
| 15 | int status, died; | 15 | int status, died; |
| 16 | 16 | ||
| 17 | if (signal (SIGCHLD, popen_sigchld_handler) == SIG_ERR) { | 17 | if (signal(SIGCHLD, popen_sigchld_handler) == SIG_ERR) { |
| 18 | printf ("Cannot catch SIGCHLD\n"); | 18 | printf("Cannot catch SIGCHLD\n"); |
| 19 | _exit(-1); | 19 | _exit(-1); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pipe (pipefd); | 22 | pipe(pipefd); |
| 23 | switch(pid=fork()){ | 23 | switch (pid = fork()) { |
| 24 | case -1: | 24 | case -1: |
| 25 | printf("can't fork\n"); | 25 | printf("can't fork\n"); |
| 26 | _exit(-1); | 26 | _exit(-1); |
| 27 | 27 | ||
| 28 | case 0 : /* this is the code the child runs */ | 28 | case 0: /* this is the code the child runs */ |
| 29 | close(1); /* close stdout */ | 29 | close(1); /* close stdout */ |
| 30 | /* pipefd[1] is for writing to the pipe. We want the output | 30 | /* pipefd[1] is for writing to the pipe. We want the output |
| 31 | * that used to go to the standard output (file descriptor 1) | 31 | * that used to go to the standard output (file descriptor 1) |
| 32 | * to be written to the pipe. The following command does this, | 32 | * to be written to the pipe. The following command does this, |
| 33 | * creating a new file descriptor 1 (the lowest available) | 33 | * creating a new file descriptor 1 (the lowest available) |
| 34 | * that writes where pipefd[1] goes. */ | 34 | * that writes where pipefd[1] goes. */ |
| 35 | dup (pipefd[1]); /* points pipefd at file descriptor */ | 35 | dup(pipefd[1]); /* points pipefd at file descriptor */ |
| 36 | /* the child isn't going to read from the pipe, so | 36 | /* the child isn't going to read from the pipe, so |
| 37 | * pipefd[0] can be closed */ | 37 | * pipefd[0] can be closed */ |
| 38 | close (pipefd[0]); | 38 | close(pipefd[0]); |
| 39 | 39 | ||
| 40 | /* These are the commands to run, with success commented. dig and nslookup only problems */ | 40 | /* These are the commands to run, with success commented. dig and nslookup only problems */ |
| 41 | /*execl ("/bin/date","date",0);*/ /* 100% */ | 41 | /*execl ("/bin/date","date",0);*/ /* 100% */ |
| 42 | /*execl ("/bin/cat", "cat", "/etc/hosts", 0);*/ /* 100% */ | 42 | /*execl ("/bin/cat", "cat", "/etc/hosts", 0);*/ /* 100% */ |
| 43 | /*execl ("/usr/bin/dig", "dig", "redhat.com", 0);*/ /* 69% */ | 43 | /*execl ("/usr/bin/dig", "dig", "redhat.com", 0);*/ /* 69% */ |
| 44 | /*execl("/bin/sleep", "sleep", "1", 0);*/ /* 100% */ | 44 | /*execl("/bin/sleep", "sleep", "1", 0);*/ /* 100% */ |
| 45 | execl ("/usr/bin/nslookup","nslookup","redhat.com",0); /* 90% (after 100 tests), 40% (after 10 tests) */ | 45 | execl("/usr/bin/nslookup", "nslookup", "redhat.com", |
| 46 | /*execl ("/bin/ping","ping","-c","1","localhost",0);*/ /* 100% */ | 46 | 0); /* 90% (after 100 tests), 40% (after 10 tests) */ |
| 47 | /*execl ("/bin/ping","ping","-c","1","192.168.10.32",0);*/ /* 100% */ | 47 | /*execl ("/bin/ping","ping","-c","1","localhost",0);*/ /* 100% */ |
| 48 | _exit(0); | 48 | /*execl ("/bin/ping","ping","-c","1","192.168.10.32",0);*/ /* 100% */ |
| 49 | _exit(0); | ||
| 49 | 50 | ||
| 50 | default: /* this is the code the parent runs */ | 51 | default: /* this is the code the parent runs */ |
| 51 | 52 | ||
| 52 | close(0); /* close stdin */ | 53 | close(0); /* close stdin */ |
| 53 | /* Set file descriptor 0 (stdin) to read from the pipe */ | 54 | /* Set file descriptor 0 (stdin) to read from the pipe */ |
| 54 | dup (pipefd[0]); | 55 | dup(pipefd[0]); |
| 55 | /* the parent isn't going to write to the pipe */ | 56 | /* the parent isn't going to write to the pipe */ |
| 56 | close (pipefd[1]); | 57 | close(pipefd[1]); |
| 57 | /* Now read from the pipe */ | 58 | /* Now read from the pipe */ |
| 58 | fgets(str, 1023, stdin); | 59 | fgets(str, 1023, stdin); |
| 59 | /*printf("1st line output is %s\n", str);*/ | 60 | /*printf("1st line output is %s\n", str);*/ |
| 60 | 61 | ||
| 61 | /*while (!childtermd);*/ /* Uncomment this line to fix */ | 62 | /*while (!childtermd);*/ /* Uncomment this line to fix */ |
| 62 | 63 | ||
| 63 | died= wait(&status); | 64 | died = wait(&status); |
| 64 | /*printf("died=%d status=%d\n", died, status);*/ | 65 | /*printf("died=%d status=%d\n", died, status);*/ |
| 65 | if (died > 0) _exit(0); | 66 | if (died > 0) { |
| 66 | else _exit(1); | 67 | _exit(0); |
| 67 | } | 68 | } else { |
| 69 | _exit(1); | ||
| 70 | } | ||
| 71 | } | ||
| 68 | } | 72 | } |
| 69 | 73 | ||
| 70 | void | 74 | void popen_sigchld_handler(int signo) { |
| 71 | popen_sigchld_handler (int signo) | 75 | if (signo == SIGCHLD) { |
| 72 | { | 76 | /*printf("Caught sigchld\n");*/ |
| 73 | if (signo == SIGCHLD) { | 77 | childtermd = 1; |
| 74 | /*printf("Caught sigchld\n");*/ | 78 | } |
| 75 | childtermd = 1; | ||
| 76 | } | ||
| 77 | } | 79 | } |
