author | Michael Krelin <hacker@klever.net> | 2004-07-23 20:40:46 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-23 20:40:46 (UTC) |
commit | 546858a1e4d13d179a6af27b474e1396cfdf0c29 (patch) (unidiff) | |
tree | ac19b0ff5e4b3164ad5375bda112a9d6d2f88c2b /src/process.cc | |
parent | 76921288a0aa39acb53102863523c388b5d0f9ee (diff) | |
download | dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.zip dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.tar.gz dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.tar.bz2 |
the ability to check/kill/reload any of the processes being monitored added.
-rw-r--r-- | src/process.cc | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/process.cc b/src/process.cc index bfab311..1ffac9f 100644 --- a/src/process.cc +++ b/src/process.cc | |||
@@ -16,19 +16,8 @@ using namespace std; | |||
16 | 16 | ||
17 | void process::check(const string& id,configuration& config) { | 17 | void process::check(const string& id,configuration& config) { |
18 | bool running = false; | 18 | try { |
19 | ifstream pids(pidfile.c_str(),ios::in); | 19 | signal(0); |
20 | if(pids) { | ||
21 | pid_t pid = 0; | ||
22 | pids >> pid; | ||
23 | pids.close(); | ||
24 | if(pid) { | ||
25 | if(!kill(pid,0)) { | ||
26 | running = true; | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | if(running){ | ||
31 | patience = 0; | 20 | patience = 0; |
32 | }else{ | 21 | }catch(exception& e) { |
33 | if(patience>60) { // TODO: configurable | 22 | if(patience>60) { // TODO: configurable |
34 | patience = 0; | 23 | patience = 0; |
@@ -186,2 +175,15 @@ void process::notify_mailto(const string& email,const string& id,const string& e | |||
186 | // TODO: check the return code | 175 | // TODO: check the return code |
187 | } | 176 | } |
177 | |||
178 | void process::signal(int signum) const { | ||
179 | ifstream pids(pidfile.c_str(),ios::in); | ||
180 | if(!pids) | ||
181 | throw runtime_error("no pidfile found"); | ||
182 | pid_t pid = 0; | ||
183 | pids >> pid; | ||
184 | pids.close(); | ||
185 | if(!pid) | ||
186 | throw runtime_error("no pid in pidfile"); | ||
187 | if(kill(pid,signum)) | ||
188 | throw runtime_error("failed to signal process"); | ||
189 | } | ||