summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-02-28 14:06:20 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-02-28 14:06:20 +0100
commitb43d23f520f7fa15c96c52eb52a68926031e4067 (patch)
tree1593b54572f1e96599b961b2fe8f6d6c13087092
parentebd0025f033ecf8f21d42e6a2c80ac312ec8116f (diff)
downloadabrt-b43d23f520f7fa15c96c52eb52a68926031e4067.tar.gz
abrt-b43d23f520f7fa15c96c52eb52a68926031e4067.tar.xz
abrt-b43d23f520f7fa15c96c52eb52a68926031e4067.zip
Rewritten CCpp hook and removed dealock in DebugDumps lib (zprikryl)
-rw-r--r--lib/Utils/DebugDump.cpp6
-rw-r--r--src/Hooks/CCpp.cpp54
2 files changed, 32 insertions, 28 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index 89be923e..fcd3b728 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -108,11 +108,13 @@ void CDebugDump::Lock()
pid_t nPID = getpid();
std::stringstream ss;
ss << nPID;
+ std::cerr << "CDebugDump::Lock(): waiting...";
while (!GetAndSetLock(lockPath, ss.str()))
{
- std::cerr << "CDebugDump::Lock(): waiting..." << std::endl;
- usleep(100);
+ std::cerr << ".";
+ usleep(5000);
}
+ std::cerr << "done." << std::endl;
}
void CDebugDump::UnLock()
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index bbc238e3..2d0a1c5d 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <time.h>
#include <syslog.h>
+#include <string>
#define CORESTEP (1024)
@@ -61,48 +62,49 @@ int main(int argc, char** argv)
try
{
- char path[PATH_MAX];
+ FILE* fp;
CDebugDump dd;
- snprintf(path, sizeof(path), "%s/ccpp-%ld-%s", DEBUG_DUMPS_DIR, time(NULL), pid);
+ int byte;
+ char dd_path[PATH_MAX] = DEBUG_DUMPS_DIR;
+ char cd_path[PATH_MAX];
- dd.Create(path);
+ snprintf(dd_path, sizeof(dd_path), "%s/ccpp-%ld-%s",
+ DEBUG_DUMPS_DIR, time(NULL), pid);
+ snprintf(cd_path, sizeof(cd_path), "%s/%s",
+ dd_path, FILENAME_BINARYDATA1);
+
+ dd.Create(dd_path);
dd.SaveProc(pid);
dd.SaveText(FILENAME_LANGUAGE, "CCpp");
-
- int size = CORESTEP*sizeof(char);
- int ii = 0;
- int data = 0;
- char* core = NULL;
- if ((core = (char*)malloc(size)) == NULL)
+ if ((fp = fopen(cd_path, "w")) == NULL)
{
- fprintf(stderr, "%s: not enough memory.\n", program_name);
- perror("");
- return -3;
+ fprintf(stderr, "%s: Can not open the file %s.\n",
+ program_name, cd_path);
+ dd.Delete();
+ dd.Close();
+ return -2;
}
- while ((data = getc(stdin)) != EOF)
+ // TODO: rewrite this
+ while ((byte = getc(stdin)) != EOF)
{
- if (ii >= size)
+ if (putc(byte, fp) == EOF)
{
- size *= CORESTEP*sizeof(char);
- if ((core = (char*)realloc(core, size)) == NULL)
- {
- fprintf(stderr, "%s: not enough memory.\n", program_name);
- perror("");
- return -3;
- }
+ fprintf(stderr, "%s: Can not write to the file %s.\n",
+ program_name, cd_path);
+ fclose(fp);
+ dd.Delete();
+ dd.Close();
+ return -3;
}
- core[ii] = data;
- ii++;
}
- dd.SaveBinary(FILENAME_BINARYDATA1, core, ii);
+ fclose(fp);
dd.Close();
- free(core);
write_log(pid);
}
catch (std::string sError)
{
fprintf(stderr, "%s: %s\n", program_name, sError.c_str());
- return -2;
+ return -4;
}
return 0;
}