-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
49 lines (41 loc) · 986 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <cstring>
#include <cstdlib>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <syslog.h>
#include <unistd.h>
#include "daemon.h"
using namespace std;
class proc_d : public iProc<proc_d>{
public:
proc_d():iProc<proc_d>(){}
void sigterm(int signo){
syslog(LOG_INFO, "got SIGTERM; exiting");
exit(0);
}
void sigint(int signo){
syslog(LOG_INFO, "got SIGINT; exiting");
exit(0);
}
void sighup(int signo){
syslog(LOG_INFO, "Re-reading configuration file");
}
};
int main(int argc, char **argv){
string cmd;
string pidfile = "/var/run/daemon/daemon.pid";
string args(argv[0]);
size_t found = args.rfind('/');
if ( found != string::npos ){
cmd = args.substr(found+1);
}else{
cmd = string(argv[0]);
}
proc_d pd;
pd.start(cmd,pidfile);
while(1){
sleep(30);
}
exit(0);
}