summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-08-03 17:57:59 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-08-03 17:57:59 +0200
commit1404fbfe4bf90d7f9dfe36deda484fe3e91b4472 (patch)
treea4ebd103d84e857fddae10030ff1746306f94e20
parent3989e5b19a1472d270c7068b5c69f2eecf0ddeb4 (diff)
downloadabrt-1404fbfe4bf90d7f9dfe36deda484fe3e91b4472.tar.gz
abrt-1404fbfe4bf90d7f9dfe36deda484fe3e91b4472.tar.xz
abrt-1404fbfe4bf90d7f9dfe36deda484fe3e91b4472.zip
lib/Plugins/CCpp.cpp: move functions out of class where appropriate.
I was struggling to read the code where classes have member functions with no apparent reasons to be such: they do not use any members of the class. Having them members of the class have only disadvantages: they need to be declared in the class (thus you need to touch TWO files), they cannot be shared among different classes, they look confusing at callsites - the code falsely suggests that function uses or alters object's state, they also are a bit less efficient. I was hesitating to do so before, but now I was told that there is a plan to gradually move to C implementation... then this change makes it a bit closer to that. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--lib/Plugins/CCpp.cpp41
-rw-r--r--lib/Plugins/CCpp.h9
2 files changed, 17 insertions, 33 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 0cbcdcc0..9f9b8743 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -48,21 +48,13 @@
#define FILENAME_BACKTRACE "backtrace"
#define FILENAME_MEMORYMAP "memorymap"
+static pid_t ExecVP(const char* pCommand, char* const pArgs[], uid_t uid, std::string& pOutput);
+
CAnalyzerCCpp::CAnalyzerCCpp() :
- m_bMemoryMap(false),
- m_Pid(0)
+ m_bMemoryMap(false)
{}
-CAnalyzerCCpp::~CAnalyzerCCpp()
-{
- if (m_Pid)
- {
- kill(m_Pid, SIGTERM);
- wait(NULL);
- }
-}
-
-std::string CAnalyzerCCpp::CreateHash(const std::string& pInput)
+static std::string CreateHash(const std::string& pInput)
{
std::string ret = "";
HASHContext* hc;
@@ -94,7 +86,7 @@ std::string CAnalyzerCCpp::CreateHash(const std::string& pInput)
return hash_str;
}
-void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage)
+static void InstallDebugInfos(const std::string& pPackage)
{
comm_layer_inner_status("Searching for debug-info packages...");
@@ -108,7 +100,6 @@ void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage)
pipe(pipeout);
child = fork();
- m_Pid = child;
if (child < 0)
{
close(pipein[0]); close(pipeout[0]);
@@ -180,7 +171,7 @@ void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage)
close(pipeout[0]);
kill(child, SIGTERM);
wait(NULL);
- throw CABRTException(EXCEP_PLUGIN, "CAnalyzerCCpp::InstallDebugInfos(): cannot install debuginfos for " + pPackage);
+ throw CABRTException(EXCEP_PLUGIN, string(__func__) + ": cannot install debuginfos for " + pPackage);
}
if (strstr(buff, "Total download size") != NULL)
{
@@ -191,7 +182,7 @@ void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage)
close(pipeout[0]);
kill(child, SIGTERM);
wait(NULL);
- throw CABRTException(EXCEP_PLUGIN, "CAnalyzerCCpp::InstallDebugInfos(): cannot install debuginfos for " + pPackage);
+ throw CABRTException(EXCEP_PLUGIN, string(__func__) + ": cannot install debuginfos for " + pPackage);
}
comm_layer_inner_status("Downloading and installing debug-info packages...");
}
@@ -200,10 +191,9 @@ void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage)
close(pipeout[0]);
wait(NULL);
- m_Pid = 0;
}
-void CAnalyzerCCpp::GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace)
+static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace)
{
comm_layer_inner_status("Getting backtrace...");
@@ -235,7 +225,7 @@ void CAnalyzerCCpp::GetBacktrace(const std::string& pDebugDumpDir, std::string&
ExecVP(command, args, atoi(UID.c_str()), pBacktrace);
}
-void CAnalyzerCCpp::GetIndependentBacktrace(const std::string& pBacktrace, std::string& pIndependentBacktrace)
+static void GetIndependentBacktrace(const std::string& pBacktrace, std::string& pIndependentBacktrace)
{
int ii = 0;
std::string line;
@@ -331,7 +321,7 @@ void CAnalyzerCCpp::GetIndependentBacktrace(const std::string& pBacktrace, std::
}
}
-void CAnalyzerCCpp::GetIndependentBuildIdPC(const std::string& pBuildIdPC, std::string& pIndependentBuildIdPC)
+static void GetIndependentBuildIdPC(const std::string& pBuildIdPC, std::string& pIndependentBuildIdPC)
{
int ii = 0;
while (ii < pBuildIdPC.length())
@@ -361,7 +351,7 @@ void CAnalyzerCCpp::GetIndependentBuildIdPC(const std::string& pBuildIdPC, std::
}
}
-void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], uid_t uid, std::string& pOutput)
+static pid_t ExecVP(const char* pCommand, char* const pArgs[], uid_t uid, std::string& pOutput)
{
int pipeout[2];
char buff[1024];
@@ -372,17 +362,16 @@ void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], uid_t uid,
struct passwd* pw = getpwuid(uid);
if (!pw)
{
- throw CABRTException(EXCEP_PLUGIN, "CAnalyzerCCpp::ExecVP(): cannot get GID for UID.");
+ throw CABRTException(EXCEP_PLUGIN, string(__func__) + ": cannot get GID for UID.");
}
pipe(pipeout); /* error check? */
child = fork();
- m_Pid = child;
if (child == -1)
{
close(pipeout[0]);
close(pipeout[1]);
- throw CABRTException(EXCEP_PLUGIN, "CAnalyzerCCpp::ExecVP(): fork failed.");
+ throw CABRTException(EXCEP_PLUGIN, string(__func__) + ": fork failed.");
}
if (child == 0)
{
@@ -451,7 +440,8 @@ I think the below code has absolutely the same effect:
close(pipeout[0]);
wait(NULL); /* why? */
- m_Pid = 0;
+
+ return 0;
}
std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir)
@@ -477,6 +467,7 @@ std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir)
GetIndependentBuildIdPC(buildIdPC, independentBuildIdPC);
return CreateHash(package + executable + independentBuildIdPC);
}
+
std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir)
{
comm_layer_inner_status("Getting global universal unique identification...");
diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h
index a6bb6aaa..ac21e8db 100644
--- a/lib/Plugins/CCpp.h
+++ b/lib/Plugins/CCpp.h
@@ -31,18 +31,11 @@ class CAnalyzerCCpp : public CAnalyzer
{
private:
bool m_bMemoryMap;
- pid_t m_Pid;
std::string m_sOldCorePattern;
std::string m_sDebugInfo;
- void InstallDebugInfos(const std::string& pPackage);
- void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace);
- void GetIndependentBacktrace(const std::string& pBacktrace, std::string& pIndependentBacktrace);
- void GetIndependentBuildIdPC(const std::string& pBuildIdPC, std::string& pIndependentBuildIdPC);
- void ExecVP(const char* pCommand, char* const pArgs[], uid_t uid, std::string& pOutput);
- std::string CreateHash(const std::string& pInput);
public:
CAnalyzerCCpp();
- virtual ~CAnalyzerCCpp();
+ /*virtual ~CAnalyzerCCpp();*/
virtual std::string GetLocalUUID(const std::string& pDebugDumpDir);
virtual std::string GetGlobalUUID(const std::string& pDebugDumpDir);
virtual void CreateReport(const std::string& pDebugDumpDir);