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

Diff of /monit/spawn.c

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

revision 1.29 by chopp, Wed Aug 13 22:18:43 2003 UTC revision 1.30 by hauk, Fri Aug 15 23:46:23 2003 UTC
# Line 80  Line 80 
80  /* -------------------------------------------------------------- Prototypes */  /* -------------------------------------------------------------- Prototypes */
81    
82    
83    static void set_monit_environment(Service_T s);
84  static void exec_alert_mail(Service_T s, Command_T c);  static void exec_alert_mail(Service_T s, Command_T c);
 static void set_monit_environment(Service_T s, Command_T c);  
85    
86    
87  /* ------------------------------------------------------------------ Public */  /* ------------------------------------------------------------------ Public */
# Line 159  void  spawn(Service_T S, Command_T C) { Line 159  void  spawn(Service_T S, Command_T C) {
159          }          }
160        }        }
161    
162        set_monit_environment(S, C);        set_monit_environment(S);
163                
164        if(! Run.isdaemon) {        if(! Run.isdaemon) {
165          redirect_stdfd();          redirect_stdfd();
# Line 238  static void exec_alert_mail(Service_T s, Line 238  static void exec_alert_mail(Service_T s,
238   * Setup the environment with special MONIT_xxx variables. The program   * Setup the environment with special MONIT_xxx variables. The program
239   * executed may use such variable for various purposes.   * executed may use such variable for various purposes.
240   */   */
241  static void set_monit_environment(Service_T s, Command_T c) {  static void set_monit_environment(Service_T s) {
242    
243    int i;    int i, j;
244    char buf[10][STRLEN];    char buf[10][STRLEN];
245    char *date= get_RFC822date(NULL);    char *date= get_RFC822date(NULL);
246    
247    snprintf(buf[0], STRLEN, "MONIT_PROGRAM_PID=%d", is_process_running(s));    i= 0;
   snprintf(buf[1], STRLEN, "MONIT_PROGRAM=%s", c->arg[0]);  
   snprintf(buf[2], STRLEN, "MONIT_DATE=%s", date);  
   snprintf(buf[3], STRLEN, "MONIT_HOST=%s", Run.localhostname);  
   snprintf(buf[4], STRLEN, "MONIT_PROGRAM_MEMORY=%ld", s->procinfo->mem_kbyte);  
   snprintf(buf[5], STRLEN, "MONIT_PROGRAM_CHILDREN=%d", s->procinfo->children);  
   snprintf(buf[6], STRLEN, "MONIT_PROGRAM_CPU_PERCENT=%d",  
            s->procinfo->cpu_percent);  
248        
249    buf[7][0]= 0;    snprintf(buf[i++], STRLEN, "MONIT_DATE=%s", date);
250      snprintf(buf[i++], STRLEN, "MONIT_SERVICE=%s", s->name);
251    for(i= 0; *buf[i]; i++)    snprintf(buf[i++], STRLEN, "MONIT_HOST=%s", Run.localhostname);
252        putenv(buf[i]);    
253      if(s->type == TYPE_PROCESS) {
254        snprintf(buf[i++], STRLEN, "MONIT_PROCESS_PID=%d", is_process_running(s));
255        snprintf(buf[i++], STRLEN, "MONIT_PROCESS_MEMORY=%ld",
256                 s->procinfo->mem_kbyte);
257        snprintf(buf[i++], STRLEN, "MONIT_PROCESS_CHILDREN=%d",
258                 s->procinfo->children);
259        snprintf(buf[i++], STRLEN, "MONIT_PROCESS_CPU_PERCENT=%d",
260                 s->procinfo->cpu_percent);
261      }
262      
263      buf[i][0]= 0;
264      
265      for(j= 0; *buf[j]; j++)
266          putenv(buf[j]);
267    
268    free(date);    free(date);
269        

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

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