diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-02-02 14:17:15 +0100 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-02-02 14:17:15 +0100 |
| commit | 9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28 (patch) | |
| tree | 6ec5b46400b7bf5b69af41dd26484f51b02ef9c4 /src/Hooks | |
| download | abrt-9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28.tar.gz abrt-9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28.tar.xz abrt-9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28.zip | |
Initial git commit
Diffstat (limited to 'src/Hooks')
| -rw-r--r-- | src/Hooks/CCpp.cpp | 94 | ||||
| -rw-r--r-- | src/Hooks/Makefile.am | 5 |
2 files changed, 99 insertions, 0 deletions
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp new file mode 100644 index 0000000..79156d2 --- /dev/null +++ b/src/Hooks/CCpp.cpp @@ -0,0 +1,94 @@ +/* + CCpp.cpp - the hook for C/C++ crashing program + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "DebugDump.h" +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <stdio.h> +#include <unistd.h> + +#define CORESTEP (1024) + +int main(int argc, char** argv) +{ + const char* program_name = argv[0]; + if (argc < 4) + { + fprintf(stderr, "Usage: %s: <pid> <time> <signal>\n", + program_name); + return -1; + } + const char* pid = argv[1]; + const char* time = argv[2]; + const char* signal = argv[3]; + + 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.Open(path, CDebugDump::CREATE); + dd.SaveText(FILENAME_TIME, time); + dd.SaveText(FILENAME_LANGUAGE, "CCpp"); + dd.SaveProc(pid); + + int size = CORESTEP*sizeof(char); + int ii = 0; + int data = 0; + char* core = NULL; + if ((core = (char*)malloc(size)) == NULL) + { + fprintf(stderr, "%s: not enaught memory.\n", program_name); + perror(""); + return -3; + } + while ((data = getc(stdin)) != EOF) + { + if (ii >= size) + { + size *= CORESTEP*sizeof(char); + if ((core = (char*)realloc(core, size)) == NULL) + { + fprintf(stderr, "%s: not enaught memory.\n", program_name); + perror(""); + return -3; + } + } + core[ii] = data; + ii++; + } + dd.SaveBinary(FILENAME_BINARY_FILE1, core, ii); + free(core); + } + catch (std::string sError) + { + fprintf(stderr, "%s: %s\n", program_name, sError.c_str()); + return -2; + } + + return 0; +} diff --git a/src/Hooks/Makefile.am b/src/Hooks/Makefile.am new file mode 100644 index 0000000..92efb6e --- /dev/null +++ b/src/Hooks/Makefile.am @@ -0,0 +1,5 @@ +libexec_PROGRAMS = hookCCpp +hookCCpp_SOURCES = CCpp.cpp +hookCCpp_LDADD = ../../lib/DebugDump/libDebugDump.la +hookCCpp_CPPFLAGS = -I$(srcdir)/../../lib/DebugDump \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\"
\ No newline at end of file |
