Commit 37decacd authored by Grzegorz Daniluk's avatar Grzegorz Daniluk Committed by Adam Wujek

wrs_watchdog: adding option to store pid file

parent e99115d5
...@@ -200,7 +200,23 @@ void clear_stuck(int cnt[][FSMS_NO]) ...@@ -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; pid_t pid, sid;
...@@ -211,6 +227,7 @@ void daemonize() ...@@ -211,6 +227,7 @@ void daemonize()
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (pid > 0) { if (pid > 0) {
write_pidfile(file, pid);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -273,6 +290,7 @@ void print_help(char *prgname) ...@@ -273,6 +290,7 @@ void print_help(char *prgname)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int c = 0; int c = 0;
char *pidfile = NULL;
prgname = argv[0]; prgname = argv[0];
...@@ -286,7 +304,7 @@ int main(int argc, char *argv[]) ...@@ -286,7 +304,7 @@ int main(int argc, char *argv[])
exit(1); exit(1);
} }
while ((c = getopt(argc, argv, "dhrgn:l")) != -1) { while ((c = getopt(argc, argv, "dhrgn:lp:")) != -1) {
switch (c) { switch (c) {
case 'd': case 'd':
daemon_mode = 1; daemon_mode = 1;
...@@ -304,6 +322,9 @@ int main(int argc, char *argv[]) ...@@ -304,6 +322,9 @@ int main(int argc, char *argv[])
port_num = atoi(optarg); port_num = atoi(optarg);
pr_info("Read %d ports from cmdline\n", port_num); pr_info("Read %d ports from cmdline\n", port_num);
break; break;
case 'p':
pidfile = optarg;
break;
case 'h': case 'h':
default: default:
print_help(prgname); print_help(prgname);
...@@ -322,7 +343,7 @@ int main(int argc, char *argv[]) ...@@ -322,7 +343,7 @@ int main(int argc, char *argv[])
} }
if (daemon_mode) { if (daemon_mode) {
daemonize(); daemonize(pidfile);
pr_info("Demonize\n"); pr_info("Demonize\n");
endless_watchdog(); endless_watchdog();
} }
......
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