From: Jason Ish Date: Fri, 17 Feb 2017 16:46:43 +0000 (-0600) Subject: pidfile: fail if the pid file exists X-Git-Tag: suricata-4.0.0-beta1~287 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92db12c3492d1931e346869695351ca1788869e2;p=thirdparty%2Fsuricata.git pidfile: fail if the pid file exists 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. --- diff --git a/src/util-pidfile.c b/src/util-pidfile.c index a13e54efed..a68188b7e6 100644 --- a/src/util-pidfile.c +++ b/src/util-pidfile.c @@ -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; }