diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-02-11 10:44:40 +0100 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-02-11 10:44:40 +0100 |
| commit | 356da89a4e2e6e50ceade12f286d104fe1c17eae (patch) | |
| tree | 1fafbfebd44b937eb63906453a285ad5a4b1558a | |
| parent | 3192f468fa5e7f10c664cca671246f962d1d36d1 (diff) | |
| parent | 08ec10a5f6a2d6159e926cb075ad3eb4964ced50 (diff) | |
| download | abrt-356da89a4e2e6e50ceade12f286d104fe1c17eae.tar.gz abrt-356da89a4e2e6e50ceade12f286d104fe1c17eae.tar.xz abrt-356da89a4e2e6e50ceade12f286d104fe1c17eae.zip | |
Merge branch 'master' of git://git.fedorahosted.org/git/crash-catcher
| -rw-r--r-- | lib/MiddleWare/CrashCatcher.conf | 2 | ||||
| -rw-r--r-- | lib/MiddleWare/Database.h | 41 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 89 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.h | 22 | ||||
| -rw-r--r-- | lib/MiddleWare/test.cpp | 12 | ||||
| -rw-r--r-- | lib/Plugins/SQLite3.cpp | 120 | ||||
| -rw-r--r-- | lib/Plugins/SQLite3.h | 21 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.cpp | 24 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.h | 8 | ||||
| -rw-r--r-- | src/Hooks/CCpp.cpp | 26 |
10 files changed, 177 insertions, 188 deletions
diff --git a/lib/MiddleWare/CrashCatcher.conf b/lib/MiddleWare/CrashCatcher.conf index 9307740..c4c2c17 100644 --- a/lib/MiddleWare/CrashCatcher.conf +++ b/lib/MiddleWare/CrashCatcher.conf @@ -1,4 +1,4 @@ # test conf file. it will be generated in the future -BlackList = /usr/bin/bash, /usr/bin/sh +BlackList = bash, bind, apache2 EnabledPlugins = SQLite3, CCpp Database = SQLite3 diff --git a/lib/MiddleWare/Database.h b/lib/MiddleWare/Database.h index 45d995d..15b20a9 100644 --- a/lib/MiddleWare/Database.h +++ b/lib/MiddleWare/Database.h @@ -30,39 +30,24 @@ /* * Table * ===== - * UUID | DebugDumpPath | Architecture | Kernel | ProgramPath | Package | - * UID | Time | Count | Reported | BackTrace | TextData1 + * UUID | UID| DebugDumpPath | Count | Reported * - * in the future we can add another TextData if we need it + * primary key (UUID, UID) */ #define DATABASE_COLUMN_UUID "UUID" -#define DATABASE_COLUMN_DEBUG_DUMP_PATH "DebugDumpPath" -#define DATABASE_COLUMN_ARCHITECTURE "Architecture" -#define DATABASE_COLUMN_KERNEL "Kernel" -#define DATABASE_COLUMN_EXECUTABLE "Executable" -#define DATABASE_COLUMN_PACKAGE "Package" #define DATABASE_COLUMN_UID "UID" -#define DATABASE_COLUMN_TIME "Time" +#define DATABASE_COLUMN_DEBUG_DUMP_PATH "DebugDumpPath" #define DATABASE_COLUMN_COUNT "Count" #define DATABASE_COLUMN_REPORTED "Reported" -#define DATABASE_COLUMN_BACKTRACE "BackTrace" -#define DATABASE_COLUMN_TEXTDATA1 "TextData1" typedef struct SDatabaseRow { std::string m_sUUID; - std::string m_sDebugDumpPath; - std::string m_sArchitecture; - std::string m_sKernel; - std::string m_sExecutable; - std::string m_sPackage; std::string m_sUID; - std::string m_sTime; + std::string m_sDebugDumpPath; std::string m_sCount; std::string m_sReported; - std::string m_sBackTrace; - std::string m_sTextData1; } database_row_t; // <column_name, <array of values in all selected rows> > @@ -76,24 +61,14 @@ class CDatabase : public CPlugin virtual void Connect() = 0; virtual void DisConnect() = 0; virtual void Insert(const std::string& pUUID, - const std::string& pDebugDumpPath, - const std::string& pArch, - const std::string& pKernel, - const std::string& pExecutable, - const std::string& pPackage, const std::string& pUID, - const std::string& pTime) = 0; - - virtual void InsertBackTrace(const std::string& pUUID, - const std::string& pBackTrace) = 0; - - virtual void InsertTextData1(const std::string& pUUID, - const std::string& pData) = 0; + const std::string& pDebugDumpPath) = 0; - virtual void Delete(const std::string& pUUID) = 0; + virtual void Delete(const std::string& pUUID, const std::string& pUID) = 0; + virtual void SetReported(const std::string& pUUID, const std::string& pUID) = 0; virtual const vector_database_rows_t GetUIDData(const std::string& pUID) = 0; - virtual const database_row_t GetUUIDData(const std::string& pUUID) = 0; + virtual const database_row_t GetUUIDData(const std::string& pUUID, const std::string& pUID) = 0; }; #endif /* DATABASE_H_ */ diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp index 8cd4bec..d52fbda 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/lib/MiddleWare/MiddleWare.cpp @@ -118,12 +118,12 @@ std::string CMiddleWare::GetLocalUUIDApplication(const std::string& pApplication } -void CMiddleWare::GetReport(const std::string& pUUID) +void CMiddleWare::GetReport(const std::string& pUUID, const std::string& pUID) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); database_row_t row; database->Connect(); - row = database->GetUUIDData(pUUID); + row = database->GetUUIDData(pUUID, pUID); database->DisConnect(); if (row.m_sUUID != pUUID) { @@ -137,25 +137,26 @@ int CMiddleWare::Report(const std::string& pReport) // TODO: write this } -void CMiddleWare::SaveDebugDumpToDatabase(const std::string& pDebugDumpPath) +int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& pCrashInfo) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); std::string UUID; - std::string architecture; - std::string kernel; - std::string executable; - std::string package; std::string UID; - std::string time; - std::string textData1; + std::string package; + std::string executable; CDebugDump dd; - dd.Open(pDebugDumpPath); - dd.LoadText(FILENAME_EXECUTABLE, executable); - // TODO: blacklist + dd.LoadText(FILENAME_PACKAGE, package); + + if (package == "" || + m_setBlackList.find(package.substr(0, package.find("-"))) != m_setBlackList.end()) + { + dd.Delete(pDebugDumpPath); + return 0; + } if (dd.Exist(FILENAME_LANGUAGE)) { @@ -176,36 +177,62 @@ void CMiddleWare::SaveDebugDumpToDatabase(const std::string& pDebugDumpPath) throw std::string("CMiddleWare::SaveDebugDumpToDataBase(): Wrong UUID."); } - dd.LoadText(FILENAME_ARCHITECTURE, architecture); - dd.LoadText(FILENAME_KERNEL, kernel); - dd.LoadText(FILENAME_PACKAGE, package); dd.LoadText(FILENAME_UID, UID); - dd.LoadText(FILENAME_TIME, time); + dd.LoadText(FILENAME_EXECUTABLE, executable); + database_row_t row; database->Connect(); - database->Insert(UUID, - pDebugDumpPath, - architecture, - kernel, - executable, - package, - UID, - time); - - if (dd.Exist(FILENAME_TEXTDATA1)) + database->Insert(UUID, UID, pDebugDumpPath); + row = database->GetUUIDData(UUID, UID); + database->DisConnect(); + + if (row.m_sReported == "1") { - dd.LoadText(FILENAME_TEXTDATA1, textData1); - database->InsertTextData1(UUID, textData1); + dd.Delete(pDebugDumpPath); + return 0; } - database->DisConnect(); + if (row.m_sCount != "1") + { + dd.Delete(pDebugDumpPath); + } + + pCrashInfo.m_sUUID = UUID; + pCrashInfo.m_sUID = UID; + pCrashInfo.m_sCount = row.m_sCount; + pCrashInfo.m_sExecutable = executable; + pCrashInfo.m_sPackage = package; + + return 1; } -vector_database_rows_t CMiddleWare::GetDebugDumps(const std::string& pUID) +CMiddleWare::vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); vector_database_rows_t rows; database->Connect(); rows = database->GetUIDData(pUID); database->DisConnect(); - return rows; + + vector_crash_infos_t infos; + std::string data; + int ii; + for (ii = 0; ii < rows.size(); ii++) + { + crash_info_t info; + CDebugDump dd; + info.m_sUUID = rows[ii].m_sUUID; + info.m_sUID = rows[ii].m_sUID; + info.m_sCount = rows[ii].m_sCount; + + dd.Open(rows[ii].m_sDebugDumpPath); + dd.LoadText(FILENAME_EXECUTABLE, data); + info.m_sExecutable = data; + dd.LoadText(FILENAME_PACKAGE, data); + info.m_sPackage = data; + + infos.push_back(info); + } + + return infos; } + diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h index 5fdba84..b9cf8b6 100644 --- a/lib/MiddleWare/MiddleWare.h +++ b/lib/MiddleWare/MiddleWare.h @@ -26,6 +26,8 @@ #include "PluginManager.h" #include <set> +#include <string> + class CMiddleWare { @@ -45,6 +47,18 @@ class CMiddleWare const std::string& pDebugDumpPath); void LoadSettings(const std::string& pPath); public: + + typedef struct SCrashInfo + { + std::string m_sUUID; + std::string m_sUID; + std::string m_sCount; + std::string m_sExecutable; + std::string m_sPackage; + } crash_info_t; + + typedef std::vector<crash_info_t> vector_crash_infos_t; + CMiddleWare(const std::string& pPlugisConfDir, const std::string& pPlugisLibDir, const std::string& pMiddleWareConfFile); @@ -54,10 +68,12 @@ class CMiddleWare void RegisterPlugin(const std::string& pName); void UnRegisterPlugin(const std::string& pName); - void GetReport(const std::string& pUUID); + void GetReport(const std::string& pUUID, const std::string& pUID); int Report(const std::string& pReport); - void SaveDebugDumpToDatabase(const std::string& pDebugDumpPath); - vector_database_rows_t GetDebugDumps(const std::string& pUID); + + int SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& pCrashInfo); + + vector_crash_infos_t GetCrashInfos(const std::string& pUID); }; #endif /*MIDDLEWARE_H_*/ diff --git a/lib/MiddleWare/test.cpp b/lib/MiddleWare/test.cpp index b75bab9..8424aa9 100644 --- a/lib/MiddleWare/test.cpp +++ b/lib/MiddleWare/test.cpp @@ -40,13 +40,17 @@ int main(int argc, char** argv) char pid[100]; sprintf(pid, "%d", getpid()); - dd.Create(std::string(DEBUG_DUMPS_DIR)+"/"+pid); - dd.SaveProc(pid); + dd.Create(std::string(DEBUG_DUMPS_DIR)+"/"+pid, pid); dd.SaveText(FILENAME_LANGUAGE, "CCpp"); dd.SaveBinary(FILENAME_BINARYDATA1, "ass0-9as", sizeof("ass0-9as")); - dd.SaveText(FILENAME_TIME, "1111111111"); - middleWare.SaveDebugDumpToDatabase(std::string(DEBUG_DUMPS_DIR)+"/"+pid); + CMiddleWare::crash_info_t info; + middleWare.SaveDebugDump(std::string(DEBUG_DUMPS_DIR)+"/"+pid, info); + + std::cout << "Application Crashed! " << + info.m_sPackage << ": " << + info.m_sExecutable << "(" << + info.m_sCount << ")" << std::endl; } catch (std::string sError) diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index fb6f78f..b28a866 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -32,10 +32,12 @@ CSQLite3::CSQLite3() : m_pDB(NULL) {} -bool CSQLite3::IsReported(const std::string& pUUID) +bool CSQLite3::Exist(const std::string& pUUID, const std::string& pUID) { vector_database_rows_t table; - GetTable("SELECT "DATABASE_COLUMN_REPORTED" FROM "TABLE_NAME" WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';", table); + GetTable("SELECT "DATABASE_COLUMN_REPORTED" FROM "TABLE_NAME" WHERE " + DATABASE_COLUMN_UUID" = '"+pUUID+"' AND " + DATABASE_COLUMN_UID" = '"+pUID+"';", table); if(table.empty()) { return false; @@ -55,7 +57,6 @@ void CSQLite3::Exec(const std::string& pCommand) void CSQLite3::GetTable(const std::string& pCommand, vector_database_rows_t& pTable) { - char **table; int ncol, nrow; char *err; @@ -76,27 +77,13 @@ void CSQLite3::GetTable(const std::string& pCommand, vector_database_rows_t& pTa { case 0: row.m_sUUID = table[jj + ncol]; break; - case 1: row.m_sDebugDumpPath = table[jj + ncol]; - break; - case 2: row.m_sArchitecture = table[jj + ncol]; - break; - case 3: row.m_sKernel = table[jj + ncol]; - break; - case 4: row.m_sExecutable = table[jj + ncol]; - break; - case 5: row.m_sPackage = table[jj + ncol]; - break; - case 6: row.m_sUID = table[jj + ncol]; - break; - case 7: row.m_sTime = table[jj + ncol]; - break; - case 8: row.m_sCount = table[jj + ncol]; + case 1: row.m_sUID = table[jj + ncol]; break; - case 9: row.m_sReported = table[jj + ncol]; + case 2: row.m_sDebugDumpPath = table[jj + ncol]; break; - case 10: row.m_sBackTrace = table[jj + ncol]; + case 3: row.m_sCount = table[jj + ncol]; break; - case 11: row.m_sTextData1 = table[jj + ncol]; + case 4: row.m_sReported = table[jj + ncol]; break; default: break; @@ -136,20 +123,13 @@ void CSQLite3::Create() throw std::string("SQLite3::Create(): Could not create database.") + sqlite3_errmsg(m_pDB); } - Exec("CREATE TABLE "TABLE_NAME"(" - DATABASE_COLUMN_UUID" VARCHAR NOT NULL PRIMARY KEY," - DATABASE_COLUMN_DEBUG_DUMP_PATH" VARCHAR NOT NULL," - DATABASE_COLUMN_ARCHITECTURE" VARCHAR(16) NOT NULL," - DATABASE_COLUMN_KERNEL" VARCHAR(32) NOT NULL," - DATABASE_COLUMN_EXECUTABLE" VARCHAR NOT NULL," - DATABASE_COLUMN_PACKAGE" VARCHAR(64) NOT NULL," + Exec("CREATE TABLE "TABLE_NAME" (" + DATABASE_COLUMN_UUID" VARCHAR NOT NULL," DATABASE_COLUMN_UID" VARCHAR(64) NOT NULL," - DATABASE_COLUMN_TIME" VARCHAR(32) NOT NULL," + DATABASE_COLUMN_DEBUG_DUMP_PATH" VARCHAR NOT NULL," DATABASE_COLUMN_COUNT" INT(10) NOT NULL DEFAULT 1," DATABASE_COLUMN_REPORTED" INT(10) NOT NULL DEFAULT 0," - DATABASE_COLUMN_BACKTRACE" VARCHAR DEFAULT \"\"," - DATABASE_COLUMN_TEXTDATA1" VARCHAR DEFAULT \"\"" - ");"); + "PRIMARY KEY (UUID, UID));"); } void CSQLite3::DisConnect() @@ -158,71 +138,47 @@ void CSQLite3::DisConnect() } void CSQLite3::Insert(const std::string& pUUID, - const std::string& pDebugDumpPath, - const std::string& pArch, - const std::string& pKernel, - const std::string& pExecutable, - const std::string& pPackage, const std::string& pUID, - const std::string& pTime) + const std::string& pDebugDumpPath) { - if (!IsReported(pUUID)) + if (!Exist(pUUID, pUID)) { Exec("INSERT INTO "TABLE_NAME"(" DATABASE_COLUMN_UUID"," - DATABASE_COLUMN_DEBUG_DUMP_PATH"," - DATABASE_COLUMN_ARCHITECTURE"," - DATABASE_COLUMN_KERNEL"," - DATABASE_COLUMN_EXECUTABLE"," - DATABASE_COLUMN_PACKAGE"," DATABASE_COLUMN_UID"," - DATABASE_COLUMN_TIME")" + DATABASE_COLUMN_DEBUG_DUMP_PATH")" " VALUES ('"+pUUID+"'," - "'"+pDebugDumpPath+"'," - "'"+pArch+"'," - "'"+pKernel+"'," - "'"+pExecutable+"'," - "'"+pPackage+"'," - "'"+pUID+"'," - "'"+pTime+"'" - ");"); + "'"+pUID+"'," + "'"+pDebugDumpPath+"'" + ");"); } else { Exec("UPDATE "TABLE_NAME" " "SET "DATABASE_COLUMN_COUNT" = "DATABASE_COLUMN_COUNT" + 1 " - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); - } -} - -void CSQLite3::Delete(const std::string& pUUID) -{ - if (IsReported(pUUID)) - { - Exec("DELETE FROM "TABLE_NAME - " WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); } } -void CSQLite3::InsertBackTrace(const std::string& pUUID, - const std::string& pBackTrace) +void CSQLite3::Delete(const std::string& pUUID, const std::string& pUID) { - if (IsReported(pUUID)) + if (Exist(pUUID, pUID)) { - Exec("UPDATE "TABLE_NAME - "SET "DATABASE_COLUMN_BACKTRACE" = "+pBackTrace+ - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + Exec("DELETE FROM "TABLE_NAME" " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); } } -void CSQLite3::InsertTextData1(const std::string& pUUID, - const std::string& pData) +void CSQLite3::SetReported(const std::string& pUUID, const std::string& pUID) { - if (IsReported(pUUID)) + if (Exist(pUUID, pUID)) { - Exec("UPDATE "TABLE_NAME - "SET "DATABASE_COLUMN_TEXTDATA1" = "+pData+ - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + Exec("UPDATE "TABLE_NAME" " + "SET "DATABASE_COLUMN_REPORTED" = 1 " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); } } @@ -232,30 +188,24 @@ const vector_database_rows_t CSQLite3::GetUIDData(const std::string& pUID) if (pUID == "0") { GetTable("SELECT * FROM "TABLE_NAME";", table); - Exec("UPDATE "TABLE_NAME" SET "DATABASE_COLUMN_REPORTED" = 1;"); } else { GetTable("SELECT * FROM "TABLE_NAME " WHERE "DATABASE_COLUMN_UID" = '"+pUID+"';", table); - Exec("UPDATE "TABLE_NAME - " SET "DATABASE_COLUMN_REPORTED" = 1 " - " WHERE "DATABASE_COLUMN_UID" = '"+pUID+"';"); } return table; } -const database_row_t CSQLite3::GetUUIDData(const std::string& pUUID) +const database_row_t CSQLite3::GetUUIDData(const std::string& pUUID, const std::string& pUID) { vector_database_rows_t table; - GetTable("SELECT * FROM "TABLE_NAME - " WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';", + GetTable("SELECT * FROM "TABLE_NAME" " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';", table); - Exec("UPDATE "TABLE_NAME - " SET "DATABASE_COLUMN_REPORTED" = 1 " - " WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); if (table.size() == 0) { diff --git a/lib/Plugins/SQLite3.h b/lib/Plugins/SQLite3.h index 35365d2..31fd8ab 100644 --- a/lib/Plugins/SQLite3.h +++ b/lib/Plugins/SQLite3.h @@ -36,7 +36,7 @@ class CSQLite3 : public CDatabase void Create(); void Exec(const std::string& pCommand); void GetTable(const std::string& pCommand, vector_database_rows_t& pTable); - bool IsReported(const std::string& pUUID); + bool Exist(const std::string& pUUID, const std::string& pUID); public: CSQLite3(); @@ -46,24 +46,13 @@ class CSQLite3 : public CDatabase void DisConnect(); void Insert(const std::string& pUUID, - const std::string& pDebugDumpPath, - const std::string& pArch, - const std::string& pKernel, - const std::string& pExecutable, - const std::string& pPackage, const std::string& pUID, - const std::string& pTime); - - void InsertBackTrace(const std::string& pUUID, - const std::string& pBackTrace); - - void InsertTextData1(const std::string& pUUID, - const std::string& pData); - - void Delete(const std::string& pUUID); + const std::string& pDebugDumpPath); + void Delete(const std::string& pUUID, const std::string& pUID); + void SetReported(const std::string& pUUID, const std::string& pUID); const vector_database_rows_t GetUIDData(const std::string& pUID); - const database_row_t GetUUIDData(const std::string& pUUID); + const database_row_t GetUUIDData(const std::string& pUUID, const std::string& pUID); void Init() {} void DeInit() {} diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 9fd887f..e0f88c4 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -32,6 +32,7 @@ #include <fcntl.h> #include <sys/procfs.h> #include <ctype.h> +#include <time.h> CDebugDump::CDebugDump() : m_sDebugDumpDir("") @@ -75,8 +76,16 @@ void CDebugDump::Create(const std::string& pDir) throw "CDebugDump::Create(): Cannot create dir: " + pDir; } SaveEnvironment(); + SaveTime(); } +void CDebugDump::Create(const std::string& pDir, const std::string& pPID) +{ + Create(pDir); + SaveProc(pPID); +} + + void CDebugDump::Delete(const std::string& pDir) { if (!ExistFileDir(pDir)) @@ -122,6 +131,18 @@ void CDebugDump::SaveEnvironment() } } +void CDebugDump::SaveTime() +{ + std::stringstream ss; + time_t t = time(NULL); + if (((time_t) -1) == t) + { + throw std::string("CDebugDump::SaveTime(): Cannot get local time."); + } + ss << t; + SaveText(FILENAME_TIME, ss.str()); +} + void CDebugDump::LoadTextFile(const std::string& pPath, std::string& pData) { std::ifstream fIn; @@ -236,10 +257,11 @@ void CDebugDump::SaveProc(const std::string& pPID) while (!packages.SearchFile(executable)) {} while (!packages.GetStatus()) {} std::string package = packages.GetSearchFileReply(); + SaveText(FILENAME_PACKAGE, package); path = "/proc/"+pPID+"/status"; - std::string uid = "0"; + std::string uid = ""; int ii = 0; LoadTextFile(path, data); diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index c8eef15..11574e9 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -43,7 +43,8 @@ class CDebugDump std::string m_sDebugDumpDir; void SaveEnvironment(); - + void SaveTime(); + void SaveProc(const std::string& pPID); void LoadTextFile(const std::string& pName, std::string& pData); void LoadBinaryFile(const std::string& pName, char** pData, unsigned int* pSize); @@ -57,16 +58,15 @@ class CDebugDump CDebugDump(); void Open(const std::string& pDir); void Create(const std::string& pDir); + void Create(const std::string& pDir, const std::string& pPID); void Delete(const std::string& pDir); - bool Exist(const std::string& pPath); + bool Exist(const std::string& pFileName); void LoadText(const std::string& pName, std::string& pData); void LoadBinary(const std::string& pName, char** pData, unsigned int* pSize); void SaveText(const std::string& pName, const std::string& pData); void SaveBinary(const std::string& pName, const char* pData, const unsigned int pSize); - - void SaveProc(const std::string& pPID); }; #endif /*DEBUGDUMP_H_*/ diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index ef8dc13..6914e31 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -25,36 +25,42 @@ #include <limits.h> #include <stdio.h> #include <unistd.h> +#include <time.h> #define CORESTEP (1024) int main(int argc, char** argv) { const char* program_name = argv[0]; - if (argc < 4) + if (argc < 3) { - fprintf(stderr, "Usage: %s: <pid> <time> <signal>\n", + fprintf(stderr, "Usage: %s: <pid> <signal>\n", program_name); return -1; } const char* pid = argv[1]; - const char* time = argv[2]; - const char* signal = argv[3]; + const char* signal = argv[2]; if (strcmp(signal, "11") != 0) { return 0; } - char path[PATH_MAX]; - CDebugDump dd; - snprintf(path, sizeof(path), "%s/%s%s", DEBUG_DUMPS_DIR, time, pid); try { - dd.Create(path); - dd.SaveText(FILENAME_TIME, time); + char path[PATH_MAX]; + CDebugDump dd; + time_t t = time(NULL); + if (((time_t) -1) == t) + { + fprintf(stderr, "%s: cannot get local time.\n", program_name); + perror(""); + return -4; + } + snprintf(path, sizeof(path), "%s/ccpp-%d-%s", DEBUG_DUMPS_DIR, t, pid); + + dd.Create(path, pid); dd.SaveText(FILENAME_LANGUAGE, "CCpp"); - dd.SaveProc(pid); int size = CORESTEP*sizeof(char); int ii = 0; |
