From 6986aa1d0a352d8d02eed4896034631fffd25a27 Mon Sep 17 00:00:00 2001 From: Gerhard Lausser Date: Tue, 1 Oct 2013 08:57:10 +0200 Subject: Don't let check_disk hang on hanging file systems --- configure.ac | 12 ++++++++++++ plugins/Makefile.am | 2 +- plugins/check_disk.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) 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 #endif #include "regex.h" +#if HAVE_PTHREAD_H +# include +#endif #ifdef __CYGWIN__ # include @@ -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); @@ -967,6 +971,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) -- cgit v1.2.3-74-g34f1 From 66f43f99340f7e77d6feb0a6dc86302124bd8db2 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Fri, 28 Nov 2014 23:55:03 +0100 Subject: check_disk: Fix pthread start routine type The function pointer passed as third argument to pthread_create(3) must be of type void *(*)(void *). --- plugins/check_disk.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index a66aaf09..6dbaab46 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -133,7 +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 *do_stat_path (void *p); void get_stats (struct parameter_list *p, struct fs_usage *fsp); void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); @@ -1005,9 +1005,11 @@ stat_path (struct parameter_list *p) #endif } -void -do_stat_path (struct parameter_list *p) +void * +do_stat_path (void *in) { + struct parameter_list *p = in; + /* Stat entry to check that dir exists and is accessible */ if (verbose >= 3) printf("calling stat on %s\n", p->name); @@ -1017,6 +1019,7 @@ do_stat_path (struct parameter_list *p) printf("DISK %s - ", _("CRITICAL")); die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); } + return NULL; } -- cgit v1.2.3-74-g34f1 From c0e6a6935bf8ea50f85a41b281dded815a8e083d Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 30 Nov 2014 11:30:36 +0100 Subject: check_disk: Remove unused status variable We didn't actually use the exit status provided by pthread_join(3) for anything. --- plugins/check_disk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 6dbaab46..75f8a9ac 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -974,7 +974,6 @@ 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; @@ -992,7 +991,7 @@ stat_path (struct parameter_list *p) } } if (statdone == 1) { - pthread_join(stat_thread, (void *)&status); + pthread_join(stat_thread, NULL); } else { pthread_detach(stat_thread); if (verbose >= 3) -- cgit v1.2.3-74-g34f1 From 0d14645cb059ce0e4154482b38b16341ba8ddaa3 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 30 Nov 2014 11:33:20 +0100 Subject: check_disk: Seperate declarations from code --- plugins/check_disk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 75f8a9ac..eb573f5f 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -977,6 +977,7 @@ stat_path (struct parameter_list *p) 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) { -- cgit v1.2.3-74-g34f1 From 7b5d1c00e8782106b11cb1723a76fec9ed46f56f Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 2 Dec 2014 01:03:57 +0100 Subject: configure.ac: Don't let pthread check depend on OS Don't check the operating system environment to detect the correct linker flags for using the POSIX thread library. --- configure.ac | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 6dacd4f4..a90a9d45 100644 --- a/configure.ac +++ b/configure.ac @@ -156,6 +156,12 @@ AC_CHECK_LIB(socket,socket,SOCKETLIBS="$SOCKETLIBS -lsocket") AC_CHECK_LIB(resolv,main,SOCKETLIBS="$SOCKETLIBS -lresolv") AC_SUBST(SOCKETLIBS) +dnl Check for POSIX thread libraries +AC_CHECK_HEADERS(pthread.h) +AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread", + AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread -lrt",-lrt)) +AC_SUBST(THRLIBS) + dnl dnl check for math-related functions needing -lm AC_CHECK_HEADERS(math.h) @@ -544,18 +550,6 @@ 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 -- cgit v1.2.3-74-g34f1 From cf3d149652a163a0bd1c1e72d1b0e2a3c5ddb610 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 2 Dec 2014 12:37:59 +0100 Subject: Cosmetic change: s/THRLIBS/THREADLIBS/ Use a more intuitive variable name. --- configure.ac | 6 +++--- plugins/Makefile.am | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index a90a9d45..3cc3d03d 100644 --- a/configure.ac +++ b/configure.ac @@ -158,9 +158,9 @@ AC_SUBST(SOCKETLIBS) dnl Check for POSIX thread libraries AC_CHECK_HEADERS(pthread.h) -AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread", - AC_CHECK_LIB(pthread,pthread_create,THRLIBS="-lpthread -lrt",-lrt)) -AC_SUBST(THRLIBS) +AC_CHECK_LIB(pthread,pthread_create,THREADLIBS="-lpthread", + AC_CHECK_LIB(pthread,pthread_create,THREADLIBS="-lpthread -lrt",-lrt)) +AC_SUBST(THREADLIBS) dnl dnl check for math-related functions needing -lm diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 26183940..41906c53 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) $(THRLIBS) +check_disk_LDADD = $(BASEOBJS) $(THREADLIBS) check_dns_LDADD = $(NETLIBS) check_dummy_LDADD = $(BASEOBJS) check_fping_LDADD = $(NETLIBS) -- cgit v1.2.3-74-g34f1 From 14d306f57359e82b309ee5c39472fa5af7ef18e1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 2 Dec 2014 12:42:58 +0100 Subject: NEWS: Mention check_disk enhancement Closes #867. Closes #1186. --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 572d615d..c01e33c6 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ This file documents the major additions and syntax changes between releases. thresholds New check_snmp "-N" option to specify SNMPv3 context name New check_nt "-l" parameters: seconds|minutes|hours|days + Make sure check_disk won't hang on hanging (network) file systems FIXES Let check_real terminate lines with CRLF when talking to the server, as -- cgit v1.2.3-74-g34f1