diff options
-rw-r--r-- | configure.ac | 12 | ||||
-rw-r--r-- | plugins/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/check_disk.c | 40 |
3 files changed, 53 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 59875e5..6dacd4f 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -544,6 +544,18 @@ else | |||
544 | with_gnutls="no" | 544 | with_gnutls="no" |
545 | fi | 545 | fi |
546 | 546 | ||
547 | dnl Check for POSIX thread libraries | ||
548 | AC_CHECK_HEADERS(pthread.h) | ||
549 | case $host in | ||
550 | *sun* | *solaris*) | ||
551 | AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread -lrt") | ||
552 | ;; | ||
553 | *) | ||
554 | AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread") | ||
555 | ;; | ||
556 | esac | ||
557 | AC_SUBST(THRLIBS) | ||
558 | |||
547 | dnl | 559 | dnl |
548 | dnl Checks for header files. | 560 | dnl Checks for header files. |
549 | dnl | 561 | dnl |
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 0ddf9bd..2618394 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -71,7 +71,7 @@ check_apt_LDADD = $(BASEOBJS) | |||
71 | check_cluster_LDADD = $(BASEOBJS) | 71 | check_cluster_LDADD = $(BASEOBJS) |
72 | check_dbi_LDADD = $(NETLIBS) $(DBILIBS) | 72 | check_dbi_LDADD = $(NETLIBS) $(DBILIBS) |
73 | check_dig_LDADD = $(NETLIBS) | 73 | check_dig_LDADD = $(NETLIBS) |
74 | check_disk_LDADD = $(BASEOBJS) | 74 | check_disk_LDADD = $(BASEOBJS) $(THRLIBS) |
75 | check_dns_LDADD = $(NETLIBS) | 75 | check_dns_LDADD = $(NETLIBS) |
76 | check_dummy_LDADD = $(BASEOBJS) | 76 | check_dummy_LDADD = $(BASEOBJS) |
77 | check_fping_LDADD = $(NETLIBS) | 77 | check_fping_LDADD = $(NETLIBS) |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 0d73a4f..a66aaf0 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -51,6 +51,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
51 | # include <limits.h> | 51 | # include <limits.h> |
52 | #endif | 52 | #endif |
53 | #include "regex.h" | 53 | #include "regex.h" |
54 | #if HAVE_PTHREAD_H | ||
55 | # include <pthread.h> | ||
56 | #endif | ||
54 | 57 | ||
55 | #ifdef __CYGWIN__ | 58 | #ifdef __CYGWIN__ |
56 | # include <windows.h> | 59 | # include <windows.h> |
@@ -130,6 +133,7 @@ void print_help (void); | |||
130 | void print_usage (void); | 133 | void print_usage (void); |
131 | double calculate_percent(uintmax_t, uintmax_t); | 134 | double calculate_percent(uintmax_t, uintmax_t); |
132 | void stat_path (struct parameter_list *p); | 135 | void stat_path (struct parameter_list *p); |
136 | void do_stat_path (struct parameter_list *p); | ||
133 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); | 137 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); |
134 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); | 138 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); |
135 | 139 | ||
@@ -968,6 +972,42 @@ print_usage (void) | |||
968 | void | 972 | void |
969 | stat_path (struct parameter_list *p) | 973 | stat_path (struct parameter_list *p) |
970 | { | 974 | { |
975 | #ifdef HAVE_PTHREAD_H | ||
976 | pthread_t stat_thread; | ||
977 | int status; | ||
978 | int statdone = 0; | ||
979 | int timer = timeout_interval; | ||
980 | struct timespec req, rem; | ||
981 | req.tv_sec = 0; | ||
982 | pthread_create(&stat_thread, NULL, do_stat_path, p); | ||
983 | while (timer-- > 0) { | ||
984 | req.tv_nsec = 10000000; | ||
985 | nanosleep(&req, &rem); | ||
986 | if (pthread_kill(stat_thread, 0)) { | ||
987 | statdone = 1; | ||
988 | break; | ||
989 | } else { | ||
990 | req.tv_nsec = 990000000; | ||
991 | nanosleep(&req, &rem); | ||
992 | } | ||
993 | } | ||
994 | if (statdone == 1) { | ||
995 | pthread_join(stat_thread, (void *)&status); | ||
996 | } else { | ||
997 | pthread_detach(stat_thread); | ||
998 | if (verbose >= 3) | ||
999 | printf("stat did not return within %ds on %s\n", timeout_interval, p->name); | ||
1000 | printf("DISK %s - ", _("CRITICAL")); | ||
1001 | die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("hangs"), _("Timeout")); | ||
1002 | } | ||
1003 | #else | ||
1004 | do_stat_path(p); | ||
1005 | #endif | ||
1006 | } | ||
1007 | |||
1008 | void | ||
1009 | do_stat_path (struct parameter_list *p) | ||
1010 | { | ||
971 | /* Stat entry to check that dir exists and is accessible */ | 1011 | /* Stat entry to check that dir exists and is accessible */ |
972 | if (verbose >= 3) | 1012 | if (verbose >= 3) |
973 | printf("calling stat on %s\n", p->name); | 1013 | printf("calling stat on %s\n", p->name); |