summaryrefslogtreecommitdiffstats
path: root/web/attachments/325264-nagios-plugins-1.4.13.check_disks.nfs.patch
blob: 1e4e0faa50c7a1da0dd90e0d7e97f11dbed88218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
diff -Naur nagios-plugins-1.4.13/configure.in nagios-plugins-1.4.13.nfs/configure.in
--- nagios-plugins-1.4.13/configure.in	2008-09-25 10:15:58.000000000 +0200
+++ nagios-plugins-1.4.13.nfs/configure.in	2009-05-01 11:33:59.000000000 +0200
@@ -453,6 +453,18 @@
 	with_gnutls="no"
 fi
 
+dnl Check for POSIX thread libraries
+AC_CHECK_HEADERS(pthread.h)
+case $host in
+	*sun* | *solaris*)
+		AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread -lrt")
+	;;
+	*)
+		AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread")
+	;;
+esac
+AC_SUBST(THRLIBS)
+
 dnl
 dnl Checks for header files.
 dnl
diff -Naur nagios-plugins-1.4.13/plugins/check_disk.c nagios-plugins-1.4.13.nfs/plugins/check_disk.c
--- nagios-plugins-1.4.13/plugins/check_disk.c	2008-07-10 12:03:55.000000000 +0200
+++ nagios-plugins-1.4.13.nfs/plugins/check_disk.c	2009-05-01 11:34:18.000000000 +0200
@@ -55,6 +55,9 @@
 # include <limits.h>
 #endif
 #include "regex.h"
+#if HAVE_PTHREAD_H
+# include <pthread.h>
+#endif
 
 
 /* If nonzero, show inode information. */
@@ -129,6 +132,7 @@
 void print_usage (void);
 double calculate_percent(uintmax_t, uintmax_t);
 void stat_path (struct parameter_list *p);
+void do_stat_path (struct parameter_list *p);
 
 double w_dfp = -1.0;
 double c_dfp = -1.0;
@@ -993,6 +997,42 @@
 void
 stat_path (struct parameter_list *p)
 {
+#ifdef HAVE_PTHREAD_H
+  pthread_t stat_thread;
+  int status;
+  int statdone = 0;
+  int timer = timeout_interval;
+  struct timespec req, rem;
+  req.tv_sec = 0;
+  pthread_create(&stat_thread, NULL, do_stat_path, p);
+  while (timer-- > 0) {
+    req.tv_nsec = 10000000;
+    nanosleep(&req, &rem);
+    if (pthread_kill(stat_thread, 0)) {
+      statdone = 1;
+      break;
+    } else {
+      req.tv_nsec = 990000000;
+      nanosleep(&req, &rem);
+    }
+  }
+  if (statdone == 1) {
+    pthread_join(stat_thread, (void *)&status);
+  } else {
+    pthread_detach(stat_thread);
+    if (verbose >= 3)
+      printf("stat did not return within %ds on %s\n", timeout_interval, p->name);
+    printf("DISK %s - ", _("CRITICAL"));
+    die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("hangs"), _("Timeout"));
+  }
+#else
+  do_stat_path(p);
+#endif
+}
+
+void
+do_stat_path (struct parameter_list *p)
+{
   /* Stat entry to check that dir exists and is accessible */
   if (verbose >= 3)
     printf("calling stat on %s\n", p->name);
diff -Naur nagios-plugins-1.4.13/plugins/Makefile.am nagios-plugins-1.4.13.nfs/plugins/Makefile.am
--- nagios-plugins-1.4.13/plugins/Makefile.am	2008-07-08 11:31:04.000000000 +0200
+++ nagios-plugins-1.4.13.nfs/plugins/Makefile.am	2009-05-01 11:34:26.000000000 +0200
@@ -54,7 +54,7 @@
 check_apt_LDADD = $(BASEOBJS) runcmd.o
 check_cluster_LDADD = $(BASEOBJS)
 check_dig_LDADD = $(NETLIBS) runcmd.o 
-check_disk_LDADD = $(BASEOBJS) popen.o
+check_disk_LDADD = $(BASEOBJS) popen.o $(THRLIBS)
 check_dns_LDADD = $(NETLIBS) runcmd.o
 check_dummy_LDADD = $(BASEOBJS)
 check_fping_LDADD = $(NETLIBS) popen.o