Commit 48bd9b63 authored by Geithner, Thomas's avatar Geithner, Thomas
Browse files

fixed bugs on argument parsing and deamonizing, added PID file handling

parent 541c8a79
......@@ -18,46 +18,56 @@ using namespace std;
using namespace desk;
void print_help(void){
cout << "\t-c / --config <config_file> : config file" << endl;
cout << "\t-d / --daemon : daemonize" << endl;
cout << "\t-h / --help : print help" << endl;
}
int main(int argc, char** argv){
char c;
int c;
uint16_t coap_port;
int opt_idx;
bool daemonize(false);
string config_file("/etc/desk.conf");
string pid_file("/var/run/desk.pid");
static struct option l_opts[] = {
{"config", 1, 0, 'c'},
{"daemon", 0, 0, 'd'},
{"pifdile", 1, 0, 'p'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
while(true){
c = getopt_long(argc, argv, "c:dh", l_opts, &opt_idx);
int opt_idx = 0;
c = getopt_long(argc, argv, "c:dhp:", l_opts, &opt_idx);
if(c == -1){
break;
}
switch(c){
case 0:
break;
case 'c':
// config
config_file = optarg;
break;
case 'p':
// pid file
pid_file = optarg;
break;
case 'd':
daemonize=true;
// daemon
daemonize=true;
break;
case 'h':
print_help();
// help
cout << "\t-c / --config <config_file> : config file" << endl;
cout << "\t-d / --daemon : daemonize" << endl;
cout << "\t-h / --help : print help" << endl;
return 0;
break;
default:
break;
}
}
......@@ -65,17 +75,26 @@ int main(int argc, char** argv){
LinakDesk desk(conf);
if(!daemonize){
CmdFrontend cf(desk);
}
coap_port = conf.get("coap_port", 5678);
CoapFrontend cof(desk, coap_port);
desk.doDeskControl();
if(daemonize){
if(!daemonize){
CmdFrontend cf(desk);
CoapFrontend cof(desk, coap_port);
desk.doDeskControl();
} else{
daemon(0, 0);
pid_t pid = getpid();
ofstream pf(pid_file);
if(pf.is_open()){
pf << to_string(pid);
pf.close();
} else{
cerr << "could not write PID file" << endl;
}
CoapFrontend cof(desk, coap_port);
desk.doDeskControl();
}
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment