|
|
@@ -51,6 +51,9 @@ const char *email = "devel@nagios-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);
|
|
|
|
|
|
@@ -989,6 +993,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)
|