summaryrefslogtreecommitdiffstats
path: root/config_test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:48:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:48:22 +0000
commit7373ce3d6988706388f136e1c06afd20a3e8d5be (patch)
treee9ae5af7d102667e5706187646db45de8238e8c4 /config_test
parentInitial commit. (diff)
downloadmonitoring-plugins-7373ce3d6988706388f136e1c06afd20a3e8d5be.tar.xz
monitoring-plugins-7373ce3d6988706388f136e1c06afd20a3e8d5be.zip
Adding upstream version 2.3.5.upstream/2.3.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'config_test')
-rw-r--r--config_test/Makefile12
-rw-r--r--config_test/child_test.c77
-rwxr-xr-xconfig_test/run_tests30
3 files changed, 119 insertions, 0 deletions
diff --git a/config_test/Makefile b/config_test/Makefile
new file mode 100644
index 0000000..1064d56
--- /dev/null
+++ b/config_test/Makefile
@@ -0,0 +1,12 @@
+
+all: child_test
+
+child_test: child_test.c
+ gcc -o child_test child_test.c
+
+test:
+ ./run_tests 10 100 > /dev/null
+
+clean:
+ rm -f child_test
+
diff --git a/config_test/child_test.c b/config_test/child_test.c
new file mode 100644
index 0000000..2add3bc
--- /dev/null
+++ b/config_test/child_test.c
@@ -0,0 +1,77 @@
+/* Base code taken from http://www-h.eng.cam.ac.uk/help/tpl/unix/fork.html
+ * Fix for redhat suggested by Ptere Pramberger, peter@pramberger.at */
+#include <unistd.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <signal.h>
+void popen_sigchld_handler (int);
+int childtermd;
+
+int main(){
+ char str[1024];
+ int pipefd[2];
+ pid_t pid;
+ int status, died;
+
+ if (signal (SIGCHLD, popen_sigchld_handler) == SIG_ERR) {
+ printf ("Cannot catch SIGCHLD\n");
+ _exit(-1);
+ }
+
+ pipe (pipefd);
+ switch(pid=fork()){
+ case -1:
+ printf("can't fork\n");
+ _exit(-1);
+
+ case 0 : /* this is the code the child runs */
+ close(1); /* close stdout */
+ /* pipefd[1] is for writing to the pipe. We want the output
+ * that used to go to the standard output (file descriptor 1)
+ * to be written to the pipe. The following command does this,
+ * creating a new file descriptor 1 (the lowest available)
+ * that writes where pipefd[1] goes. */
+ dup (pipefd[1]); /* points pipefd at file descriptor */
+ /* the child isn't going to read from the pipe, so
+ * pipefd[0] can be closed */
+ close (pipefd[0]);
+
+ /* These are the commands to run, with success commented. dig and nslookup only problems */
+ /*execl ("/bin/date","date",0);*/ /* 100% */
+ /*execl ("/bin/cat", "cat", "/etc/hosts", 0);*/ /* 100% */
+ /*execl ("/usr/bin/dig", "dig", "redhat.com", 0);*/ /* 69% */
+ /*execl("/bin/sleep", "sleep", "1", 0);*/ /* 100% */
+ execl ("/usr/bin/nslookup","nslookup","redhat.com",0); /* 90% (after 100 tests), 40% (after 10 tests) */
+ /*execl ("/bin/ping","ping","-c","1","localhost",0);*/ /* 100% */
+ /*execl ("/bin/ping","ping","-c","1","192.168.10.32",0);*/ /* 100% */
+ _exit(0);
+
+ default: /* this is the code the parent runs */
+
+ close(0); /* close stdin */
+ /* Set file descriptor 0 (stdin) to read from the pipe */
+ dup (pipefd[0]);
+ /* the parent isn't going to write to the pipe */
+ close (pipefd[1]);
+ /* Now read from the pipe */
+ fgets(str, 1023, stdin);
+ /*printf("1st line output is %s\n", str);*/
+
+ /*while (!childtermd);*/ /* Uncomment this line to fix */
+
+ died= wait(&status);
+ /*printf("died=%d status=%d\n", died, status);*/
+ if (died > 0) _exit(0);
+ else _exit(1);
+ }
+}
+
+void
+popen_sigchld_handler (int signo)
+{
+ if (signo == SIGCHLD) {
+ /*printf("Caught sigchld\n");*/
+ childtermd = 1;
+ }
+}
diff --git a/config_test/run_tests b/config_test/run_tests
new file mode 100755
index 0000000..e7db3ca
--- /dev/null
+++ b/config_test/run_tests
@@ -0,0 +1,30 @@
+#!/bin/ksh
+# $1 is the number of iterations to run
+# If $2 is specified, this is the number of times you run each iteration
+# If there is a fail at run, exit 1
+# Prints to stdout # of successes and passes
+# Prints to stderr a dot for each run
+
+total_runs=$2
+[[ -z $total_runs ]] && total_runs=1
+run=1
+while [[ $run -le $total_runs ]] ; do
+ i=0
+ success=0
+ fail=0
+ while [[ $i -lt $1 ]] ; do
+ ./child_test
+ if [[ $? -eq 0 ]] ; then
+ success=$(($success+1))
+ else
+ fail=$((fail+1))
+ fi
+ i=$(($i+1))
+ done
+ print "Success=$success Fail=$fail"
+ [[ $fail -gt 0 ]] && exit 1
+ run=$(($run+1))
+ [[ $total_runs -gt 1 ]] && print -u2 -n "."
+done
+[[ $total_runs -gt 1 ]] && print -u2
+exit 0