diff options
author | Karel Klic <kklic@redhat.com> | 2009-11-09 13:55:20 +0100 |
---|---|---|
committer | Karel Klic <kklic@redhat.com> | 2009-11-09 13:55:20 +0100 |
commit | 19f406b4930c931a932dc6930762e8e12e29ce8b (patch) | |
tree | b08468bf9a010cbce0ecd000a0279222f0d4b4e7 /src/Hooks | |
parent | 801ab58f32f2cb7dca3352b721a07c83705a0287 (diff) | |
parent | 8fa9a6ecd247454ab758efecf818d8067455c778 (diff) | |
download | abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.tar.gz abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.tar.xz abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.zip |
merge
Diffstat (limited to 'src/Hooks')
-rw-r--r-- | src/Hooks/CCpp.cpp | 35 | ||||
-rw-r--r-- | src/Hooks/abrt-pyhook-helper.cpp | 174 | ||||
-rw-r--r-- | src/Hooks/abrt_exception_handler.py.in | 89 | ||||
-rw-r--r-- | src/Hooks/dumpoops.cpp | 54 |
4 files changed, 190 insertions, 162 deletions
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index e6768a60..0f95d05b 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -54,32 +54,41 @@ static char* get_cmdline(pid_t pid) char path[PATH_MAX]; char cmdline[COMMAND_LINE_SIZE]; snprintf(path, sizeof(path), "/proc/%u/cmdline", (int)pid); - int dst = 0; + int idx = 0; int fd = open(path, O_RDONLY); if (fd >= 0) { int len = read(fd, cmdline, sizeof(cmdline) - 1); - if (len >= 0) + close(fd); + + if (len > 0) { - int src = 0; - while (src < len) + /* In Linux, there is always one trailing NUL byte, + * prevent it from being replaced by space below. + */ + if (cmdline[len - 1] == '\0') + len--; + + while (idx < len) { - char ch = cmdline[src++]; + unsigned char ch = cmdline[idx]; if (ch == '\0') { - cmdline[dst++] = ' '; + cmdline[idx++] = ' '; } - /* TODO: maybe just ch >= ' '? */ - else if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) + else if (ch >= ' ' && ch <= 0x7e) { - cmdline[dst++] = ch; + cmdline[idx++] = ch; + } + else + { + cmdline[idx++] = '?'; } } } - close(fd); } - cmdline[dst] = '\0'; + cmdline[idx] = '\0'; return xstrdup(cmdline); } @@ -179,7 +188,7 @@ int main(int argc, char** argv) dd.SaveText(FILENAME_ANALYZER, "CCpp"); dd.SaveText(FILENAME_EXECUTABLE, executable); dd.SaveText(FILENAME_CMDLINE, cmdline); - dd.SaveText(FILENAME_REASON, std::string("Process was terminated by signal ") + signal_str); + dd.SaveText(FILENAME_REASON, ssprintf("Process was terminated by signal %s", signal_str).c_str()); int len = strlen(path); snprintf(path + len, sizeof(path) - len, "/"FILENAME_COREDUMP); @@ -212,7 +221,7 @@ int main(int argc, char** argv) } catch (CABRTException& e) { - error_msg_and_die("%s", e.what().c_str()); + error_msg_and_die("%s", e.what()); } catch (std::exception& e) { diff --git a/src/Hooks/abrt-pyhook-helper.cpp b/src/Hooks/abrt-pyhook-helper.cpp index e15ff684..8a5a1914 100644 --- a/src/Hooks/abrt-pyhook-helper.cpp +++ b/src/Hooks/abrt-pyhook-helper.cpp @@ -18,118 +18,102 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include <argp.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> + +#include <getopt.h> +/* We can easily get rid of abrtlib (libABRTUtils.so) usage in this file, + * but DebugDump will pull it in anyway */ +#include "abrtlib.h" #include "DebugDump.h" #if HAVE_CONFIG_H -#include <config.h> +# include <config.h> #endif - -const char *argp_program_version = "abrt-pyhook-helper " VERSION; -const char *argp_program_bug_address = "<crash-catcher@lists.fedorahosted.org>"; - -static char doc[] = "abrt-pyhook-helper -- stores crash data to abrt shared directory"; -static struct argp_option options[] = { - {"pid" , 'p', "PID" , 0, "PID of process that caused the crash" }, - {"executable", 'e', "PATH" , 0, "absolute path to the program that crashed" }, - {"uuid" , 'u', "UUID" , 0, "hash generated from the backtrace"}, - {"cmdline" , 'c', "TEXT" , 0, "command line of the crashed program"}, - {"loginuid" , 'l', "UID" , 0, "login UID"}, - { 0 } -}; +#define MAX_BT_SIZE (1024*1024) -struct arguments -{ - char *pid; - char *executable; - char *uuid; - char *cmdline; - char *loginuid; -}; +static char *pid; +static char *executable; +static char *uuid; +static char *cmdline; +static char *loginuid; -static error_t -parse_opt (int key, char *arg, struct argp_state *state) +int main(int argc, char** argv) { - /* Get the input argument from argp_parse, which we - know is a pointer to our arguments structure. */ - struct arguments *arguments = (struct arguments*)state->input; - - switch (key) + // Parse options + static const struct option longopts[] = { + // name , has_arg , flag, val + { "pid" , required_argument, NULL, 'p' }, + { "executable", required_argument, NULL, 'e' }, + { "uuid" , required_argument, NULL, 'u' }, + { "cmdline" , required_argument, NULL, 'c' }, + { "loginuid" , required_argument, NULL, 'l' }, + { 0 }, + }; + int opt; + while ((opt = getopt_long(argc, argv, "p:e:u:c:l:", longopts, NULL)) != -1) { - case 'p': arguments->pid = arg; break; - case 'e': arguments->executable = arg; break; - case 'u': arguments->uuid = arg; break; - case 'c': arguments->cmdline = arg; break; - case 'l': arguments->loginuid = arg; break; - - case ARGP_KEY_ARG: - argp_usage(state); - exit(1); - break; - - case ARGP_KEY_END: - if (!arguments->pid) + switch (opt) { - argp_usage(state); - exit(1); + case 'p': + pid = optarg; + break; + case 'e': + executable = optarg; + break; + case 'u': + uuid = optarg; + break; + case 'c': + cmdline = optarg; + break; + case 'l': + loginuid = optarg; + break; + default: + usage: + error_msg_and_die( + "Usage: abrt-pyhook-helper [OPTIONS] <BACKTRACE\n" + "\nOptions:\n" + " -p,--pid PID PID of process that caused the crash\n" + " -p,--executable PATH absolute path to the program that crashed\n" + " -u,--uuid UUID hash generated from the backtrace\n" + " -c,--cmdline TEXT command line of the crashed program\n" + " -l,--loginuid UID login UID\n" + ); } - break; - - default: - return ARGP_ERR_UNKNOWN; } - return 0; -} - -/* Our argp parser. */ -static struct argp argp = { options, parse_opt, 0, doc }; - -int main(int argc, char** argv) -{ - struct arguments arguments; - argp_parse (&argp, argc, argv, 0, 0, &arguments); + if (!pid) + goto usage; +// is it really ok if other params aren't specified? abrtd might get confused... + + // Read the backtrace from stdin + char *bt = (char*)xmalloc(MAX_BT_SIZE); + ssize_t len = full_read(STDIN_FILENO, bt, MAX_BT_SIZE-1); + if (len < 0) + { + perror_msg_and_die("Read error"); + } + bt[len] = '\0'; + if (len == MAX_BT_SIZE-1) + { + error_msg("Backtrace size limit exceeded, trimming to 1 MB"); + } + // Create directory with the debug dump char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/pyhook-%ld-%s", DEBUG_DUMPS_DIR, - (long)time(NULL), arguments.pid); + snprintf(path, sizeof(path), DEBUG_DUMPS_DIR"/pyhook-%ld-%s", + (long)time(NULL), pid); CDebugDump dd; dd.Create(path, geteuid()); dd.SaveText(FILENAME_ANALYZER, "Python"); - if (arguments.executable) - dd.SaveText(FILENAME_EXECUTABLE, arguments.executable); - if (arguments.cmdline) - dd.SaveText("cmdline", arguments.cmdline); - if (arguments.uuid) - dd.SaveText("uuid", arguments.uuid); - if (arguments.loginuid) - dd.SaveText("uid", arguments.loginuid); - - // Read the backtrace from stdin. - int c; - int capacity = 1024; - char *bt = (char*)malloc(capacity); - char *btptr = bt; - while ((c = getchar()) != EOF) - { - if (c >= 0 && c <= 255) - *btptr++ = (char)c; - if (btptr - bt >= capacity - 1) - { - capacity *= 2; - bt = (char*)realloc(bt, capacity); - if (!bt) - { - printf("Error while allocating memory for backtrace."); - return 1; - } - } - } - *btptr = '\0'; - + if (executable) + dd.SaveText(FILENAME_EXECUTABLE, executable); + if (cmdline) + dd.SaveText("cmdline", cmdline); + if (uuid) + dd.SaveText("uuid", uuid); + if (loginuid) + dd.SaveText("uid", loginuid); dd.SaveText("backtrace", bt); free(bt); dd.Close(); diff --git a/src/Hooks/abrt_exception_handler.py.in b/src/Hooks/abrt_exception_handler.py.in index 362aaf24..010bf12d 100644 --- a/src/Hooks/abrt_exception_handler.py.in +++ b/src/Hooks/abrt_exception_handler.py.in @@ -181,51 +181,54 @@ def handleMyException((etype, value, tb)): # ignore uncaught ctrl-c if etype == KeyboardInterrupt: return sys.__excepthook__(etype, value, tb) - - import os.path - from hashlib import md5 - import traceback - - syslog.syslog("abrt: Pyhook: Detected unhandled exception in %s " % sys.argv[0]) - elist = traceback.format_exception (etype, value, tb) - tblast = traceback.extract_tb(tb, limit=None) - if len(tblast): - tblast = tblast[len(tblast)-1] - extxt = traceback.format_exception_only(etype, value) - text = "" - text = text + "Summary: TB" - if tblast and len(tblast) > 3: - ll = [] - ll.extend(tblast[:3]) - ll[0] = os.path.basename(tblast[0]) - tblast = ll - - m = md5() - ntext = "" - for t in tblast: - ntext += str(t) + ":" - m.update(str(t)) - - tb_uuid = str(m.hexdigest())[:8] - text += tb_uuid + " " + ntext - - text += extxt[0] - text += "\n" - text += "".join(elist) - - trace = tb - while trace.tb_next: - trace = trace.tb_next - frame = trace.tb_frame - text += ("\nLocal variables in innermost frame:\n") + try: - for (key, val) in frame.f_locals.items(): - text += "%s: %s\n" % (key, val) - except: + import os.path + from hashlib import md5 + import traceback + + syslog.syslog("abrt: Pyhook: Detected unhandled exception in %s " % sys.argv[0]) + elist = traceback.format_exception (etype, value, tb) + tblast = traceback.extract_tb(tb, limit=None) + if len(tblast): + tblast = tblast[len(tblast)-1] + extxt = traceback.format_exception_only(etype, value) + text = "" + text = text + "Summary: TB" + if tblast and len(tblast) > 3: + ll = [] + ll.extend(tblast[:3]) + ll[0] = os.path.basename(tblast[0]) + tblast = ll + + m = md5() + ntext = "" + for t in tblast: + ntext += str(t) + ":" + m.update(str(t)) + + tb_uuid = str(m.hexdigest())[:8] + text += tb_uuid + " " + ntext + + text += extxt[0] + text += "\n" + text += "".join(elist) + + trace = tb + while trace.tb_next: + trace = trace.tb_next + frame = trace.tb_frame + text += ("\nLocal variables in innermost frame:\n") + try: + for (key, val) in frame.f_locals.items(): + text += "%s: %s\n" % (key, val) + except: + pass + + # add coredump saving + write_dump(os.getpid(), tb_uuid, text) + except: #silently ignore any error in this hook, to not interfere with the python scripts pass - - # add coredump saving - write_dump(os.getpid(), tb_uuid, text) return sys.__excepthook__(etype, value, tb) def installExceptionHandler(debug = 1): diff --git a/src/Hooks/dumpoops.cpp b/src/Hooks/dumpoops.cpp index eeeca7ea..b031d39c 100644 --- a/src/Hooks/dumpoops.cpp +++ b/src/Hooks/dumpoops.cpp @@ -25,6 +25,7 @@ */ #include "abrtlib.h" +#include "abrt_types.h" #include "KerneloopsScanner.h" #include <dlfcn.h> @@ -38,13 +39,36 @@ do { \ int main(int argc, char **argv) { - if (!argv[1]) - { - log("usage: %s FILE", argv[0]); - return 1; + char *program_name = strrchr(argv[0], '/'); + program_name = program_name ? program_name + 1 : argv[0]; + + /* Parse options */ + bool opt_d = 0, opt_s = 0; + int opt; + while ((opt = getopt(argc, argv, "ds")) != -1) { + switch (opt) { + case 'd': + opt_d = 1; + break; + case 's': + opt_s = 1; + break; + default: + usage: + error_msg_and_die( + "Usage: %s [-ds] FILE\n\n" + "Options:\n" + "\t-d\tCreate ABRT dump for every oops found\n" + "\t-s\tPrint found oopses on standard output\n" + , program_name + ); + } } - char *slash = strrchr(argv[0], '/'); - msg_prefix = xasprintf("%s: ", slash ? slash+1 : argv[0]); + argv += optind; + if (!argv[0]) + goto usage; + + msg_prefix = xasprintf("%s: ", program_name); /* Load KerneloopsScanner plugin */ // const plugin_info_t *plugin_info; @@ -67,13 +91,21 @@ int main(int argc, char **argv) // scanner->LoadSettings(path); /* Use it: parse and dump the oops */ - int cnt = scan_syslog_file(scanner, argv[1]); + int cnt = scan_syslog_file(scanner, argv[0]); log("found oopses: %d", cnt); - if (cnt > 0) - { - log("dumping oopses"); - save_oops_to_debug_dump(scanner); + if (cnt > 0) { + if (opt_s) { + int i = 0; + while (i < scanner->m_pOopsList.size()) { + printf("\nVersion: %s", scanner->m_pOopsList[i].c_str()); + i++; + } + } + if (opt_d) { + log("dumping oopses"); + save_oops_to_debug_dump(scanner); + } } /*dlclose(handle); - why bother? */ |