]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
Fix: Reuse PID file if current PID matches
authorBerbe <54095-Berbe@users.noreply.gitlab.nic.cz>
Mon, 27 Oct 2025 10:24:01 +0000 (10:24 +0000)
committerBerbe <54095-Berbe@users.noreply.gitlab.nic.cz>
Fri, 31 Oct 2025 10:51:08 +0000 (10:51 +0000)
Co-Authored-By: David VaĊĦek <david.vasek@nic.cz>
src/knot/common/process.c
src/knot/common/process.h

index cda00797c06abe8cd4b5a1844e5e83b2e1c8f772..115d3bd959837f3a0d4b3300eaf8cca55f92cf4a 100644 (file)
@@ -101,7 +101,7 @@ unsigned long pid_check_and_create(void)
        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;
@@ -136,6 +136,11 @@ void pid_cleanup(void)
        }
 }
 
+bool pid_current(pid_t pid)
+{
+       return pid == getpid();
+}
+
 bool pid_running(pid_t pid)
 {
        return kill(pid, 0) == 0;
index f64e77b39b2447dc253e0a0bb424b25f7afdb7bd..05b1bf86b09f4eb50e68e26443e9b02c134e8838 100644 (file)
@@ -27,6 +27,16 @@ unsigned long pid_check_and_create(void);
  */
 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.
  *