Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Geithner, Thomas
desk-control
Commits
48bd9b63
Commit
48bd9b63
authored
Oct 11, 2017
by
Geithner, Thomas
Browse files
fixed bugs on argument parsing and deamonizing, added PID file handling
parent
541c8a79
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/desk-main.cpp
View file @
48bd9b63
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment