Co-Authored-By: David VaĊĦek <david.vasek@nic.cz>
pid_t pid = pid_read(pidfile);
/* Check PID for existence and liveness. */
- if (pid > 0 && pid_running(pid)) {
+ if (pid > 0 && pid_running(pid) && !pid_current(pid)) {
log_fatal("server PID found, already running");
free(pidfile);
return 0;
}
}
+bool pid_current(pid_t pid)
+{
+ return pid == getpid();
+}
+
bool pid_running(pid_t pid)
{
return kill(pid, 0) == 0;
*/
void pid_cleanup(void);
+/*!
+ * \brief Return true if the PID is the one of the current process.
+ *
+ * \param pid Process ID.
+ *
+ * \retval true if the same.
+ * \retval false if different.
+ */
+bool pid_current(pid_t pid);
+
/*!
* \brief Return true if the PID is running.
*