summaryrefslogtreecommitdiffabout
path: root/src/process.cc
Unidiff
Diffstat (limited to 'src/process.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/process.cc30
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
@@ -15,21 +15,10 @@ using namespace std;
15#include "configuration.h" 15#include "configuration.h"
16 16
17void process::check(const string& id,configuration& config) { 17void 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;
35 }else{ 24 }else{
@@ -185,3 +174,16 @@ void process::notify_mailto(const string& email,const string& id,const string& e
185 waitpid(pid,&status,0); 174 waitpid(pid,&status,0);
186 // TODO: check the return code 175 // TODO: check the return code
187} 176}
177
178void 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}