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

Diff of /monit/spawn.c

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

revision 1.12 by hauk, Thu Aug 29 22:50:47 2002 UTC revision 1.13 by hauk, Fri Sep 6 17:24:53 2002 UTC
# Line 54  Line 54 
54    
55  /* Private prototypes */  /* Private prototypes */
56  static void do_free();  static void do_free();
57  static Command_T copy_command(Command_T C);  static Command_T copy_command(Command_T);
58    static Mail_T create_exec_alert_list(Process_T, Command_T);
59    
60    
61  /**  /**
# Line 113  void  spawn(Process_T P, Command_T C) { Line 114  void  spawn(Process_T P, Command_T C) {
114      } else  {      } else  {
115    
116        Command_T c= copy_command(C);        Command_T c= copy_command(C);
117          Mail_T alert_list= create_exec_alert_list(P, C);
118                
119        /*        /*
120         * Reset all signals, so the child process is         * Reset all signals, so the child process is
# Line 134  void  spawn(Process_T P, Command_T C) { Line 136  void  spawn(Process_T P, Command_T C) {
136         * same file creation mask monit was started with         * same file creation mask monit was started with
137         */         */
138        umask(Run.umask);        umask(Run.umask);
139          
140        /*        /*
141         * The exec statement done by the second child         * The exec statement done by the second child
142         */         */
143        (void) execv(c->arg[0], c->arg);        (void) execv(c->arg[0], c->arg);
144          sendmail(alert_list);
145        log("Could not execute %s\n", c->arg[0]);        log("Could not execute %s\n", c->arg[0]);
146          gc_mail_list(&alert_list);
147        _exit (1);        _exit (1);
148                
149      }      }
       
150    }    }
151    
152    /* Wait for first child - aka second parent, to exit */    /* Wait for first child - aka second parent, to exit */
# Line 181  static void do_free() { Line 184  static void do_free() {
184    free(Run.pidfile);    free(Run.pidfile);
185    free(Run.logfile);    free(Run.logfile);
186    free(Run.localhostname);    free(Run.localhostname);
   free(Run.mailserver);  
187    free(Run.Env.user);    free(Run.Env.user);
188    free(Run.Env.home);    free(Run.Env.home);
189    free(Run.Env.cwd);    free(Run.Env.cwd);
# Line 191  static void do_free() { Line 193  static void do_free() {
193    free(Run.MailFormat.subject);    free(Run.MailFormat.subject);
194    free(Run.MailFormat.message);    free(Run.MailFormat.message);
195    free(Run.bind_addr);    free(Run.bind_addr);
196      /* Run.mailserver is not freed since it's used in exec alert */
197    
198  }  }
199    
# Line 210  static Command_T copy_command(Command_T Line 213  static Command_T copy_command(Command_T
213        
214  }  }
215    
216    
217    /*
218     * Create a list of mail addresses to send mail to in case the exec
219     * fails. Only mail objects that has registred interest for restart
220     * notification is used.
221     */
222    static Mail_T create_exec_alert_list(Process_T p, Command_T c) {
223    
224      Mail_T l= NULL;
225      Mail_T h= p->maillist;
226    
227      for(; h; h= h->next)
228          if(h->alert_on_restart) {
229            
230            Mail_T n= NEW(n);
231            char *message= xmalloc(STRLEN);
232            
233            n->to= xstrdup(h->to);
234            n->from= xstrdup("monit@localhost");
235            n->subject= xstrdup("monit alert -- exec error");
236            snprintf(message, STRLEN,
237             "NOTE, THIS EMAIL TAKES PRECEDENCE OVER SUBSEQUENT RESTART ALERTS\n\n"
238                     "Could not execute program '%s' for process %s\n\n"
239                     "Your faithful employee,\nmonit",
240                       c->arg[0]?c->arg[0]:"null", p->name);
241            n->message= message;
242            if(l)
243                n->next= l;
244            l= n;
245            
246          }
247    
248      return l;
249      
250    }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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