aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Gerhard Lausser <lausser@users.sourceforge.net> 2013-10-01 08:57:10 +0200
committerGravatar Holger Weiss <holger@zedat.fu-berlin.de> 2014-11-28 22:08:08 +0100
commit6986aa1d0a352d8d02eed4896034631fffd25a27 (patch)
treea61dccd97b1a00a52a7d48787e12facc361d37af
parentf3b789a526af04434813c3d49dfb28b106ad691c (diff)
downloadmonitoring-plugins-6986aa1d0a352d8d02eed4896034631fffd25a27.tar.gz
Don't let check_disk hang on hanging file systems
-rw-r--r--configure.ac12
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/check_disk.c40
3 files changed, 53 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 59875e5a..6dacd4f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -544,6 +544,18 @@ else
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 --git a/plugins/Makefile.am b/plugins/Makefile.am
index 0ddf9bd1..26183940 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -71,7 +71,7 @@ check_apt_LDADD = $(BASEOBJS)
check_cluster_LDADD = $(BASEOBJS)
check_dbi_LDADD = $(NETLIBS) $(DBILIBS)
check_dig_LDADD = $(NETLIBS)
-check_disk_LDADD = $(BASEOBJS)
+check_disk_LDADD = $(BASEOBJS) $(THRLIBS)
check_dns_LDADD = $(NETLIBS)
check_dummy_LDADD = $(BASEOBJS)
check_fping_LDADD = $(NETLIBS)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 0d73a4f1..a66aaf09 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -51,6 +51,9 @@ const char *email = "devel@monitoring-plugins.org";
# include <limits.h>
#endif
#include "regex.h"
+#if HAVE_PTHREAD_H
+# include <pthread.h>
+#endif
#ifdef __CYGWIN__
# include <windows.h>
@@ -130,6 +133,7 @@ void print_help (void);
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);
void get_stats (struct parameter_list *p, struct fs_usage *fsp);
void get_path_stats (struct parameter_list *p, struct fs_usage *fsp);
@@ -968,6 +972,42 @@ print_usage (void)
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);