Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
cb9e5232
Commit
cb9e5232
authored
Jan 30, 2004
by
Leigh B. Stoller
Browse files
Proper daemonization, create pidfile, output to debug log.
parent
b9283c36
Changes
1
Hide whitespace changes
Inline
Side-by-side
event/linktest/linktest.c
View file @
cb9e5232
...
...
@@ -46,6 +46,7 @@ main(int argc, char **argv) {
char
*
port
=
NULL
;
char
*
keyfile
=
NULL
;
char
*
pideid
=
NULL
;
char
*
pidfile
=
NULL
;
char
*
logfile
=
NULL
;
char
*
progname
;
char
c
;
...
...
@@ -53,7 +54,7 @@ main(int argc, char **argv) {
progname
=
argv
[
0
];
while
((
c
=
getopt
(
argc
,
argv
,
"s:p:e:l:dk:"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"s:p:e:l:dk:
i:
"
))
!=
-
1
)
{
switch
(
c
)
{
case
'd'
:
debug
++
;
...
...
@@ -67,6 +68,9 @@ main(int argc, char **argv) {
case
'e'
:
pideid
=
optarg
;
break
;
case
'i'
:
pidfile
=
optarg
;
break
;
case
'l'
:
logfile
=
optarg
;
break
;
...
...
@@ -139,8 +143,25 @@ main(int argc, char **argv) {
* event system calls.
*/
if
(
!
debug
)
daemon
(
0
,
0
);
daemon
(
0
,
1
);
/*
* Write out a pidfile if root (after we daemonize).
*/
if
(
!
getuid
())
{
FILE
*
fp
;
if
(
pidfile
)
strcpy
(
buf
,
pidfile
);
else
sprintf
(
buf
,
"%s/linktest.pid"
,
_PATH_VARRUN
);
fp
=
fopen
(
buf
,
"w"
);
if
(
fp
!=
NULL
)
{
fprintf
(
fp
,
"%d
\n
"
,
getpid
());
(
void
)
fclose
(
fp
);
}
}
/*
* Begin the event loop, waiting to receive event notifications:
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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