/[monit]/monit/p.y
ViewVC logotype

Diff of /monit/p.y

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

revision 1.49 by hauk, Fri Dec 20 17:45:38 2002 UTC revision 1.50 by hauk, Fri Dec 20 23:15:21 2002 UTC
# Line 127  Line 127 
127    extern char *yytext;    extern char *yytext;
128        
129    /* Local variables */    /* Local variables */
   static int cfg_errflag= FALSE;  
130    static Process_T tail= NULL;    static Process_T tail= NULL;
131      static int cfg_errflag= FALSE;
132    static Process_T current= NULL;    static Process_T current= NULL;
133    static Command_T command= NULL;    static Command_T command= NULL;
134    static struct IHavePrecedence ihp= { FALSE, FALSE };    static Process_T depend_list= NULL;
135    static struct MailFilter mtf= { NULL, NULL, NULL, FALSE, FALSE, FALSE,    static struct IHavePrecedence ihp= {FALSE, FALSE};
136                                    FALSE, FALSE, FALSE };    static struct MailFilter mtf= {NULL, NULL, NULL, FALSE, FALSE, FALSE,
137    static struct PortSet portset= { -1, NULL, 0, SOCK_STREAM, AF_INET, FALSE,                                   FALSE, FALSE, FALSE};
138                                     NULL, NULL, NULL, NULL };    static struct PortSet portset= {-1, NULL, 0, SOCK_STREAM, AF_INET, FALSE,
139    static struct ResourceSet resourceset= { 0, 0, OPERATOR_EQUAL, 1, ACTION_ALERT };                                    NULL, NULL, NULL, NULL};
140    static struct TimestampSet timestampset= { NULL, OPERATOR_EQUAL, 0, ACTION_ALERT };    static struct ResourceSet resourceset= {0, 0, OPERATOR_EQUAL, 1,
141                                              ACTION_ALERT};
142      static struct TimestampSet timestampset= {NULL, OPERATOR_EQUAL, 0,
143                                                ACTION_ALERT};
144    
145    /* Private prototypes */    /* Private prototypes */
146    static void initialize();    static void initialize();
# Line 169  Line 172 
172    static char *append_hostname(char *);    static char *append_hostname(char *);
173    static void cleanup_md5_string(char *);    static void cleanup_md5_string(char *);
174    static void check_depend();    static void check_depend();
175    static void search_depend(Process_T p);    static void order_depend(Process_T);
176      static void validate_depend(Process_T, int *);
177  %}  %}
178    
179  %union {  %union {
# Line 651  int parse(char *controlfile) { Line 655  int parse(char *controlfile) {
655    
656    /* Creation of the global process list is synchronized  */    /* Creation of the global process list is synchronized  */
657    LOCK(Run.mutex)    LOCK(Run.mutex)
658          
659        initialize();        initialize();
660        yyparse();        yyparse();
661    END_LOCK;        fclose(yyin);
         
   fclose(yyin);  
   
   /* If defined - add the last process to the process list */  
   if ( current ) {  
662    
663      createprocinfo();        /* If defined - add the last process to the process list */
664      addprocess(current);        if(current) {
665            
666    }          createprocinfo();
667            addprocess(current);
668    /* Post-parse check the sanity of any dependency graph */          
669    check_depend();        }
670          
671          /* Check the sanity of any dependency graph */
672          check_depend();
673      END_LOCK;
674            
675    return ( cfg_errflag == 0 );    return ( cfg_errflag == 0 );
676        
# Line 1323  static void check_hostname(char *hostnam Line 1327  static void check_hostname(char *hostnam
1327    
1328    
1329  /*  /*
1330   * Check the dependency graph for any errors   * Check the dependency graph for errors and if dependencies are
1331     * present reshuffle the process list in a depending order.
1332   */   */
1333  static void check_depend() {  static void check_depend() {
1334    
1335    Process_T p;    Process_T p;
1336      int has_depend= FALSE;
1337        
1338    for (p= processlist; p; p= p->next) {    for (p= processlist; p; p= p->next) {
1339      if(p->visited)      if(p->visited)
1340          continue;          continue;
1341      search_depend(p);      validate_depend(p, &has_depend);
1342      reset_depend();      reset_depend();
1343    }    }
1344        
1345      if(has_depend) {
1346        
1347        Process_T d;
1348        
1349        for (p= processlist; p; p= p->next) {
1350          if(p->visited)
1351              continue;
1352          order_depend(p);
1353        }
1354        
1355        processlist= depend_list;
1356        
1357        for(d= depend_list; d; d= d->next_depend)
1358            d->next= d->next_depend;
1359        
1360      }
1361    
1362    reset_depend();    reset_depend();
1363        
1364  }  }
# Line 1400  static void cleanup_md5_string(char *md5 Line 1423  static void cleanup_md5_string(char *md5
1423  /*  /*
1424   * Search for any errors in the process dependency graph   * Search for any errors in the process dependency graph
1425   */   */
1426  static void search_depend(Process_T p) {  static void validate_depend(Process_T p, int *has_depend) {
1427    
1428    if(p->visited)    if(p->visited)
1429        return;        return;
# Line 1426  static void search_depend(Process_T p) { Line 1449  static void search_depend(Process_T p) {
1449        }        }
1450                
1451        dp->depend_visited= TRUE;        dp->depend_visited= TRUE;
1452        search_depend(dp);        *has_depend= TRUE;
1453          validate_depend(dp, has_depend);
1454                
1455      }      }
1456    }    }
1457      
1458      p->visited= TRUE;
1459    
1460    }
1461    
1462    
1463    /*
1464     * Order the process list with the most "depending" process last and
1465     * the least first.
1466     */
1467    static void order_depend(Process_T p) {
1468    
1469      if(p->visited)
1470          return;
1471    
1472    p->visited= TRUE;    p->visited= TRUE;
1473    
1474      if(p->dependantlist) {
1475        
1476        Dependant_T d;
1477        
1478        for(d= p->dependantlist; d; d= d->next ) {
1479          
1480          Process_T dp= get_process(d->dependant);
1481          
1482          order_depend(dp);
1483          
1484        }
1485      }
1486    
1487      p->next_depend= depend_list;
1488      depend_list= p;
1489    
1490  }  }

Legend:
Removed from v.1.49  
changed lines
  Added in v.1.50

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