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

Diff of /monit/control.c

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

revision 1.51 by hauk, Wed Jul 2 19:32:02 2003 UTC revision 1.52 by hauk, Wed Jul 16 20:29:28 2003 UTC
# Line 39  Line 39 
39  #include "monitor.h"  #include "monitor.h"
40  #include "net.h"  #include "net.h"
41  #include "socket.h"  #include "socket.h"
42    #include "event.h"
43    
44    
45  /**  /**
# Line 57  Line 58 
58  /* -------------------------------------------------------------- Prototypes */  /* -------------------------------------------------------------- Prototypes */
59    
60    
61    static void *wait_stop(void *);
62    static void *wait_start(void *);
63  static void do_stop(Service_T);  static void do_stop(Service_T);
64  static void do_start(Service_T);  static void do_start(Service_T);
 static void wait_stop(Service_T);  
 static void wait_start(Service_T);  
65  static void do_depend(Service_T, char *);  static void do_depend(Service_T, char *);
66    
67    
# Line 282  static void do_start(Service_T s) { Line 283  static void do_start(Service_T s) {
283    if(s->start && (s->task!=TASK_PROCESS || !is_process_running(s))) {    if(s->start && (s->task!=TASK_PROCESS || !is_process_running(s))) {
284      log("start: (%s) %s\n", s->name, s->start->arg[0]);      log("start: (%s) %s\n", s->name, s->start->arg[0]);
285      spawn(s, s->start);      spawn(s, s->start);
286      if(s->task==TASK_PROCESS)      if(s->task==TASK_PROCESS) {
287        wait_start(s);        int status;
288          pthread_t thread;
289          status= pthread_create(&thread, NULL, wait_start, s);
290          if(status != 0) {
291            log("Warning: Failed to create the start control thread. "
292                "Thread error -- %s.\n", strerror(status));
293          }
294        }
295    }    }
296    
297        
298    LOCK(Run.mutex)    LOCK(Run.mutex)
299      s->do_monitor= TRUE;      s->do_monitor= TRUE;
# Line 317  static void do_stop(Service_T s) { Line 326  static void do_stop(Service_T s) {
326    if(s->stop && (s->task!=TASK_PROCESS || is_process_running(s))) {    if(s->stop && (s->task!=TASK_PROCESS || is_process_running(s))) {
327      log("stop: (%s) %s\n", s->name, s->stop->arg[0]);      log("stop: (%s) %s\n", s->name, s->stop->arg[0]);
328      spawn(s, s->stop);      spawn(s, s->stop);
329      if(s->task==TASK_PROCESS)      if(s->task==TASK_PROCESS) {
330        wait_stop(s);        int status;
331          pthread_t thread;
332          status= pthread_create(&thread, NULL, wait_stop, s);
333          if(status != 0) {
334            log("Warning: Failed to create the stop control thread. "
335                "Thread error -- %s.\n", strerror(status));
336          }
337        }
338    }    }
339        
340    /* Reset the proc info object in case of a later restart */    /* Reset the proc info object in case of a later restart */
341    memset(s->procinfo, 0, sizeof *(s->procinfo));    memset(s->procinfo, 0, sizeof *(s->procinfo));
342        
# Line 370  static void do_depend(Service_T s, char Line 386  static void do_depend(Service_T s, char
386    
387  /*  /*
388   * This function suspend the control until the service s is running.   * This function suspend the control until the service s is running.
389   * @param s A Service to wait for   * @param service A Service to wait for
390   */   */
391  static void wait_start(Service_T s) {  static void *wait_start(void *service) {
392    
393      Service_T s= service;
394    int max_tries= Run.polltime;    int max_tries= Run.polltime;
395        
396    ASSERT(s);    ASSERT(s);
397    
398    while(max_tries--) {    pthread_detach(pthread_self());
399    
400      while(max_tries-- && !Run.stopped) {
401      if(is_process_running(s))      if(is_process_running(s))
402        break;        break;
403      sleep(1);      sleep(1);
404    }    }
405        
406    if(!is_process_running(s))    if(!is_process_running(s)) {
407        log("failed: to start (%s)\n", s->name);      Event_post(s, EVENT_FAILED, "Failed to start '%s'\n", s->name);
408      }
409    
410      return NULL;
411        
412  }  }
413    
414    
415  /*  /*
416   * This function suspend the control until the service s is stopped.   * This function suspend the control until the service s is stopped.
417   * @param s A Service to wait for   * @param service A Service to wait for
418   */   */
419  static void wait_stop(Service_T s) {  static void *wait_stop(void *service) {
420    
421      Service_T s= service;
422    int max_tries= Run.polltime;    int max_tries= Run.polltime;
423        
424    ASSERT(s);    ASSERT(s);
425    
426    while(max_tries--) {    pthread_detach(pthread_self());
427    
428      while(max_tries-- && !Run.stopped) {
429      if(!is_process_running(s))      if(!is_process_running(s))
430        break;        break;
431      sleep(1);      sleep(1);
432    }    }
433    
434    if(is_process_running(s))    if(is_process_running(s)) {
435        log("failed: to stop (%s)\n", s->name);      Event_post(s, EVENT_FAILED, "Failed to stop '%s'\n", s->name);
436      }
437      
438      return NULL;
439    
440  }  }

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52

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