Common subdirectories: monit-2.5.orig/contrib and monit-2.5/contrib Common subdirectories: monit-2.5.orig/doc and monit-2.5/doc Common subdirectories: monit-2.5.orig/http and monit-2.5/http diff -u monit-2.5.orig/l.l monit-2.5/l.l --- monit-2.5.orig/l.l Wed Jul 10 21:43:30 2002 +++ monit-2.5/l.l Fri Jul 12 12:19:25 2002 @@ -80,6 +80,7 @@ restart { return RESTART; } timeout { return TIMEOUT; } checksum { return CHECKSUM; } +checksumalways { return CHECKSUMALWAYS; } expect { return EXPECT; } mailserver { return MAILSERVER; } every { return EVERY; } diff -u monit-2.5.orig/monitor.h.in monit-2.5/monitor.h.in --- monit-2.5.orig/monitor.h.in Thu Jul 11 13:44:55 2002 +++ monit-2.5/monitor.h.in Fri Jul 12 12:30:28 2002 @@ -51,6 +51,8 @@ #define is(a,b) ((a&&b)?!strcasecmp(a, b):0) +#define MAX(x,y) ((x) > (y) ? (x) : (y)) + /** Replace the standard signal function with a more reliable using sigaction.*/ typedef void Sigfunc(int); Sigfunc *signal(int signo, Sigfunc * func); @@ -136,6 +138,7 @@ typedef struct mychecksum { char *file; /**< A filename to compute a md5 checksum for */ char *md5; /**< A md5 checksum computed for the file */ + time_t last_cmtime; /**< The ctime of the file when checked last time */ /** For internal use */ struct mychecksum *next; /**< next checksum in chain */ @@ -173,6 +176,7 @@ int def_every; /**< TRUE if every is defined for the process */ int def_timeout; /**< TRUE if timeout is defined for the process */ int def_checksum; /**< TRUE if checksum is defined for the process */ + int checksum_always; /**< TRUE if checksum is always calculated */ Port_T portlist; /**< Portnumbers the process listens on */ Checksum_T checksumlist; /**< A list of file associated checksums */ diff -u monit-2.5.orig/p.y monit-2.5/p.y --- monit-2.5.orig/p.y Wed Jul 10 22:48:44 2002 +++ monit-2.5/p.y Fri Jul 12 13:26:34 2002 @@ -40,6 +40,7 @@ #include #include #include +#include #include "net.h" #include "monitor.h" @@ -128,7 +129,7 @@ %token CHECK PIDFILE START STOP %token HOST PORT TYPE UDP TCP PROTOCOL %token ALERT MAILFORMAT -%token TIMEOUT RESTART CHECKSUM EXPECT EVERY +%token TIMEOUT RESTART CHECKSUM CHECKSUMALWAYS EXPECT EVERY %token DEFAULT HTTP FTP SMTP POP IMAP NNTP %token STRING PATH MAILADDR MAILFROM MAILSUBJECT MAILBODY %token NUMBER @@ -172,6 +173,7 @@ | checksum | autostart | group + | checksumalways ; setdaemon : SET DAEMON NUMBER { @@ -370,6 +372,10 @@ } ; +checksumalways : CHECKSUMALWAYS YES { current->checksum_always=TRUE; } + | CHECKSUMALWAYS NO { current->checksum_always=FALSE; } + ; + autostart : AUTOSTART YES { current->do_validate=TRUE; } | AUTOSTART NO { current->do_validate=FALSE; } ; @@ -483,6 +489,7 @@ /* Set default values */ current->do_validate= TRUE; + current->checksum_always= TRUE; current->name= name; current->pidfile= pidfile; @@ -523,18 +530,32 @@ static void addchecksum(char *filename, char *sum) { Checksum_T c= NEW(c); + long cmtime; c->file= filename; if ( sum ) { c->md5= sum; - + } else if ( ! set_md5sum(&c->md5, filename) ) { error("%s: Cannot compute a checksum for %s at line %d\n", prog, filename, lineno-1); cfg_errflag++; + + } + + if (( cmtime=getchange_file(filename) ) == FALSE ) { + + error("%s: Cannot stat %s at line %d\n", + prog, filename, lineno-1); + cfg_errflag++; + c->last_cmtime=0; + + } else { + + c->last_cmtime=cmtime; } Common subdirectories: monit-2.5.orig/protocols and monit-2.5/protocols diff -u monit-2.5.orig/util.c monit-2.5/util.c --- monit-2.5.orig/util.c Thu Jul 11 13:59:00 2002 +++ monit-2.5/util.c Fri Jul 12 13:26:01 2002 @@ -30,6 +30,7 @@ #include #include #include +#include #include "monitor.h" #include "engine.h" @@ -301,6 +302,7 @@ Port_T n; Mail_T r; Checksum_T c; + char *buf = xmalloc(STRLEN); printf("%-21s = %s\n", "Process Name", p->name); printf(" %-20s = %s\n", "Group", is_str_defined(p->group)); @@ -311,6 +313,8 @@ for (c= p->checksumlist; c; c= c->next) { printf(" %-20s = %s %s\n", "Checksum", c->md5, c->file); + strftime(buf, STRLEN,"%Y/%m/%d %H:%M", localtime(&c->last_cmtime)); + printf(" %-20s = %s %s\n", "Last File Change", buf, c->file); } @@ -374,7 +378,8 @@ printf(" %-20s = %s\n", "Autostart", p->do_validate?"yes":"no"); printf("\n"); - + + free(buf); } @@ -772,4 +777,22 @@ return FALSE; +} + +/** + * Get a files last modified timestamp. This function returns the max + * of either st_mtime or st_ctime. If the file does not exist or is + * not a regular file FALSE is returned + * @param file A file to stat + * @return last modification time or FALSE if not found or not a regular file +*/ +long getchange_file(char *file) { + + struct stat buf; + + if(!stat(file, &buf)) + if(S_ISREG(buf.st_mode)) + return MAX(buf.st_mtime, buf.st_ctime); + + return FALSE; } diff -u monit-2.5.orig/validate.c monit-2.5/validate.c --- monit-2.5.orig/validate.c Sun Jul 7 21:48:15 2002 +++ monit-2.5/validate.c Fri Jul 12 13:26:16 2002 @@ -25,6 +25,7 @@ #include #include #include +#include #include "monitor.h" #include "net.h" @@ -383,6 +384,7 @@ static int check_checksum(Process_T p) { Checksum_T c; + long cmtime; if ( !p->def_checksum ) { @@ -391,7 +393,41 @@ } for ( c= p->checksumlist; c; c= c->next ) { - + + if ( ! p->checksum_always ) { + + if (( cmtime= getchange_file(c->file) ) == FALSE ) { + + log("'%s' is not correctly statable\n", c->file); + + return FALSE; + + } else { + + if ( cmtime == c->last_cmtime ) { + + if ( Run.debug ) { + + log("'%s' cmtime is still the same\n", c->file ); + + } + + return FALSE; + + } else { + + if ( Run.debug ) { + + log("'%s' cmtime has changed \n", c->file); + + } + + c->last_cmtime = cmtime; + + } + } + } + if ( ! checksum_helper(p, c->file, c->md5) ) { return TRUE;