63 |
static int compare_value(int, int, int); |
static int compare_value(int, int, int); |
64 |
|
|
65 |
/** |
/** |
66 |
* Check that all processes in the process list are running and |
* This function contains the main process and check machinery for |
67 |
* accepts connections if port is defined. Restart any process not |
* monit. The validate function check processes in the process list |
68 |
* running. Also restart process if connection or the protocol test |
* to see if they are running and that they accepts connections if |
69 |
* fails. |
* ports are defined. Not running processes are restarted. This |
70 |
|
* function also handles the various tests per process that are |
71 |
|
* defined in the control file. |
72 |
* |
* |
73 |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
74 |
* @author Olivier Beyssac, <ob@r14.freenix.org> (check_skip) |
* @author Olivier Beyssac, <ob@r14.freenix.org> (check_skip) |
91 |
|
|
92 |
Process_T p; |
Process_T p; |
93 |
|
|
94 |
if ( ! update_loadavg() ) { |
if(! update_loadavg()) { |
95 |
|
|
96 |
log("Update of loadavg has failed!\n"); |
log("Update of loadavg has failed!\n"); |
97 |
|
|
98 |
} |
} |
99 |
|
|
100 |
for (p= processlist; p; p= p->next) { |
for(p= processlist; p; p= p->next) { |
101 |
if(p->visited) |
if(p->visited) |
102 |
continue; |
continue; |
103 |
do_validate(p); |
do_validate(p); |
112 |
|
|
113 |
|
|
114 |
/** |
/** |
115 |
* Validate the given process - If the process is not running, |
* Validate the given process - If the process is not running, start |
116 |
* start it. If the process listens on a port try to connect to |
* it. If the process listens on a port try to connect to the port and |
117 |
* the port and test the stated protocol at the port, if the |
* test the stated protocol at the port. If any of the various tests |
118 |
* connect or protocol test fails, optionaly restart the process. |
* fails then do the specified action on the process. |
119 |
* |
* |
120 |
* We block for the signals SIGTERM while in this function. |
* We block for the signals SIGTERM while in this function. |
121 |
*/ |
*/ |
130 |
|
|
131 |
|
|
132 |
/* First, check for pre-conditions */ |
/* First, check for pre-conditions */ |
133 |
if (do_not_validate(p)) return; |
if(do_not_validate(p)) return; |
134 |
|
|
135 |
/* Set a SIGTERM block */ |
/* Set a SIGTERM block */ |
136 |
sigemptyset(&ns); |
sigemptyset(&ns); |
138 |
pthread_sigmask(SIG_BLOCK, &ns, &os); |
pthread_sigmask(SIG_BLOCK, &ns, &os); |
139 |
|
|
140 |
/* Test for running process */ |
/* Test for running process */ |
141 |
if (!(pid= is_process_running(p))) { |
if(!(pid= is_process_running(p))) { |
142 |
|
|
143 |
do_start(p, "Reason: Process is not running."); |
do_start(p, "Reason: Process is not running."); |
144 |
goto reinstall; |
goto reinstall; |
145 |
|
|
146 |
} else { |
} else { |
147 |
|
|
148 |
if (Run.debug) { |
if(Run.debug) { |
149 |
|
|
150 |
log("'%s' is running with pid %d\n", p->name, (int)pid); |
log("'%s' is running with pid %d\n", p->name, (int)pid); |
151 |
|
|
153 |
|
|
154 |
} |
} |
155 |
|
|
156 |
if ( Run.doprocess ) { |
if(Run.doprocess) { |
157 |
|
|
158 |
if ( update_process_data(p, pid) ) { |
if(update_process_data(p, pid)) { |
159 |
|
|
160 |
if ( ! check_process_state(p, report)) { |
if(! check_process_state(p, report)) { |
161 |
|
|
162 |
smtp_alert_resource(p, "Reason: %s\n", report); |
smtp_alert_resource(p, "Reason: %s\n", report); |
163 |
|
|
164 |
} else { |
} else { |
165 |
|
|
166 |
if ( Run.debug ) { |
if(Run.debug) { |
167 |
|
|
168 |
log("'%s' check_process_state() passed.\n", p->name); |
log("'%s' check_process_state() passed.\n", p->name); |
169 |
|
|
171 |
|
|
172 |
} |
} |
173 |
|
|
174 |
for( pr= p->resourcelist; pr; pr= pr->next ) { |
for(pr= p->resourcelist; pr; pr= pr->next) { |
175 |
|
|
176 |
if ( !check_resources(p, pr, report) ) { |
if(!check_resources(p, pr, report)) { |
177 |
|
|
178 |
switch (pr->action) { |
switch(pr->action) { |
179 |
case ACTION_ALERT: |
case ACTION_ALERT: |
180 |
smtp_alert_resource(p, "Reason: %s\n", report); |
smtp_alert_resource(p, "Reason: %s\n", report); |
181 |
|
/* We are also interested in other alerts/stops/restarts! */ |
182 |
/* We are also interested in other alerts/stops/restarts! */ |
pr->cycle=0; |
183 |
pr->cycle=0; |
break; |
|
break; |
|
184 |
|
|
185 |
case ACTION_STOP: |
case ACTION_STOP: |
186 |
|
do_stop(p, "Reason: %s\n", report); |
187 |
do_stop(p, "Reason: %s\n", report); |
reset_resource_counter(p); |
188 |
reset_resource_counter(p); |
goto reinstall; |
|
goto reinstall; |
|
189 |
|
|
190 |
case ACTION_RESTART: |
case ACTION_RESTART: |
191 |
|
do_restart(p, "Reason: %s\n", report); |
192 |
do_restart(p, "Reason: %s\n", report); |
reset_resource_counter(p); |
193 |
reset_resource_counter(p); |
goto reinstall; |
|
goto reinstall; |
|
194 |
|
|
195 |
default: |
default: |
196 |
|
log("'%s' Unknow resource failure action.\n", p->name); |
197 |
log("'%s' Unknow resource failure action.\n", p->name); |
break; |
|
break; |
|
|
|
|
|
/* Internal Alert ??? */ |
|
|
|
|
198 |
} |
} |
199 |
|
|
200 |
} |
} |
201 |
|
|
202 |
} |
} |
203 |
|
|
204 |
} else { |
} else { |
205 |
|
|
206 |
log("'%s' failed to get process data\n", p->name); |
log("'%s' failed to get process data\n", p->name); |
207 |
|
|
|
/* Internal Alert ??? */ |
|
|
|
|
208 |
} |
} |
209 |
|
|
210 |
} |
} |
211 |
|
|
212 |
for( tl= p->timestamplist; tl; tl= tl->next ) { |
for(tl= p->timestamplist; tl; tl= tl->next) { |
213 |
|
|
214 |
if ( !check_timestamp(p, tl, report) ) { |
if(!check_timestamp(p, tl, report)) { |
215 |
|
|
216 |
switch (tl->action) { |
switch(tl->action) { |
217 |
case ACTION_ALERT: |
case ACTION_ALERT: |
218 |
smtp_alert_timestamp(p, "Reason: %s\n", report); |
smtp_alert_timestamp(p, "Reason: %s\n", report); |
219 |
break; /* continue */ |
break; /* continue */ |
220 |
|
|
221 |
case ACTION_STOP: |
case ACTION_STOP: |
222 |
|
do_stop(p, "Reason: %s\n", report); |
223 |
do_stop(p, "Reason: %s\n", report); |
goto reinstall; |
|
goto reinstall; |
|
224 |
|
|
225 |
case ACTION_RESTART: |
case ACTION_RESTART: |
226 |
|
do_restart(p, "Reason: %s\n", report); |
227 |
do_restart(p, "Reason: %s\n", report); |
goto reinstall; |
|
goto reinstall; |
|
228 |
|
|
229 |
default: |
default: |
230 |
|
log("'%s' Unknow timestamp failure action.\n", p->name); |
231 |
log("'%s' Unknow timestamp failure action.\n", p->name); |
break; |
|
break; |
|
232 |
|
|
233 |
} |
} |
234 |
|
|
239 |
/* Test each host:port and protocol in the process's portlist */ |
/* Test each host:port and protocol in the process's portlist */ |
240 |
for(pp= p->portlist; pp; pp= pp->next) { |
for(pp= p->portlist; pp; pp= pp->next) { |
241 |
|
|
242 |
if (!check_connection(p, pp, report)) { |
if(!check_connection(p, pp, report)) { |
243 |
|
|
244 |
do_restart(p, "Reason: %s\n", report); |
do_restart(p, "Reason: %s\n", report); |
245 |
goto reinstall; |
goto reinstall; |
281 |
log("Trying to restart '%s'\n", p->name); |
log("Trying to restart '%s'\n", p->name); |
282 |
|
|
283 |
check_process(p->name, "stop", FALSE); |
check_process(p->name, "stop", FALSE); |
|
|
|
|
sleep(10); /* Wait for process termination */ |
|
|
|
|
284 |
check_process(p->name, "start", FALSE); |
check_process(p->name, "start", FALSE); |
|
|
|
|
/* In the case we just started our own smtp server we'll |
|
|
* sleep before attempting to send alert */ |
|
|
sleep(3); |
|
|
|
|
285 |
smtp_alert_restart(p, "%s", tmp); |
smtp_alert_restart(p, "%s", tmp); |
286 |
|
|
287 |
} else { |
} else { |
310 |
if(p->def_timeout) |
if(p->def_timeout) |
311 |
p->nstart++; |
p->nstart++; |
312 |
|
|
|
/* Start alert */ |
|
313 |
va_start(ap, m); |
va_start(ap, m); |
314 |
if(m) |
if(m) |
315 |
tmp=format(m, ap); |
tmp=format(m, ap); |
317 |
|
|
318 |
if(p->mode!= MODE_PASSIVE && p->start) { |
if(p->mode!= MODE_PASSIVE && p->start) { |
319 |
|
|
|
/* Start process and take care of dependants */ |
|
320 |
check_process(p->name, "start", FALSE); |
check_process(p->name, "start", FALSE); |
|
|
|
|
/* In the case we just started our own smtp server we'll |
|
|
* sleep before attempting to send alert */ |
|
|
sleep(3); |
|
|
|
|
321 |
smtp_alert_restart(p, "%s", tmp); |
smtp_alert_restart(p, "%s", tmp); |
322 |
|
|
323 |
} else { |
} else { |
343 |
if(!p->do_validate) |
if(!p->do_validate) |
344 |
return; |
return; |
345 |
|
|
|
/* Stop alert */ |
|
346 |
va_start(ap, m); |
va_start(ap, m); |
347 |
if(m) |
if(m) |
348 |
tmp=format(m, ap); |
tmp=format(m, ap); |
355 |
if(p->mode!= MODE_PASSIVE && p->stop) { |
if(p->mode!= MODE_PASSIVE && p->stop) { |
356 |
|
|
357 |
smtp_alert_stop(p, "%s", tmp); |
smtp_alert_stop(p, "%s", tmp); |
|
|
|
|
/* In the case we just stop our own smtp server we'll |
|
|
* sleep before stopping it */ |
|
|
sleep(3); |
|
|
|
|
|
/* Stop the process and dependants */ |
|
358 |
check_process(p->name, "stop", FALSE); |
check_process(p->name, "stop", FALSE); |
359 |
|
|
360 |
} else { |
} else { |
377 |
*/ |
*/ |
378 |
static int do_not_validate(Process_T p) { |
static int do_not_validate(Process_T p) { |
379 |
|
|
380 |
return (!p->do_validate || |
return(!p->do_validate || |
381 |
check_skip(p) || |
check_skip(p) || |
382 |
check_timeout(p) || |
check_timeout(p) || |
383 |
check_checksum(p)); |
check_checksum(p)); |
384 |
|
|
385 |
} |
} |
386 |
|
|
394 |
volatile int rv= TRUE; |
volatile int rv= TRUE; |
395 |
|
|
396 |
/* Control comes here if a timeout occures */ |
/* Control comes here if a timeout occures */ |
397 |
if (sigsetjmp(timeout, TRUE)) { |
if(sigsetjmp(timeout, TRUE)) { |
398 |
|
|
399 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
400 |
"timed out when testing %s [%s]", |
"timed out when testing %s [%s]", |
412 |
alarm(CHECK_TIMEOUT); |
alarm(CHECK_TIMEOUT); |
413 |
|
|
414 |
/* Open a socket to the destination INET[hostname:port] or UNIX[pathname] */ |
/* Open a socket to the destination INET[hostname:port] or UNIX[pathname] */ |
415 |
|
if((pp->socket= create_generic_socket(pp)) < 0) { |
|
if ((pp->socket= create_generic_socket(pp)) < 0) { |
|
416 |
|
|
417 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
418 |
"does not accept connection at %s.", |
"does not accept connection at %s.", |
425 |
|
|
426 |
} else { |
} else { |
427 |
|
|
428 |
if (Run.debug) { |
if(Run.debug) { |
429 |
|
|
430 |
log("'%s' succeeded connecting to %s\n", |
log("'%s' succeeded connecting to %s\n", |
431 |
p->name, pp->address); |
p->name, pp->address); |
435 |
} |
} |
436 |
|
|
437 |
/* Verify that the socket is ready for i|o */ |
/* Verify that the socket is ready for i|o */ |
438 |
if (!check_connection_io(pp)) { |
if(!check_connection_io(pp)) { |
439 |
|
|
440 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
441 |
"socket at %s is not ready for i|o -- %s", |
"socket at %s is not ready for i|o -- %s", |
442 |
pp->address, STRERROR); |
pp->address, STRERROR); |
443 |
|
|
444 |
log("'%s' %s\n", p->name, report); |
log("'%s' %s\n", p->name, report); |
445 |
|
|
446 |
rv= FALSE; |
rv= FALSE; |
448 |
|
|
449 |
} |
} |
450 |
|
|
451 |
if (pp->ssl != NULL ) { |
if(pp->ssl != NULL) { |
452 |
|
|
453 |
if (!embed_ssl_socket(pp->ssl, pp->socket)) { |
if(!embed_ssl_socket(pp->ssl, pp->socket)) { |
454 |
|
|
455 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
456 |
"failed establish SSL communication on socket at %s", |
"failed establish SSL communication on socket at %s", |
462 |
|
|
463 |
} |
} |
464 |
|
|
465 |
if ( pp->certmd5 != NULL ) { |
if(pp->certmd5 != NULL) { |
466 |
|
|
467 |
if (! check_ssl_md5sum(pp->ssl, pp->certmd5)) { |
if(! check_ssl_md5sum(pp->ssl, pp->certmd5)) { |
468 |
|
|
469 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
470 |
"md5sums of SSL certificates do not match at %s", |
"md5sums of SSL certificates do not match at %s", |
481 |
} |
} |
482 |
|
|
483 |
/* Run the protocol verification routine through the socket */ |
/* Run the protocol verification routine through the socket */ |
484 |
if (! pp->protocol->check(pp)) { |
if(! pp->protocol->check(pp)) { |
485 |
|
|
486 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
487 |
"test with protocol [%s] failed at %s.", |
"test with protocol [%s] failed at %s.", |
494 |
|
|
495 |
} else { |
} else { |
496 |
|
|
497 |
if (Run.debug) { |
if(Run.debug) { |
498 |
|
|
499 |
log("'%s' succeeded testing protocol [%s] at %s\n", |
log("'%s' succeeded testing protocol [%s] at %s\n", |
500 |
p->name, pp->protocol->name, pp->address); |
p->name, pp->protocol->name, pp->address); |
506 |
|
|
507 |
alarm(0); |
alarm(0); |
508 |
|
|
509 |
if (pp->ssl != NULL) { |
if(pp->ssl != NULL) { |
510 |
|
|
511 |
cleanup_ssl_socket(pp->ssl); |
cleanup_ssl_socket(pp->ssl); |
512 |
|
|
527 |
|
|
528 |
ProcInfo_T pi= p->procinfo; |
ProcInfo_T pi= p->procinfo; |
529 |
|
|
530 |
if ( pi->status_flag & PROCESS_ZOMBIE ) { |
if(pi->status_flag & PROCESS_ZOMBIE) { |
531 |
|
|
532 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
533 |
"process with pid %d is a zombie\n", pi->pid); |
"process with pid %d is a zombie\n", pi->pid); |
544 |
|
|
545 |
} else { |
} else { |
546 |
|
|
547 |
if ( Run.debug ) { |
if(Run.debug) { |
548 |
|
|
549 |
log("'%s' zombie check passed [status_flag=%04x]\n", |
log("'%s' zombie check passed [status_flag=%04x]\n", |
550 |
p->name, pi->status_flag); |
p->name, pi->status_flag); |
562 |
* Resets the resource counter |
* Resets the resource counter |
563 |
*/ |
*/ |
564 |
static void reset_resource_counter(Process_T p) { |
static void reset_resource_counter(Process_T p) { |
565 |
|
|
566 |
Resource_T pr; |
Resource_T pr; |
567 |
|
|
568 |
for( pr= p->resourcelist; pr; pr= pr->next ) { |
for(pr= p->resourcelist; pr; pr= pr->next) { |
569 |
|
|
570 |
pr->cycle=0; |
pr->cycle=0; |
571 |
|
|
572 |
} |
} |
573 |
|
|
574 |
} |
} |
575 |
|
|
576 |
|
|
583 |
ProcInfo_T pi= p->procinfo; |
ProcInfo_T pi= p->procinfo; |
584 |
int okay= TRUE; |
int okay= TRUE; |
585 |
|
|
586 |
switch (pr->resource_id) { |
switch(pr->resource_id) { |
587 |
case RESOURCE_ID_CPU_PERCENT: |
case RESOURCE_ID_CPU_PERCENT: |
588 |
if ( compare_value(pr->operator, pi->cpu_percent, pr->limit) ) { |
if(compare_value(pr->operator, pi->cpu_percent, pr->limit)) { |
589 |
|
|
590 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
591 |
"cpu usage of %.1f%% matches resource limit [cpu usage%s%.1f%%]", |
"cpu usage of %.1f%% matches resource limit [cpu usage%s%.1f%%]", |
596 |
|
|
597 |
} else { |
} else { |
598 |
|
|
599 |
if ( Run.debug ) { |
if(Run.debug) { |
600 |
|
|
601 |
log("'%s' cpu usage check passed [current cpu usage=%.1f%%]\n", |
log("'%s' cpu usage check passed [current cpu usage=%.1f%%]\n", |
602 |
p->name, pi->cpu_percent/10.0); |
p->name, pi->cpu_percent/10.0); |
606 |
break; |
break; |
607 |
|
|
608 |
case RESOURCE_ID_MEM_PERCENT: |
case RESOURCE_ID_MEM_PERCENT: |
609 |
if ( compare_value(pr->operator, pi->mem_percent, pr->limit) ) { |
if(compare_value(pr->operator, pi->mem_percent, pr->limit)) { |
610 |
|
|
611 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
612 |
"mem usage of %.1f%% matches resource limit [mem usage%s%.1f%%]", |
"mem usage of %.1f%% matches resource limit [mem usage%s%.1f%%]", |
617 |
|
|
618 |
} else { |
} else { |
619 |
|
|
620 |
if ( Run.debug ) { |
if(Run.debug) { |
621 |
|
|
622 |
log("'%s' mem usage check passed [current mem usage=%.1f%%]\n", |
log("'%s' mem usage check passed [current mem usage=%.1f%%]\n", |
623 |
p->name, pi->mem_percent/10.0); |
p->name, pi->mem_percent/10.0); |
628 |
|
|
629 |
case RESOURCE_ID_MEM_KBYTE: |
case RESOURCE_ID_MEM_KBYTE: |
630 |
|
|
631 |
if ( compare_value(pr->operator, pi->mem_kbyte, pr->limit) ) { |
if(compare_value(pr->operator, pi->mem_kbyte, pr->limit)) { |
632 |
|
|
633 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
634 |
"mem amount of %ldkB matches resource limit [mem amount%s%ldkB]", |
"mem amount of %ldkB matches resource limit [mem amount%s%ldkB]", |
639 |
|
|
640 |
} else { |
} else { |
641 |
|
|
642 |
if ( Run.debug ) { |
if(Run.debug) { |
643 |
|
|
644 |
log("'%s' mem amount check passed [current mem amount=%ldkB]\n", |
log("'%s' mem amount check passed [current mem amount=%ldkB]\n", |
645 |
p->name, pi->mem_kbyte); |
p->name, pi->mem_kbyte); |
650 |
|
|
651 |
case RESOURCE_ID_LOAD1: |
case RESOURCE_ID_LOAD1: |
652 |
|
|
653 |
if ( compare_value(pr->operator, (int)(Run.loadavg[0]*10.0), pr->limit) ) { |
if(compare_value(pr->operator, (int)(Run.loadavg[0]*10.0), pr->limit)) { |
654 |
|
|
655 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
656 |
"loadavg(1min) of %.1f matches resource limit " |
"loadavg(1min) of %.1f matches resource limit " |
662 |
|
|
663 |
} else { |
} else { |
664 |
|
|
665 |
if ( Run.debug ) { |
if(Run.debug) { |
666 |
|
|
667 |
log("'%s' loadavg(1min) check passed [current loadavg(1min)=%.1f]\n", |
log("'%s' loadavg(1min) check passed [current loadavg(1min)=%.1f]\n", |
668 |
p->name, Run.loadavg[0] ); |
p->name, Run.loadavg[0]); |
669 |
|
|
670 |
} |
} |
671 |
} |
} |
673 |
|
|
674 |
case RESOURCE_ID_LOAD5: |
case RESOURCE_ID_LOAD5: |
675 |
|
|
676 |
if ( compare_value(pr->operator, (int)(Run.loadavg[1]*10.0), pr->limit) ) { |
if(compare_value(pr->operator, (int)(Run.loadavg[1]*10.0), pr->limit)) { |
677 |
|
|
678 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
679 |
"loadavg(5min) of %.1f matches resource limit " |
"loadavg(5min) of %.1f matches resource limit " |
685 |
|
|
686 |
} else { |
} else { |
687 |
|
|
688 |
if ( Run.debug ) { |
if(Run.debug) { |
689 |
|
|
690 |
log("'%s' loadavg(5min) check passed [current loadavg(5min)=%.1f]\n", |
log("'%s' loadavg(5min) check passed [current loadavg(5min)=%.1f]\n", |
691 |
p->name, Run.loadavg[1]); |
p->name, Run.loadavg[1]); |
696 |
|
|
697 |
case RESOURCE_ID_LOAD15: |
case RESOURCE_ID_LOAD15: |
698 |
|
|
699 |
if ( compare_value(pr->operator, (int)(Run.loadavg[2]*10.0), pr->limit) ) { |
if(compare_value(pr->operator, (int)(Run.loadavg[2]*10.0), pr->limit)) { |
700 |
|
|
701 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
702 |
"loadavg(15min) of %.1f matches resource limit " |
"loadavg(15min) of %.1f matches resource limit " |
708 |
|
|
709 |
} else { |
} else { |
710 |
|
|
711 |
if ( Run.debug ) { |
if(Run.debug) { |
712 |
|
|
713 |
log("'%s' loadavg(15min) check passed " |
log("'%s' loadavg(15min) check passed " |
714 |
"[current loadavg(15min)=%.1f]\n", |
"[current loadavg(15min)=%.1f]\n", |
720 |
|
|
721 |
default: |
default: |
722 |
|
|
723 |
log("'%s' error: unknow resource ID: [%d]\n", p->name, pr->resource_id); |
log("'%s' error: unknow resource ID: [%d]\n", p->name, pr->resource_id); |
|
|
|
|
/* Internal Alert ??? */ |
|
724 |
|
|
725 |
} |
} |
726 |
|
|
727 |
if ( okay && pr->cycle > 0 ) { |
if(okay && pr->cycle > 0) { |
728 |
|
|
729 |
pr->cycle--; |
pr->cycle--; |
730 |
|
|
731 |
} else if ( ! okay ) { |
} else if(! okay) { |
732 |
|
|
733 |
pr->cycle++; |
pr->cycle++; |
734 |
|
|
735 |
} |
} |
736 |
|
|
737 |
if ( pr->cycle >= pr->max_cycle ) { |
if(pr->cycle >= pr->max_cycle) { |
738 |
|
|
739 |
return FALSE; |
return FALSE; |
740 |
|
|
741 |
} |
} |
742 |
|
|
743 |
return TRUE; |
return TRUE; |
744 |
|
|
745 |
} |
} |
746 |
|
|
747 |
|
|
750 |
*/ |
*/ |
751 |
static int check_timeout(Process_T p) { |
static int check_timeout(Process_T p) { |
752 |
|
|
753 |
if (!p->def_timeout) { |
if(!p->def_timeout) { |
754 |
|
|
755 |
return FALSE; |
return FALSE; |
756 |
|
|
757 |
} |
} |
758 |
|
|
759 |
/* |
/* |
760 |
* Start counting cycles |
* Start counting cycles |
761 |
*/ |
*/ |
762 |
if (p->nstart > 0) { |
if(p->nstart > 0) { |
763 |
|
|
764 |
p->ncycle++; |
p->ncycle++; |
765 |
|
|
768 |
/* |
/* |
769 |
* Check timeout |
* Check timeout |
770 |
*/ |
*/ |
771 |
if (p->nstart >= p->to_start && p->ncycle <= p->to_cycle) { |
if(p->nstart >= p->to_start && p->ncycle <= p->to_cycle) { |
772 |
|
|
773 |
/* |
/* |
774 |
* Got timeout - Set do not validate flag. This statement is |
* Got timeout - Set do not validate flag. This statement is |
795 |
* Stop counting and reset if the |
* Stop counting and reset if the |
796 |
* cycle interval is passed |
* cycle interval is passed |
797 |
*/ |
*/ |
798 |
if (p->ncycle > p->to_cycle) { |
if(p->ncycle > p->to_cycle) { |
799 |
|
|
800 |
p->ncycle= 0; |
p->ncycle= 0; |
801 |
p->nstart= 0; |
p->nstart= 0; |
813 |
*/ |
*/ |
814 |
static int check_skip(Process_T p) { |
static int check_skip(Process_T p) { |
815 |
|
|
816 |
if (!p->def_every) { |
if(!p->def_every) { |
817 |
|
|
818 |
return FALSE; |
return FALSE; |
819 |
|
|
820 |
} |
} |
821 |
|
|
822 |
if (++p->nevery < p->every) { |
if(++p->nevery < p->every) { |
823 |
|
|
824 |
return TRUE; |
return TRUE; |
825 |
|
|
843 |
|
|
844 |
Checksum_T c; |
Checksum_T c; |
845 |
|
|
846 |
if (!p->def_checksum) { |
if(!p->def_checksum) { |
847 |
|
|
848 |
return FALSE; |
return FALSE; |
849 |
|
|
850 |
} |
} |
851 |
|
|
852 |
for (c= p->checksumlist; c; c= c->next) { |
for(c= p->checksumlist; c; c= c->next) { |
853 |
|
|
854 |
if (! checksum_helper(p, c->file, c->md5)) { |
if(! checksum_helper(p, c->file, c->md5)) { |
855 |
|
|
856 |
return TRUE; |
return TRUE; |
857 |
|
|
859 |
|
|
860 |
} |
} |
861 |
|
|
862 |
if (Run.debug) { |
if(Run.debug) { |
863 |
|
|
864 |
log("'%s' have valid checksums\n", p->name); |
log("'%s' have valid checksums\n", p->name); |
865 |
|
|
912 |
time_t now; |
time_t now; |
913 |
time_t timestamp; |
time_t timestamp; |
914 |
|
|
915 |
if( (int)time(&now) == -1 ) { |
if((int)time(&now) == -1) { |
916 |
vlog(report, STRLEN, p, "can't get actual time"); |
vlog(report, STRLEN, p, "can't get actual time"); |
917 |
return FALSE; |
return FALSE; |
918 |
} |
} |
919 |
|
|
920 |
if ( !(timestamp= get_timestamp(t->pathname, S_IFDIR|S_IFREG)) ) { |
if(!(timestamp= get_timestamp(t->pathname, S_IFDIR|S_IFREG))) { |
921 |
vlog(report, STRLEN, p, "can't get timestamp for %s", t->pathname); |
vlog(report, STRLEN, p, "can't get timestamp for %s", t->pathname); |
922 |
return FALSE; |
return FALSE; |
923 |
} |
} |
924 |
|
|
925 |
if( compare_value(t->operator, (int)(now - timestamp), t->time) ) { |
if(compare_value(t->operator, (int)(now - timestamp), t->time)) { |
926 |
vlog(report, STRLEN, p, "timestamp test failed for %s", t->pathname); |
vlog(report, STRLEN, p, "timestamp test failed for %s", t->pathname); |
927 |
return FALSE; |
return FALSE; |
928 |
} |
} |
955 |
|
|
956 |
va_start(ap, m); |
va_start(ap, m); |
957 |
|
|
958 |
if (m) { |
if(m) { |
959 |
|
|
960 |
tmp=format(m,ap); |
tmp=format(m,ap); |
961 |
|
|
976 |
*/ |
*/ |
977 |
static int compare_value(int operator, int left, int right) { |
static int compare_value(int operator, int left, int right) { |
978 |
|
|
979 |
switch (operator) { |
switch(operator) { |
980 |
|
|
981 |
case OPERATOR_GREATER: |
case OPERATOR_GREATER: |
982 |
|
|
983 |
if( left > right ) |
if(left > right) |
984 |
return TRUE; |
return TRUE; |
985 |
break; |
break; |
986 |
|
|
987 |
case OPERATOR_LESS: |
case OPERATOR_LESS: |
988 |
|
|
989 |
if( left < right ) |
if(left < right) |
990 |
return TRUE; |
return TRUE; |
991 |
break; |
break; |
992 |
|
|
993 |
case OPERATOR_EQUAL: |
case OPERATOR_EQUAL: |
994 |
|
|
995 |
if( left == right ) |
if(left == right) |
996 |
return TRUE; |
return TRUE; |
997 |
break; |
break; |
998 |
|
|
999 |
case OPERATOR_NOTEQUAL: |
case OPERATOR_NOTEQUAL: |
1000 |
|
|
1001 |
if( left != right ) |
if(left != right) |
1002 |
return TRUE; |
return TRUE; |
1003 |
break; |
break; |
1004 |
|
|