]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pidfile: fail if the pid file exists
authorJason Ish <ish@unx.ca>
Fri, 17 Feb 2017 16:46:43 +0000 (10:46 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 21 Feb 2017 08:56:27 +0000 (09:56 +0100)
Changes the pidfile check function to fail just on the
existence of the file to address issue
https://redmine.openinfosecfoundation.org/issues/1335
but log a message if the pid file appears to be stale.

src/util-pidfile.c

index a13e54efedaf36b74d7be7c89a4bfd4a7a84567b..a68188b7e6167d89a35f50a8683f68b27151cc00 100644 (file)
@@ -89,8 +89,13 @@ void SCPidfileRemove(const char *pid_filename)
 }
 
 /**
- * \brief Check a pid file (used at the startup)
- *        This commonly needed by the init scripts
+ * \brief Check the Suricata pid file (used at the startup)
+ *
+ * This commonly needed by the init scripts.
+ *
+ * This function will fail if the PID file exists, but tries to log a
+ * meaningful message if appears Suricata is running, or if the PID
+ * file appears to be stale.
  *
  * \param pointer to the name of the pid file to write (optarg)
  *
@@ -113,15 +118,19 @@ int SCPidfileTestRunning(const char *pid_filename)
         }
 
         if (fscanf(pf, "%d", &pidv) == 1 && kill(pidv, 0) == 0) {
-            fclose(pf);
             SCLogError(SC_ERR_INITIALIZATION,
-                    "pid file '%s' exists. Is Suricata already running? Aborting!",
-                    pid_filename);
-            return -1;
+                    "pid file '%s' exists and Suricata appears to be running. "
+                    "Aborting!", pid_filename);
+        } else {
+            SCLogError(SC_ERR_INITIALIZATION,
+                    "pid file '%s' exists but appears stale. "
+                    "Make sure Suricata is not running and then remove %s. "
+                    "Aborting!",
+                    pid_filename, pid_filename);
         }
 
-        if (pf != NULL)
-            fclose(pf);
+        fclose(pf);
+        return -1;
     }
     return 0;
 }