52 |
#include "monitor.h" |
#include "monitor.h" |
53 |
#include "engine.h" |
#include "engine.h" |
54 |
|
|
|
/* Private prototypes */ |
|
|
static void do_free(); |
|
|
static Command_T copy_command(Command_T); |
|
|
static Mail_T create_exec_alert_list(Process_T, Command_T); |
|
|
|
|
55 |
|
|
56 |
/** |
/** |
57 |
* Function for spawning of a process. This function fork's twice to |
* Function for spawning of a process. This function fork's twice to |
66 |
*/ |
*/ |
67 |
|
|
68 |
|
|
69 |
|
/* -------------------------------------------------------------- Prototypes */ |
70 |
|
|
71 |
|
|
72 |
|
static void do_free(); |
73 |
|
static Command_T copy_command(Command_T); |
74 |
|
static Mail_T create_exec_alert_list(Service_T, Command_T); |
75 |
|
|
76 |
|
|
77 |
/* ------------------------------------------------------------------ Public */ |
/* ------------------------------------------------------------------ Public */ |
78 |
|
|
79 |
|
|
80 |
/** |
/** |
81 |
* Execute the given command. If the execution fails, an alert message |
* Execute the given command. If the execution fails, an alert message |
82 |
* is sent to the email addresses found in the process object that has |
* is sent to the email addresses found in the service object that has |
83 |
* registred interest for restart alerts. |
* registred interest for restart alerts. |
84 |
* @param P A Process object |
* @param P A Service object |
85 |
* @param C A Command object |
* @param C A Command object |
86 |
*/ |
*/ |
87 |
void spawn(Process_T P, Command_T C) { |
void spawn(Service_T S, Command_T C) { |
88 |
|
|
89 |
pid_t pid; |
pid_t pid; |
90 |
sigset_t mask, save; |
sigset_t mask, save; |
91 |
|
|
92 |
ASSERT(P); |
ASSERT(S); |
93 |
ASSERT(C); |
ASSERT(C); |
94 |
|
|
95 |
/* |
/* |
120 |
} else { |
} else { |
121 |
|
|
122 |
Command_T c= copy_command(C); |
Command_T c= copy_command(C); |
123 |
Mail_T alert_list= create_exec_alert_list(P, C); |
Mail_T alert_list= create_exec_alert_list(S, C); |
124 |
|
|
125 |
/* |
/* |
126 |
* Reset all signals, so the child process is |
* Reset all signals, so the child process is |
253 |
* fails. Only mail objects that has registred interest for restart |
* fails. Only mail objects that has registred interest for restart |
254 |
* notification is used. |
* notification is used. |
255 |
*/ |
*/ |
256 |
static Mail_T create_exec_alert_list(Process_T p, Command_T c) { |
static Mail_T create_exec_alert_list(Service_T s, Command_T c) { |
257 |
|
|
258 |
Mail_T l= NULL; |
Mail_T l= NULL; |
259 |
Mail_T h= p->maillist; |
Mail_T h= s->maillist; |
260 |
|
|
261 |
for(; h; h= h->next) |
for(; h; h= h->next) |
262 |
if(h->alert_on_restart) { |
if(h->alert_on_restart) { |
269 |
n->subject= xstrdup("monit alert -- exec error"); |
n->subject= xstrdup("monit alert -- exec error"); |
270 |
snprintf(message, STRLEN, |
snprintf(message, STRLEN, |
271 |
"NOTE, THIS EMAIL TAKES PRECEDENCE OVER SUBSEQUENT RESTART ALERTS\n\n" |
"NOTE, THIS EMAIL TAKES PRECEDENCE OVER SUBSEQUENT RESTART ALERTS\n\n" |
272 |
"Could not execute program '%s' for process %s\n\n" |
"Could not execute program '%s' for service %s\n\n" |
273 |
"Your faithful employee,\nmonit", |
"Your faithful employee,\nmonit", |
274 |
c->arg[0]?c->arg[0]:"null", p->name); |
c->arg[0]?c->arg[0]:"null", s->name); |
275 |
n->message= message; |
n->message= message; |
276 |
n->next= l; |
n->next= l; |
277 |
l= n; |
l= n; |