diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2005-09-12 10:31:29 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2005-09-12 10:31:29 +0000 |
commit | e85edd9e55d79b7e475f009df64accb65f317905 (patch) | |
tree | 1adf431a06733721b459d673fc1214295f53774a /config_test | |
parent | 3c554b72de0df28175e7ed8a0bcf3b7e509335d9 (diff) | |
download | monitoring-plugins-e85edd9e55d79b7e475f009df64accb65f317905.tar.gz |
ECHILD error at waitpid on Red Hat systems (Peter Pramberger and
Sascha Runschke - 1250191)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1213 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'config_test')
-rw-r--r-- | config_test/Makefile | 10 | ||||
-rw-r--r-- | config_test/child_test.c | 77 | ||||
-rwxr-xr-x | config_test/run_tests | 16 |
3 files changed, 103 insertions, 0 deletions
diff --git a/config_test/Makefile b/config_test/Makefile new file mode 100644 index 00000000..295696e9 --- /dev/null +++ b/config_test/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | |||
2 | all: child_test.c | ||
3 | gcc -o child_test child_test.c | ||
4 | |||
5 | test: | ||
6 | ./run_tests 10 | ||
7 | |||
8 | clean: | ||
9 | rm -f child_test | ||
10 | |||
diff --git a/config_test/child_test.c b/config_test/child_test.c new file mode 100644 index 00000000..e7d82106 --- /dev/null +++ b/config_test/child_test.c | |||
@@ -0,0 +1,77 @@ | |||
1 | // Base code taken from http://www-h.eng.cam.ac.uk/help/tpl/unix/fork.html | ||
2 | // Fix for redhat suggested by Ptere Pramberger, peter@pramberger.at | ||
3 | #include <unistd.h> | ||
4 | #include <sys/wait.h> | ||
5 | #include <stdio.h> | ||
6 | #include <sys/types.h> | ||
7 | #include <signal.h> | ||
8 | void popen_sigchld_handler (int); | ||
9 | int childtermd; | ||
10 | |||
11 | int main(){ | ||
12 | char str[1024]; | ||
13 | int pipefd[2]; | ||
14 | pid_t pid; | ||
15 | int status, died; | ||
16 | |||
17 | if (signal (SIGCHLD, popen_sigchld_handler) == SIG_ERR) { | ||
18 | printf ("Cannot catch SIGCHLD\n"); | ||
19 | _exit(-1); | ||
20 | } | ||
21 | |||
22 | pipe (pipefd); | ||
23 | switch(pid=fork()){ | ||
24 | case -1: | ||
25 | printf("can't fork\n"); | ||
26 | _exit(-1); | ||
27 | |||
28 | case 0 : // this is the code the child runs | ||
29 | close(1); // close stdout | ||
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) | ||
32 | // to be written to the pipe. The following command does this, | ||
33 | // creating a new file descripter 1 (the lowest available) | ||
34 | // that writes where pipefd[1] goes. | ||
35 | dup (pipefd[1]); // points pipefd at file descriptor | ||
36 | // the child isn't going to read from the pipe, so | ||
37 | // pipefd[0] can be closed | ||
38 | close (pipefd[0]); | ||
39 | |||
40 | //These are the commands to run, with success commented. dig and nslookup only problems | ||
41 | //execl ("/bin/date","date",0); // 100% | ||
42 | //execl ("/bin/cat", "cat", "/etc/hosts", 0); // 100% | ||
43 | //execl ("/usr/bin/dig", "dig", "redhat.com", 0); // 69% | ||
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) | ||
46 | //execl ("/bin/ping","ping","-c","1","localhost",0); // 100% | ||
47 | //execl ("/bin/ping","ping","-c","1","192.168.10.32",0); // 100% | ||
48 | _exit(0); | ||
49 | |||
50 | default: // this is the code the parent runs | ||
51 | |||
52 | close(0); // close stdin | ||
53 | // Set file descriptor 0 (stdin) to read from the pipe | ||
54 | dup (pipefd[0]); | ||
55 | // the parent isn't going to write to the pipe | ||
56 | close (pipefd[1]); | ||
57 | // Now read from the pipe | ||
58 | fgets(str, 1023, stdin); | ||
59 | //printf("1st line output is %s\n", str); | ||
60 | |||
61 | //while (!childtermd); // Uncomment this line to fix | ||
62 | |||
63 | died= wait(&status); | ||
64 | //printf("died=%d status=%d\n", died, status); | ||
65 | if (died > 0) _exit(0); | ||
66 | else _exit(1); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | void | ||
71 | popen_sigchld_handler (int signo) | ||
72 | { | ||
73 | if (signo == SIGCHLD) { | ||
74 | //printf("Caught sigchld\n"); | ||
75 | childtermd = 1; | ||
76 | } | ||
77 | } | ||
diff --git a/config_test/run_tests b/config_test/run_tests new file mode 100755 index 00000000..e41db232 --- /dev/null +++ b/config_test/run_tests | |||
@@ -0,0 +1,16 @@ | |||
1 | #!/bin/ksh | ||
2 | |||
3 | i=0 | ||
4 | success=0 | ||
5 | fail=0 | ||
6 | while [[ $i -lt $1 ]] ; do | ||
7 | ./child_test | ||
8 | if [[ $? -eq 0 ]] ; then | ||
9 | success=$(($success+1)) | ||
10 | else | ||
11 | fail=$((fail+1)) | ||
12 | fi | ||
13 | i=$(($i+1)) | ||
14 | done | ||
15 | print "Success=$success Fail=$fail" | ||
16 | [[ $fail -gt 0 ]] && exit 1 | ||