/[monit]/monit/validate.c
ViewVC logotype

Diff of /monit/validate.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.75 by hauk, Thu Aug 14 21:43:14 2003 UTC revision 1.76 by hauk, Fri Aug 15 01:12:56 2003 UTC
# Line 241  static int do_not_validate(Service_T s) Line 241  static int do_not_validate(Service_T s)
241   * Return FALSE in case of a fatal event.   * Return FALSE in case of a fatal event.
242   */   */
243  static int eval_actions(int action, Service_T s, char *report, char *check,  static int eval_actions(int action, Service_T s, char *report, char *check,
244                          int alert_event) {                          int event) {
245    
246    ASSERT(s);    ASSERT(s);
247    ASSERT(check);    ASSERT(check);
# Line 250  static int eval_actions(int action, Serv Line 250  static int eval_actions(int action, Serv
250    switch(action) {    switch(action) {
251    case ACTION_ALERT:    case ACTION_ALERT:
252      if(s->def_timeout) s->nstart++;      if(s->def_timeout) s->nstart++;
253      Event_post(s, alert_event, "Event: %s\n", report);      Event_post(s, event, "Event: %s\n", report);
254      break; /* continue */      break; /* continue */
255            
256    case ACTION_STOP:    case ACTION_STOP:
# Line 262  static int eval_actions(int action, Serv Line 262  static int eval_actions(int action, Serv
262      return FALSE;      return FALSE;
263            
264    case ACTION_EXEC:    case ACTION_EXEC:
265      Event_post(s, alert_event, "Event: %s\n", report);      Event_post(s, event, "Event: %s\n", report);
266      return FALSE;      return FALSE;
267    
268    default:    default:
# Line 308  static int check_timestamps(Service_T s) Line 308  static int check_timestamps(Service_T s)
308  static int check_directory(Service_T s) {  static int check_directory(Service_T s) {
309    
310    struct stat stat_buf;    struct stat stat_buf;
311    char report[STRLEN];    char report[STRLEN]= {0};
312    
313    if(stat(s->path, &stat_buf) != 0) {    if(stat(s->path, &stat_buf) != 0) {
314      Event_post(s, EVENT_RESTART,      Event_post(s, EVENT_RESTART,
# Line 324  static int check_directory(Service_T s) Line 324  static int check_directory(Service_T s)
324    
325    if(check_perm(s, stat_buf.st_mode)) {    if(check_perm(s, stat_buf.st_mode)) {
326      s->perm->event_flag= TRUE;      s->perm->event_flag= TRUE;
327      if(! eval_actions(s->perm->action, s, report, "permission", EVENT_PERMISSION))      if(! eval_actions(s->perm->action, s, report, "permission",
328                          EVENT_PERMISSION))
329        return FALSE;        return FALSE;
330    }    }
331    
# Line 352  static int check_directory(Service_T s) Line 353  static int check_directory(Service_T s)
353  static int check_file(Service_T s) {  static int check_file(Service_T s) {
354    
355    Size_T sl;    Size_T sl;
   char report[STRLEN];  
356    struct stat stat_buf;    struct stat stat_buf;
357      char report[STRLEN]= {0};
358    
359    if(stat(s->path, &stat_buf) != 0) {    if(stat(s->path, &stat_buf) != 0) {
360      Event_post(s, EVENT_RESTART, "Event: file '%s' doesn't exist\n", s->name);      Event_post(s, EVENT_RESTART, "Event: file '%s' doesn't exist\n", s->name);
# Line 367  static int check_file(Service_T s) { Line 368  static int check_file(Service_T s) {
368        
369    if(check_checksum(s)) {    if(check_checksum(s)) {
370      s->checksum->event_flag= TRUE;      s->checksum->event_flag= TRUE;
371      if(! eval_actions(s->checksum->action, s, report, "checksum", EVENT_CHECKSUM))      if(! eval_actions(s->checksum->action, s, report, "checksum",
372                          EVENT_CHECKSUM))
373        return FALSE;        return FALSE;
374    }    }
375    
376    if(check_perm(s, stat_buf.st_mode)) {    if(check_perm(s, stat_buf.st_mode)) {
377      s->perm->event_flag= TRUE;      s->perm->event_flag= TRUE;
378      if(! eval_actions(s->perm->action, s, report, "permission", EVENT_PERMISSION))      if(! eval_actions(s->perm->action, s, report, "permission",
379                          EVENT_PERMISSION))
380        return FALSE;        return FALSE;
381    }    }
382    
# Line 412  static int check_file(Service_T s) { Line 415  static int check_file(Service_T s) {
415  static int check_device(Service_T s) {  static int check_device(Service_T s) {
416    
417    Device_T td;    Device_T td;
   char report[STRLEN];  
418    struct stat stat_buf;    struct stat stat_buf;
419      char report[STRLEN]= {0};
420    
421    if(stat(s->path, &stat_buf) != 0) {    if(stat(s->path, &stat_buf) != 0) {
422      Event_post(s, EVENT_RESTART, "Event: device '%s' doesn't exist\n", s->name);      Event_post(s, EVENT_RESTART, "Event: device '%s' doesn't exist\n", s->name);
# Line 422  static int check_device(Service_T s) { Line 425  static int check_device(Service_T s) {
425        
426    if(check_perm(s, stat_buf.st_mode)) {    if(check_perm(s, stat_buf.st_mode)) {
427      s->perm->event_flag= TRUE;      s->perm->event_flag= TRUE;
428      if(! eval_actions(s->perm->action, s, report, "permission", EVENT_PERMISSION))      if(! eval_actions(s->perm->action, s, report, "permission",
429                          EVENT_PERMISSION))
430        return FALSE;        return FALSE;
431    }    }
432    
# Line 468  static int check_process(Service_T s, Pr Line 472  static int check_process(Service_T s, Pr
472    Port_T pp;    Port_T pp;
473    Resource_T pr;    Resource_T pr;
474    pid_t  pid= -1;    pid_t  pid= -1;
475    char report[STRLEN];    char report[STRLEN]={0};
476        
477    /* Test for running process */    /* Test for running process */
478    if(!(pid= is_process_running(s))) {    if(!(pid= is_process_running(s))) {
# Line 848  static int check_checksum(Service_T s) { Line 852  static int check_checksum(Service_T s) {
852      return FALSE;      return FALSE;
853    
854    if( !check_md5(s->path, s->checksum->md5) ) {    if( !check_md5(s->path, s->checksum->md5) ) {
     Event_post(s, EVENT_CHECKSUM, "'%s' CHECKSUM ERROR for %s\n",  
                s->name, s->path);  
855      return TRUE;      return TRUE;
856    }    }
857        
# Line 874  static int check_perm(Service_T s, mode_ Line 876  static int check_perm(Service_T s, mode_
876      return FALSE;      return FALSE;
877    
878    if( (mode & 07777) != s->perm->perm ) {    if( (mode & 07777) != s->perm->perm ) {
     Event_post(s, EVENT_PERMISSION,  
                "Event: '%s' permission test failed -- "  
                "current permission: %o\n",  
                s->name, mode&07777);  
879      return TRUE;      return TRUE;
880    }    }
881    
# Line 903  static int check_uid(Service_T s, uid_t Line 901  static int check_uid(Service_T s, uid_t
901      return FALSE;      return FALSE;
902    
903    if( uid != s->uid->uid ) {    if( uid != s->uid->uid ) {
     Event_post(s, EVENT_UID,  
                "Event: '%s' uid test failed -- "  
                "current uid: %d\n",  
                s->name, (int)uid);  
904      return TRUE;      return TRUE;
905    }    }
906    
# Line 932  static int check_gid(Service_T s, gid_t Line 926  static int check_gid(Service_T s, gid_t
926      return FALSE;      return FALSE;
927    
928    if( gid != s->gid->gid ) {    if( gid != s->gid->gid ) {
     Event_post(s, EVENT_GID,  
                "Event: '%s' gid test failed -- "  
                "current gid: %d\n",  
                s->name, (int)gid);  
929      return TRUE;      return TRUE;
930    }    }
931    
# Line 993  static int check_timestamp_item(Service_ Line 983  static int check_timestamp_item(Service_
983  /**  /**
984   * Returns TRUE if the size test succeded, otherwise FALSE   * Returns TRUE if the size test succeded, otherwise FALSE
985   */   */
986  static int check_size_item(Service_T s, Size_T sl, unsigned long size, char *report) {  static int check_size_item(Service_T s, Size_T sl, unsigned long size,
987                               char *report) {
988    
989    ASSERT(s);    ASSERT(s);
990    ASSERT(sl);    ASSERT(sl);
# Line 1085  static int check_device_resources(Servic Line 1076  static int check_device_resources(Servic
1076                 t->devinfo->f_blocks, td->limit_percent)) {                 t->devinfo->f_blocks, td->limit_percent)) {
1077            snprintf(report, STRLEN,            snprintf(report, STRLEN,
1078                 "space usage %ld%% matches resource limit [space usage%s%d%%]",                 "space usage %ld%% matches resource limit [space usage%s%d%%]",
1079                     100 * (t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) /                     100*(t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) /
1080                     t->devinfo->f_blocks, operatorshortnames[td->operator],                     t->devinfo->f_blocks, operatorshortnames[td->operator],
1081                     td->limit_percent);                     td->limit_percent);
1082            return FALSE;            return FALSE;
# Line 1103  static int check_device_resources(Servic Line 1094  static int check_device_resources(Servic
1094        }        }
1095        DEBUG("'%s' space usage check passed [current space usage=%.1f%%]\n",        DEBUG("'%s' space usage check passed [current space usage=%.1f%%]\n",
1096              t->name,              t->name,
1097              (float) 100 * (t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) /              (float) 100*(t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) /
1098              t->devinfo->f_blocks);              t->devinfo->f_blocks);
1099        return TRUE;        return TRUE;
1100                

Legend:
Removed from v.1.75  
changed lines
  Added in v.1.76

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26