Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
84
Issues
84
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Software
Commits
37decacd
Commit
37decacd
authored
Jul 02, 2015
by
Grzegorz Daniluk
Committed by
Adam Wujek
Jul 10, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrs_watchdog: adding option to store pid file
parent
e99115d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
wrs_watchdog.c
userspace/wrs_watchdog/wrs_watchdog.c
+24
-3
No files found.
userspace/wrs_watchdog/wrs_watchdog.c
View file @
37decacd
...
...
@@ -200,7 +200,23 @@ void clear_stuck(int cnt[][FSMS_NO])
}
}
void
daemonize
()
void
write_pidfile
(
char
*
file
,
pid_t
pid
)
{
FILE
*
f
;
if
(
file
==
NULL
)
return
;
f
=
fopen
(
file
,
"w"
);
if
(
f
==
NULL
)
{
pr_error
(
"Could not create PID file
\n
"
);
return
;
}
fprintf
(
f
,
"%d
\n
"
,
(
int
)
pid
);
fclose
(
f
);
}
void
daemonize
(
char
*
file
)
{
pid_t
pid
,
sid
;
...
...
@@ -211,6 +227,7 @@ void daemonize()
exit
(
EXIT_FAILURE
);
}
if
(
pid
>
0
)
{
write_pidfile
(
file
,
pid
);
exit
(
EXIT_SUCCESS
);
}
...
...
@@ -273,6 +290,7 @@ void print_help(char *prgname)
int
main
(
int
argc
,
char
*
argv
[])
{
int
c
=
0
;
char
*
pidfile
=
NULL
;
prgname
=
argv
[
0
];
...
...
@@ -286,7 +304,7 @@ int main(int argc, char *argv[])
exit
(
1
);
}
while
((
c
=
getopt
(
argc
,
argv
,
"dhrgn:l"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"dhrgn:l
p:
"
))
!=
-
1
)
{
switch
(
c
)
{
case
'd'
:
daemon_mode
=
1
;
...
...
@@ -304,6 +322,9 @@ int main(int argc, char *argv[])
port_num
=
atoi
(
optarg
);
pr_info
(
"Read %d ports from cmdline
\n
"
,
port_num
);
break
;
case
'p'
:
pidfile
=
optarg
;
break
;
case
'h'
:
default:
print_help
(
prgname
);
...
...
@@ -322,7 +343,7 @@ int main(int argc, char *argv[])
}
if
(
daemon_mode
)
{
daemonize
();
daemonize
(
pidfile
);
pr_info
(
"Demonize
\n
"
);
endless_watchdog
();
}
...
...
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