mirror of https://github.com/nirenjan/libx52.git
Disable use of PID file when running in foreground
When running in foreground, it is likely that it is running within systemd. In this case, a stale PID file is likely to have a PID that corresponds to a different process, which can still be kill'ed by the root user. This results in a false positive that the process is still running and causes the daemon to abort prematurely. Fixes #42reverse-scroll
parent
6a8dff0a17
commit
8c8f261c80
|
@ -105,6 +105,7 @@ static void start_daemon(bool foreground, const char *pid_file)
|
||||||
pid_file = X52D_PID_FILE;
|
pid_file = X52D_PID_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!foreground) {
|
||||||
/* Check if there is an existing daemon process running */
|
/* Check if there is an existing daemon process running */
|
||||||
pid_fd = fopen(pid_file, "r");
|
pid_fd = fopen(pid_file, "r");
|
||||||
if (pid_fd != NULL) {
|
if (pid_fd != NULL) {
|
||||||
|
@ -124,7 +125,6 @@ static void start_daemon(bool foreground, const char *pid_file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foreground) {
|
|
||||||
/* Fork off the parent process */
|
/* Fork off the parent process */
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
|
@ -163,7 +163,6 @@ static void start_daemon(bool foreground, const char *pid_file)
|
||||||
/* Terminate the parent */
|
/* Terminate the parent */
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Write the PID to the pid_file */
|
/* Write the PID to the pid_file */
|
||||||
pid_fd = fopen(pid_file, "w");
|
pid_fd = fopen(pid_file, "w");
|
||||||
|
@ -181,7 +180,6 @@ static void start_daemon(bool foreground, const char *pid_file)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foreground) {
|
|
||||||
/* Set new file permissions */
|
/* Set new file permissions */
|
||||||
umask(0);
|
umask(0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue