Attached is a patch that will re-init monit if the timestamp of the monit pidfile is older than the uptime of the system and you have sysinfo.

This is useful on embedded systems that may not have a battery backed clock, as when the time is set, the system can jump forward 40 years.
diff -Naur monit-5.6-orig/src/monit.c monit-5.6-new/src/monit.c
--- monit-5.6-orig/src/monit.c  2013-08-20 00:37:08.000000000 -0700
+++ monit-5.6-new/src/monit.c   2013-09-04 15:48:14.412894000 -0700
@@ -97,7 +97,7 @@
 
 
 static void  do_init();                       /* Initialize this application */
-static void  do_reinit();           /* Re-initialize the runtime application */
+void  do_reinit();           /* Re-initialize the runtime application */
 static void  do_action(char **);         /* Dispatch to the submitted action */
 static void  do_exit();                                    /* Finalize monit */
 static void  do_default();                              /* Do default action */
@@ -328,7 +328,7 @@
  * Re-Initialize the application - called if a
  * monit daemon receives the SIGHUP signal.
  */
-static void do_reinit() {
+void do_reinit() {
         int status;
 
         LogInfo("Awakened by the SIGHUP signal\n");
diff -Naur monit-5.6-orig/src/util.c monit-5.6-new/src/util.c
--- monit-5.6-orig/src/util.c   2013-03-02 15:53:10.000000000 -0800
+++ monit-5.6-new/src/util.c    2013-09-04 19:23:14.859592000 -0700
@@ -1,4 +1,4 @@
-/*
+ /*
  * Copyright (C) Tildeslash Ltd. All rights reserved.
  *
  * This program is free software: you can redistribute it and/or modify
@@ -119,6 +119,10 @@
 #include <grp.h>
 #endif
 
+#ifdef HAVE_SYS_SYSINFO_H
+#include <sys/sysinfo.h>
+#endif
+
 #include "monit.h"
 #include "engine.h"
 #include "md5.h"
@@ -129,6 +133,7 @@
 #include "process.h"
 #include "event.h"
 
+extern void do_reinit();
 
 struct ad_user {
         const char *login;
@@ -1462,8 +1467,23 @@
         ASSERT(pidfile);
 
         if ((ctime= file_getTimestamp(pidfile, S_IFREG)) ) {
+
                 time_t now= time(&now);
                 time_t since= now-ctime;
+#ifdef HAVE_SYS_SYSINFO_H
+               struct sysinfo info;
+
+               sysinfo(&info);
+
+               if (since > info.uptime) {
+                 LogWarning("Reloading monit due to time change.\n");
+                 do_reinit();
+#endif
+                 now= time(&now);
+                 since= now-ctime;
+#ifdef HAVE_SYS_SYSINFO_H
+               }
+#endif
                 return since;
         }
         return (time_t)-1;
diff -Naur monit-5.6-orig/src/validate.c monit-5.6-new/src/validate.c
--- monit-5.6-orig/src/validate.c       2013-08-27 14:35:08.000000000 -0700
+++ monit-5.6-new/src/validate.c        2013-09-04 18:29:32.068951000 -0700
@@ -153,6 +153,9 @@
                         do_scheduled_action(s);
         }
 
+       /* Check to see if time skipped forward */
+       Util_getProcessUptime(Run.pidfile);
+
         /* Check the services */
         time_t now = Time_now();
         for (s = servicelist; s && !Run.stopped; s = s->next) {
--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general

Reply via email to