diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2014-12-02 13:22:17 +0100 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2014-12-02 13:22:17 +0100 |
commit | 04e0a182aeb5defaf6b39cbbd8d9c87491c4f1e4 (patch) | |
tree | f979149a56a5392fe1827dc5f39d5faf310437ab /plugins/check_disk.c | |
parent | ed9394880c18a66fa2b60483774cf49064dd3771 (diff) | |
parent | 14d306f57359e82b309ee5c39472fa5af7ef18e1 (diff) | |
download | monitoring-plugins-04e0a182aeb5defaf6b39cbbd8d9c87491c4f1e4.tar.gz |
Merge branch 'handle-hanging-nfs'
* handle-hanging-nfs:
NEWS: Mention check_disk enhancement
Cosmetic change: s/THRLIBS/THREADLIBS/
configure.ac: Don't let pthread check depend on OS
check_disk: Seperate declarations from code
check_disk: Remove unused status variable
check_disk: Fix pthread start routine type
Don't let check_disk hang on hanging file systems
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 0d73a4f1..eb573f5f 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 (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); @@ -968,6 +972,44 @@ print_usage (void) void stat_path (struct parameter_list *p) { +#ifdef HAVE_PTHREAD_H + pthread_t stat_thread; + 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, NULL); + } 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 (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); @@ -977,6 +1019,7 @@ 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; } |