Skip to content

Commit

Permalink
Ensure 'pid' will be consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Apr 19, 2024
1 parent e32d1ab commit d93d44d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
19 changes: 2 additions & 17 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
#include <utility>
#include <vector>

#ifndef _WIN32
#include <unistd.h>
#else
#include <process.h>
#endif

#include "json.h"

#include <simplecpp.h>
Expand Down Expand Up @@ -139,15 +133,6 @@ static std::vector<std::string> split(const std::string &str, const std::string
return ret;
}

static int getPid()
{
#ifndef _WIN32
return getpid();
#else
return _getpid();
#endif
}

static std::string getDumpFileName(const Settings& settings, const std::string& filename)
{
if (!settings.dumpFile.empty())
Expand All @@ -157,7 +142,7 @@ static std::string getDumpFileName(const Settings& settings, const std::string&
if (settings.dump)
extension = ".dump";
else
extension = "." + std::to_string(getPid()) + ".dump";
extension = "." + std::to_string(settings.pid) + ".dump";

if (!settings.dump && !settings.buildDir.empty())
return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, filename, emptyString) + extension;
Expand Down Expand Up @@ -1409,7 +1394,7 @@ void CppCheck::executeAddons(const std::vector<std::string>& files, const std::s
std::string fileList;

if (files.size() >= 2 || endsWith(files[0], ".ctu-info")) {
fileList = Path::getPathFromFilename(files[0]) + FILELIST + std::to_string(getPid());
fileList = Path::getPathFromFilename(files[0]) + FILELIST + std::to_string(mSettings.pid);
filesDeleter.addFile(fileList);
std::ofstream fout(fileList);
for (const std::string& f: files)
Expand Down
17 changes: 17 additions & 0 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

#include "json.h"

#ifndef _WIN32
#include <unistd.h> // for getpid()
#else
#include <process.h> // for getpid()
#endif


std::atomic<bool> Settings::mTerminated;

const char Settings::SafeChecks::XmlRootName[] = "safe-checks";
Expand All @@ -37,12 +44,22 @@ const char Settings::SafeChecks::XmlExternalFunctions[] = "external-functions";
const char Settings::SafeChecks::XmlInternalFunctions[] = "internal-functions";
const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables";

static int getPid()
{
#ifndef _WIN32
return getpid();
#else
return _getpid();
#endif
}

Settings::Settings()
{
severity.setEnabled(Severity::error, true);
certainty.setEnabled(Certainty::normal, true);
setCheckLevel(Settings::CheckLevel::exhaustive);
executor = defaultExecutor();
pid = getPid();
}

std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppressions)
Expand Down
3 changes: 3 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
/** @brief max number of sets of arguments to pass to subfuncions in valueflow */
int performanceValueFlowMaxSubFunctionArgs = 256;

/** @brief pid of cppcheck. Intention is that this is set in the main process. */
int pid;

/** @brief plist output (--plist-output=&lt;dir&gt;) */
std::string plistOutput;

Expand Down

0 comments on commit d93d44d

Please sign in to comment.