summaryrefslogtreecommitdiffabout
path: root/src/process.cc
authorMichael Krelin <hacker@klever.net>2004-07-23 20:40:46 (UTC)
committer Michael Krelin <hacker@klever.net>2004-07-23 20:40:46 (UTC)
commit546858a1e4d13d179a6af27b474e1396cfdf0c29 (patch) (side-by-side diff)
treeac19b0ff5e4b3164ad5375bda112a9d6d2f88c2b /src/process.cc
parent76921288a0aa39acb53102863523c388b5d0f9ee (diff)
downloaddudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.zip
dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.tar.gz
dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.tar.bz2
the ability to check/kill/reload any of the processes being monitored added.
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;
#include "configuration.h"
void process::check(const string& id,configuration& config) {
- bool running = false;
- ifstream pids(pidfile.c_str(),ios::in);
- if(pids) {
- pid_t pid = 0;
- pids >> pid;
- pids.close();
- if(pid) {
- if(!kill(pid,0)) {
- running = true;
- }
- }
- }
- if(running){
+ try {
+ signal(0);
patience = 0;
- }else{
+ }catch(exception& e) {
if(patience>60) { // TODO: configurable
patience = 0;
}else{
@@ -185,3 +174,16 @@ void process::notify_mailto(const string& email,const string& id,const string& e
waitpid(pid,&status,0);
// TODO: check the return code
}
+
+void process::signal(int signum) const {
+ ifstream pids(pidfile.c_str(),ios::in);
+ if(!pids)
+ throw runtime_error("no pidfile found");
+ pid_t pid = 0;
+ pids >> pid;
+ pids.close();
+ if(!pid)
+ throw runtime_error("no pid in pidfile");
+ if(kill(pid,signum))
+ throw runtime_error("failed to signal process");
+}