int main(int argc, char **argv) { /* I18n */ setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif abrt_init(argv); /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( "& [options] -d DIR\n" "\n" "Analyzes C/C++ backtrace, generates duplication hash, backtrace rating,\n" "and identifies crash function in problem directory DIR" ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1 }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Problem directory")), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); export_abrt_envvars(0); struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; char *component = dd_load_text(dd, FILENAME_COMPONENT); /* Read backtrace */ char *backtrace_str = dd_load_text_ext(dd, FILENAME_BACKTRACE, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE); if (!backtrace_str) { dd_close(dd); return 1; } /* Compute backtrace hash */ struct sr_location location; sr_location_init(&location); const char *backtrace_str_ptr = backtrace_str; struct sr_gdb_stacktrace *backtrace = sr_gdb_stacktrace_parse(&backtrace_str_ptr, &location); free(backtrace_str); /* Store backtrace hash */ if (!backtrace) { /* * The parser failed. Compute the duphash from the executable * instead of a backtrace. * and component only. This is not supposed to happen often. */ log(_("Backtrace parsing failed for %s"), dump_dir_name); log("%d:%d: %s", location.line, location.column, location.message); struct strbuf *emptybt = strbuf_new(); char *executable = dd_load_text(dd, FILENAME_EXECUTABLE); strbuf_prepend_str(emptybt, executable); free(executable); strbuf_prepend_str(emptybt, component); log_debug("Generating duphash: %s", emptybt->buf); char hash_str[SHA1_RESULT_LEN*2 + 1]; str_to_sha1str(hash_str, emptybt->buf); dd_save_text(dd, FILENAME_DUPHASH, hash_str); /* * Other parts of ABRT assume that if no rating is available, * it is ok to allow reporting of the bug. To be sure no bad * backtrace is reported, rate the backtrace with the lowest * rating. */ dd_save_text(dd, FILENAME_RATING, "0"); strbuf_free(emptybt); free(component); dd_close(dd); /* Report success even if the parser failed, as the backtrace * has been created and rated. The failure is caused by a flaw * in the parser, not in the backtrace. */ return 0; } /* Compute duplication hash. */ struct sr_thread *crash_thread = (struct sr_thread *)sr_gdb_stacktrace_find_crash_thread(backtrace); if (crash_thread) { char *hash_str; if (g_verbose >= 3) { hash_str = sr_thread_get_duphash(crash_thread, 3, component, SR_DUPHASH_NOHASH); log("Generating duphash: %s", hash_str); free(hash_str); } hash_str = sr_thread_get_duphash(crash_thread, 3, component, SR_DUPHASH_NORMAL); dd_save_text(dd, FILENAME_DUPHASH, hash_str); free(hash_str); } else log(_("Crash thread not found")); /* Compute the backtrace rating. */ float quality = sr_gdb_stacktrace_quality_complex(backtrace); const char *rating; if (quality < 0.6f) rating = "0"; else if (quality < 0.7f) rating = "1"; else if (quality < 0.8f) rating = "2"; else if (quality < 0.9f) rating = "3"; else rating = "4"; dd_save_text(dd, FILENAME_RATING, rating); /* Get the function name from the crash frame. */ struct sr_gdb_frame *crash_frame = sr_gdb_stacktrace_get_crash_frame(backtrace); if (crash_frame) { if (crash_frame->function_name && 0 != strcmp(crash_frame->function_name, "??")) { dd_save_text(dd, FILENAME_CRASH_FUNCTION, crash_frame->function_name); } sr_gdb_frame_free(crash_frame); } sr_gdb_stacktrace_free(backtrace); dd_close(dd); free(component); return 0; }
static int run_post_create(const char *dirname) { /* If doesn't start with "g_settings_dump_location/"... */ if (!dir_is_in_dump_location(dirname)) { /* Then refuse to operate on it (someone is attacking us??) */ error_msg("Bad problem directory name '%s', should start with: '%s'", dirname, g_settings_dump_location); return 400; /* Bad Request */ } if (!dir_has_correct_permissions(dirname, DD_PERM_EVENTS)) { error_msg("Problem directory '%s' has wrong owner or group", dirname); return 400; /* */ } /* Check completness */ { struct dump_dir *dd = dd_opendir(dirname, DD_OPEN_READONLY); char *provoker = NULL; const bool event_dir = dd && problem_dump_dir_was_provoked_by_abrt_event(dd, &provoker); if (event_dir) { if (g_settings_debug_level == 0) { error_msg("Removing problem provoked by ABRT(pid:%s): '%s'", provoker, dirname); dd_delete(dd); } else { char *dumpdir = NULL; char *event = NULL; char *reason = NULL; char *cmdline = NULL; /* Ignore errors */ dd_get_env_variable(dd, "DUMP_DIR", &dumpdir); dd_get_env_variable(dd, "EVENT", &event); reason = dd_load_text(dd, FILENAME_REASON); cmdline = dd_load_text(dd, FILENAME_CMDLINE); error_msg("ABRT_SERVER_PID=%s;DUMP_DIR='%s';EVENT='%s';REASON='%s';CMDLINE='%s'", provoker, dumpdir, event, reason, cmdline); } free(provoker); return 400; } const bool complete = dd && problem_dump_dir_is_complete(dd); dd_close(dd); if (complete) { error_msg("Problem directory '%s' has already been processed", dirname); return 403; } } int child_stdout_fd; int child_pid = spawn_event_handler_child(dirname, "post-create", &child_stdout_fd); char *dup_of_dir = NULL; struct strbuf *cmd_output = strbuf_new(); bool child_is_post_create = 1; /* else it is a notify child */ read_child_output: //log("Reading from event fd %d", child_stdout_fd); /* Read streamed data and split lines */ for (;;) { char buf[250]; /* usually we get one line, no need to have big buf */ errno = 0; int r = safe_read(child_stdout_fd, buf, sizeof(buf) - 1); if (r <= 0) break; buf[r] = '\0'; /* split lines in the current buffer */ char *raw = buf; char *newline; while ((newline = strchr(raw, '\n')) != NULL) { *newline = '\0'; strbuf_append_str(cmd_output, raw); char *msg = cmd_output->buf; if (child_is_post_create && prefixcmp(msg, "DUP_OF_DIR: ") == 0 ) { free(dup_of_dir); dup_of_dir = xstrdup(msg + strlen("DUP_OF_DIR: ")); } else log("%s", msg); strbuf_clear(cmd_output); /* jump to next line */ raw = newline + 1; } /* beginning of next line. the line continues by next read */ strbuf_append_str(cmd_output, raw); } /* EOF/error */ /* Wait for child to actually exit, collect status */ int status = 0; if (safe_waitpid(child_pid, &status, 0) <= 0) /* should not happen */ perror_msg("waitpid(%d)", child_pid); /* If it was a "notify[-dup]" event, then we're done */ if (!child_is_post_create) goto ret; /* exit 0 means "this is a good, non-dup dir" */ /* exit with 1 + "DUP_OF_DIR: dir" string => dup */ if (status != 0) { if (WIFSIGNALED(status)) { log("'post-create' on '%s' killed by signal %d", dirname, WTERMSIG(status)); goto delete_bad_dir; } /* else: it is WIFEXITED(status) */ if (!dup_of_dir) { log("'post-create' on '%s' exited with %d", dirname, WEXITSTATUS(status)); goto delete_bad_dir; } } const char *work_dir = (dup_of_dir ? dup_of_dir : dirname); /* Load problem_data (from the *first dir* if this one is a dup) */ struct dump_dir *dd = dd_opendir(work_dir, /*flags:*/ 0); if (!dd) /* dd_opendir already emitted error msg */ goto delete_bad_dir; /* Update count */ char *count_str = dd_load_text_ext(dd, FILENAME_COUNT, DD_FAIL_QUIETLY_ENOENT); unsigned long count = strtoul(count_str, NULL, 10); /* Don't increase crash count if we are working with newly uploaded * directory (remote crash) which already has its crash count set. */ if ((status != 0 && dup_of_dir) || count == 0) { count++; char new_count_str[sizeof(long)*3 + 2]; sprintf(new_count_str, "%lu", count); dd_save_text(dd, FILENAME_COUNT, new_count_str); /* This condition can be simplified to either * (status * != 0 && * dup_of_dir) or (count == 1). But the * chosen form is much more reliable and safe. We must not call * dd_opendir() to locked dd otherwise we go into a deadlock. */ if (strcmp(dd->dd_dirname, dirname) != 0) { /* Update the last occurrence file by the time file of the new problem */ struct dump_dir *new_dd = dd_opendir(dirname, DD_OPEN_READONLY); char *last_ocr = NULL; if (new_dd) { /* TIME must exists in a valid dump directory but we don't want to die * due to broken duplicated dump directory */ last_ocr = dd_load_text_ext(new_dd, FILENAME_TIME, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE | DD_FAIL_QUIETLY_ENOENT); dd_close(new_dd); } else { /* dd_opendir() already produced a message with good information about failure */ error_msg("Can't read the last occurrence file from the new dump directory."); } if (!last_ocr) { /* the new dump directory may lie in the dump location for some time */ log("Using current time for the last occurrence file which may be incorrect."); time_t t = time(NULL); last_ocr = xasprintf("%lu", (long)t); } dd_save_text(dd, FILENAME_LAST_OCCURRENCE, last_ocr); free(last_ocr); } } /* Reset mode/uig/gid to correct values for all files created by event run */ dd_sanitize_mode_and_owner(dd); dd_close(dd); if (!dup_of_dir) log_notice("New problem directory %s, processing", work_dir); else { log_warning("Deleting problem directory %s (dup of %s)", strrchr(dirname, '/') + 1, strrchr(dup_of_dir, '/') + 1); delete_dump_dir(dirname); } /* Run "notify[-dup]" event */ int fd; child_pid = spawn_event_handler_child( work_dir, (dup_of_dir ? "notify-dup" : "notify"), &fd ); //log("Started notify, fd %d -> %d", fd, child_stdout_fd); xmove_fd(fd, child_stdout_fd); child_is_post_create = 0; strbuf_clear(cmd_output); free(dup_of_dir); dup_of_dir = NULL; goto read_child_output; delete_bad_dir: log_warning("Deleting problem directory '%s'", dirname); delete_dump_dir(dirname); ret: strbuf_free(cmd_output); free(dup_of_dir); close(child_stdout_fd); return 0; }
int main(int argc, char **argv) { abrt_init(argv); const char *dump_dir_name = "."; /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( "\b [-v] -d DIR\n" "\n" "Calculates and saves UUID and DUPHASH of python crash dumps" ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Dump directory")), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); export_abrt_envvars(0); struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; char *bt = dd_load_text(dd, FILENAME_BACKTRACE); /* Hash 1st line of backtrace and save it as UUID and DUPHASH */ /* "example.py:1:<module>:ZeroDivisionError: integer division or modulo by zero" */ unsigned char hash_bytes[SHA1_RESULT_LEN]; sha1_ctx_t sha1ctx; sha1_begin(&sha1ctx); const char *bt_end = strchrnul(bt, '\n'); sha1_hash(&sha1ctx, bt, bt_end - bt); sha1_end(&sha1ctx, hash_bytes); free(bt); char hash_str[SHA1_RESULT_LEN*2 + 1]; unsigned len = SHA1_RESULT_LEN; unsigned char *s = hash_bytes; char *d = hash_str; while (len) { *d++ = "0123456789abcdef"[*s >> 4]; *d++ = "0123456789abcdef"[*s & 0xf]; s++; len--; } *d = '\0'; dd_save_text(dd, FILENAME_UUID, hash_str); dd_save_text(dd, FILENAME_DUPHASH, hash_str); dd_close(dd); return 0; }
int main(int argc, char **argv) { /* I18n */ setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif abrt_init(argv); const char *dump_dir_name = "."; /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( "& [-v] -d DIR\n" "\n" "Calculates and saves UUID of coredump in problem directory DIR" ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Problem directory")), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); export_abrt_envvars(0); char *unstrip_n_output = NULL; char *coredump_path = xasprintf("%s/"FILENAME_COREDUMP, dump_dir_name); if (access(coredump_path, R_OK) == 0) unstrip_n_output = run_unstrip_n(dump_dir_name, /*timeout_sec:*/ 30); free(coredump_path); if (unstrip_n_output) { /* Run unstrip -n and trim its output, leaving only sizes and build ids */ /* modifies unstrip_n_output in-place: */ trim_unstrip_output(unstrip_n_output, unstrip_n_output); } else { /* bad dump_dir_name, can't run unstrip, etc... * or maybe missing coredump - try generating it from core_backtrace */ unstrip_n_output = build_ids_from_core_backtrace(dump_dir_name); } /* Hash package + executable + unstrip_n_output and save it as UUID */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; char *executable = dd_load_text(dd, FILENAME_EXECUTABLE); /* FILENAME_PACKAGE may be missing if ProcessUnpackaged = yes... */ char *package = dd_load_text_ext(dd, FILENAME_PACKAGE, DD_FAIL_QUIETLY_ENOENT); /* Package variable has "firefox-3.5.6-1.fc11[.1]" format */ /* Remove distro suffix and maybe least significant version number */ char *p = package; while (*p) { if (*p == '.' && (p[1] < '0' || p[1] > '9')) { /* We found "XXXX.nondigitXXXX", trim this part */ *p = '\0'; break; } p++; } char *first_dot = strchr(package, '.'); if (first_dot) { char *last_dot = strrchr(first_dot, '.'); if (last_dot != first_dot) { /* There are more than one dot: "1.2.3" * Strip last part, we don't want to distinquish crashes * in packages which differ only by minor release number. */ *last_dot = '\0'; } } char *string_to_hash = xasprintf("%s%s%s", package, executable, unstrip_n_output); /*free(package);*/ /*free(executable);*/ /*free(unstrip_n_output);*/ log_debug("String to hash: %s", string_to_hash); char hash_str[SHA1_RESULT_LEN*2 + 1]; str_to_sha1str(hash_str, string_to_hash); dd_save_text(dd, FILENAME_UUID, hash_str); dd_close(dd); return 0; }
/* This function is run after each post-create event is finished (there may be * multiple such events). * * It first checks if there is CORE_BACKTRACE or UUID item in the dump dir * we are processing. * * If there is a CORE_BACKTRACE, it iterates over all other dump * directories and computes similarity to their core backtraces (if any). * If one of them is similar enough to be considered duplicate, the function * saves the path to the dump directory in question and returns 1 to indicate * that we have indeed found a duplicate of currently processed dump directory. * No more events are processed and program prints the path to the other * directory and returns failure. * * If there is an UUID item (and no core backtrace), the function again * iterates over all other dump directories and compares this UUID to their * UUID. If there is a match, the path to the duplicate is saved and 1 is returned. * * If duplicate is not found as described above, the function returns 0 and we * either process remaining events if there are any, or successfully terminate * processing of the current dump directory. */ static int is_crash_a_dup(const char *dump_dir_name, void *param) { int retval = 0; /* defaults to no dup found, "run_event, please continue iterating" */ struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); if (!dd) return 0; /* wtf? (error, but will be handled elsewhere later) */ free(type); type = dd_load_text(dd, FILENAME_TYPE); free(executable); executable = dd_load_text_ext(dd, FILENAME_EXECUTABLE, DD_FAIL_QUIETLY_ENOENT); char *container_id = dd_load_text_ext(dd, FILENAME_CONTAINER_ID, DD_FAIL_QUIETLY_ENOENT); dup_uuid_init(dd); dup_corebt_init(dd); dd_close(dd); /* dump_dir_name can be relative */ dump_dir_name = realpath(dump_dir_name, NULL); DIR *dir = opendir(g_settings_dump_location); if (dir == NULL) goto end; /* Scan crash dumps looking for a dup */ //TODO: explain why this is safe wrt concurrent runs struct dirent *dent; while ((dent = readdir(dir)) != NULL && crash_dump_dup_name == NULL) { if (dot_or_dotdot(dent->d_name)) continue; /* skip "." and ".." */ const char *ext = strrchr(dent->d_name, '.'); if (ext && strcmp(ext, ".new") == 0) continue; /* skip anything named "<dirname>.new" */ dd = NULL; char *tmp_concat_path = concat_path_file(g_settings_dump_location, dent->d_name); char *dump_dir_name2 = realpath(tmp_concat_path, NULL); if (g_verbose > 1 && !dump_dir_name2) perror_msg("realpath(%s)", tmp_concat_path); free(tmp_concat_path); if (!dump_dir_name2) continue; char *dd_uid = NULL, *dd_type = NULL; char *dd_executable = NULL, *dd_container_id = NULL; if (strcmp(dump_dir_name, dump_dir_name2) == 0) goto next; /* we are never a dup of ourself */ int sv_logmode = logmode; /* Silently ignore any error in the silent log level. */ logmode = g_verbose == 0 ? 0 : sv_logmode; dd = dd_opendir(dump_dir_name2, /*flags:*/ DD_FAIL_QUIETLY_ENOENT | DD_OPEN_READONLY); logmode = sv_logmode; if (!dd) goto next; /* problems from different containers are not duplicates */ if (container_id != NULL) { dd_container_id = dd_load_text_ext(dd, FILENAME_CONTAINER_ID, DD_FAIL_QUIETLY_ENOENT); if (dd_container_id != NULL && strcmp(container_id, dd_container_id) != 0) { goto next; } } /* crashes of different users are not considered duplicates */ dd_uid = dd_load_text_ext(dd, FILENAME_UID, DD_FAIL_QUIETLY_ENOENT); if (strcmp(uid, dd_uid)) { goto next; } /* different crash types are not duplicates */ dd_type = dd_load_text_ext(dd, FILENAME_TYPE, DD_FAIL_QUIETLY_ENOENT); if (strcmp(type, dd_type)) { goto next; } /* different executables are not duplicates */ dd_executable = dd_load_text_ext(dd, FILENAME_EXECUTABLE, DD_FAIL_QUIETLY_ENOENT); if ( (executable != NULL && dd_executable == NULL) || (executable == NULL && dd_executable != NULL) || ((executable != NULL && dd_executable != NULL) && strcmp(executable, dd_executable) != 0)) { goto next; } if (dup_uuid_compare(dd) || dup_corebt_compare(dd) ) { crash_dump_dup_name = dump_dir_name2; dump_dir_name2 = NULL; retval = 1; /* "run_event, please stop iterating" */ /* sonce crash_dump_dup_name != NULL now, we exit the loop */ } next: free(dump_dir_name2); dd_close(dd); free(dd_uid); free(dd_type); free(dd_container_id); } closedir(dir); end: free((char*)dump_dir_name); free(container_id); return retval; }
char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char *debuginfo_dirs) { INITIALIZE_LIBABRT(); struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return NULL; char *executable = dd_load_text(dd, FILENAME_EXECUTABLE); dd_close(dd); /* Let user know what's going on */ log(_("Generating backtrace")); unsigned i = 0; char *args[25]; args[i++] = (char*)"gdb"; args[i++] = (char*)"-batch"; struct strbuf *set_debug_file_directory = strbuf_new(); unsigned auto_load_base_index = 0; if(debuginfo_dirs == NULL) { // set non-existent debug file directory to prevent resolving // function names - we need offsets for core backtrace. strbuf_append_str(set_debug_file_directory, "set debug-file-directory /"); } else { strbuf_append_str(set_debug_file_directory, "set debug-file-directory /usr/lib/debug"); struct strbuf *debug_directories = strbuf_new(); const char *p = debuginfo_dirs; while (1) { while (*p == ':') p++; if (*p == '\0') break; const char *colon_or_nul = strchrnul(p, ':'); strbuf_append_strf(debug_directories, "%s%.*s/usr/lib/debug", (debug_directories->len == 0 ? "" : ":"), (int)(colon_or_nul - p), p); p = colon_or_nul; } strbuf_append_strf(set_debug_file_directory, ":%s", debug_directories->buf); args[i++] = (char*)"-iex"; auto_load_base_index = i; args[i++] = xasprintf("add-auto-load-safe-path %s", debug_directories->buf); args[i++] = (char*)"-iex"; args[i++] = xasprintf("add-auto-load-scripts-directory %s", debug_directories->buf); strbuf_free(debug_directories); } args[i++] = (char*)"-ex"; const unsigned debug_dir_cmd_index = i++; args[debug_dir_cmd_index] = strbuf_free_nobuf(set_debug_file_directory); /* "file BINARY_FILE" is needed, without it gdb cannot properly * unwind the stack. Currently the unwind information is located * in .eh_frame which is stored only in binary, not in coredump * or debuginfo. * * Fedora GDB does not strictly need it, it will find the binary * by its build-id. But for binaries either without build-id * (= built on non-Fedora GCC) or which do not have * their debuginfo rpm installed gdb would not find BINARY_FILE * so it is still makes sense to supply "file BINARY_FILE". * * Unfortunately, "file BINARY_FILE" doesn't work well if BINARY_FILE * was deleted (as often happens during system updates): * gdb uses specified BINARY_FILE * even if it is completely unrelated to the coredump. * See https://bugzilla.redhat.com/show_bug.cgi?id=525721 * * TODO: check mtimes on COREFILE and BINARY_FILE and not supply * BINARY_FILE if it is newer (to at least avoid gdb complaining). */ args[i++] = (char*)"-ex"; const unsigned file_cmd_index = i++; args[file_cmd_index] = xasprintf("file %s", executable); free(executable); args[i++] = (char*)"-ex"; const unsigned core_cmd_index = i++; args[core_cmd_index] = xasprintf("core-file %s/"FILENAME_COREDUMP, dump_dir_name); args[i++] = (char*)"-ex"; const unsigned bt_cmd_index = i++; /*args[9] = ... see below */ args[i++] = (char*)"-ex"; args[i++] = (char*)"info sharedlib"; /* glibc's abort() stores its message in __abort_msg variable */ args[i++] = (char*)"-ex"; args[i++] = (char*)"print (char*)__abort_msg"; args[i++] = (char*)"-ex"; args[i++] = (char*)"print (char*)__glib_assert_msg"; args[i++] = (char*)"-ex"; args[i++] = (char*)"info all-registers"; args[i++] = (char*)"-ex"; const unsigned dis_cmd_index = i++; args[dis_cmd_index] = (char*)"disassemble"; args[i++] = NULL; /* Get the backtrace, but try to cap its size */ /* Limit bt depth. With no limit, gdb sometimes OOMs the machine */ unsigned bt_depth = 1024; const char *thread_apply_all = "thread apply all -ascending"; const char *full = " full"; char *bt = NULL; while (1) { args[bt_cmd_index] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full); bt = exec_vp(args, /*redirect_stderr:*/ 1, timeout_sec, NULL); free(args[bt_cmd_index]); if ((bt && strnlen(bt, 256*1024) < 256*1024) || bt_depth <= 32) { break; } bt_depth /= 2; if (bt) log("Backtrace is too big (%u bytes), reducing depth to %u", (unsigned)strlen(bt), bt_depth); else /* (NB: in fact, current impl. of exec_vp() never returns NULL) */ log("Failed to generate backtrace, reducing depth to %u", bt_depth); free(bt); /* Replace -ex disassemble (which disasms entire function $pc points to) * to a version which analyzes limited, small patch of code around $pc. * (Users reported a case where bare "disassemble" attempted to process * entire .bss). * TODO: what if "$pc-N" underflows? in my test, this happens: * Dump of assembler code from 0xfffffffffffffff0 to 0x30: * End of assembler dump. * (IOW: "empty" dump) */ args[dis_cmd_index] = (char*)"disassemble $pc-20, $pc+64"; if (bt_depth <= 64 && thread_apply_all[0] != '\0') { /* This program likely has gazillion threads, dont try to bt them all */ bt_depth = 128; thread_apply_all = ""; } if (bt_depth <= 64 && full[0] != '\0') { /* Looks like there are gigantic local structures or arrays, disable "full" bt */ bt_depth = 128; full = ""; } } if (auto_load_base_index > 0) { free(args[auto_load_base_index]); free(args[auto_load_base_index + 2]); } free(args[debug_dir_cmd_index]); free(args[file_cmd_index]); free(args[core_cmd_index]); return bt; }
void problem_data_load_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd, char **excluding) { char *short_name; char *full_name; dd_init_next_file(dd); while (dd_get_next_file(dd, &short_name, &full_name)) { if (excluding && is_in_string_list(short_name, excluding)) { //log("Excluded:'%s'", short_name); goto next; } if (short_name[0] == '#' || (short_name[0] && short_name[strlen(short_name) - 1] == '~') ) { //log("Excluded (editor backup file):'%s'", short_name); goto next; } ssize_t sz = 4*1024; char *text = NULL; bool editable = is_editable_file(short_name); if (!editable) { text = is_text_file(full_name, &sz); if (!text) { problem_data_add(problem_data, short_name, full_name, CD_FLAG_BIN + CD_FLAG_ISNOTEDITABLE ); goto next; } } char *content; if (sz < 4*1024) /* did is_text_file read entire file? */ { /* yes */ content = text; } else { /* no, need to read it all */ free(text); content = dd_load_text(dd, short_name); } /* Strip '\n' from one-line elements: */ char *nl = strchr(content, '\n'); if (nl && nl[1] == '\0') *nl = '\0'; /* Sanitize possibly corrupted utf8. * Of control chars, allow only tab and newline. */ char *sanitized = sanitize_utf8(content, (SANITIZE_ALL & ~SANITIZE_LF & ~SANITIZE_TAB) ); if (sanitized) { free(content); content = sanitized; } int flags = 0; if (editable) flags |= CD_FLAG_TXT | CD_FLAG_ISEDITABLE; else flags |= CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE; static const char *const list_files[] = { FILENAME_UID , FILENAME_PACKAGE , FILENAME_EXECUTABLE, FILENAME_TIME , FILENAME_COUNT , NULL }; if (is_in_string_list(short_name, (char**)list_files)) flags |= CD_FLAG_LIST; if (strcmp(short_name, FILENAME_TIME) == 0) flags |= CD_FLAG_UNIXTIME; problem_data_add(problem_data, short_name, content, flags ); free(content); next: free(short_name); free(full_name); } }
int main(int argc, char **argv) { setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif abrt_init(argv); struct ureport_server_config config; ureport_server_config_init(&config); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, OPT_u = 1 << 2, OPT_k = 1 << 3, OPT_t = 1 << 4, OPT_h = 1 << 5, OPT_i = 1 << 6, }; int ret = 1; /* "failure" (for now) */ int insecure = !config.ur_ssl_verify; const char *conf_file = UREPORT_CONF_FILE_PATH; const char *arg_server_url = NULL; const char *client_auth = NULL; const char *http_auth = NULL; GList *auth_items = NULL; const char *dump_dir_path = "."; const char *ureport_hash = NULL; int ureport_hash_from_rt = 0; int rhbz_bug = -1; int rhbz_bug_from_rt = 0; const char *email_address = NULL; int email_address_from_env = 0; char *comment = NULL; int comment_file = 0; char *attach_value = NULL; char *attach_value_from_rt = NULL; char *attach_value_from_rt_data = NULL; char *report_result_type = NULL; char *attach_type = NULL; struct dump_dir *dd = NULL; struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT__DUMP_DIR(&dump_dir_path), OPT_STRING('u', "url", &arg_server_url, "URL", _("Specify server URL")), OPT_BOOL('k', "insecure", &insecure, _("Allow insecure connection to ureport server")), OPT_STRING('t', "auth", &client_auth, "SOURCE", _("Use client authentication")), OPT_STRING('h', "http-auth", &http_auth, "CREDENTIALS", _("Use HTTP Authentication")), OPT_LIST('i', "auth_items", &auth_items, "AUTH_ITEMS", _("Additional files included in 'auth' key")), OPT_STRING('c', NULL, &conf_file, "FILE", _("Configuration file")), OPT_STRING('a', "attach", &ureport_hash, "BTHASH", _("bthash of uReport to attach (conflicts with -A)")), OPT_BOOL('A', "attach-rt", &ureport_hash_from_rt, _("attach to a bthash from reported_to (conflicts with -a)")), OPT_STRING('e', "email", &email_address, "EMAIL", _("contact e-mail address (requires -a|-A, conflicts with -E)")), OPT_BOOL('E', "email-env", &email_address_from_env, _("contact e-mail address from environment or configuration file (requires -a|-A, conflicts with -e)")), OPT_INTEGER('b', "bug-id", &rhbz_bug, _("attach RHBZ bug (requires -a|-A, conflicts with -B)")), OPT_BOOL('B', "bug-id-rt", &rhbz_bug_from_rt, _("attach last RHBZ bug from reported_to (requires -a|-A, conflicts with -b)")), OPT_STRING('o', "comment", &comment, "DESCRIPTION", _("attach short text (requires -a|-A, conflicts with -D)")), OPT_BOOL('O', "comment-file", &comment_file, _("attach short text from comment (requires -a|-A, conflicts with -d)")), /* va l ue */ OPT_STRING('l', "value", &attach_value, "DATA", _("attach value (requires -a|-A and -T, conflicts with -L)")), OPT_STRING('L', "value-rt", &attach_value_from_rt, "FIELD", _("attach data of FIELD [URL] of the last report result (requires -a|-A, -r and -T, conflicts with -l)")), OPT_STRING('r', "report-result-type", &report_result_type, "REPORT_RESULT_TYPE", _("use REPORT_RESULT_TYPE when looking for FIELD in reported_to (used only with -L)")), OPT_STRING('T', "type", &attach_type, "ATTACHMENT_TYPE", _("attach DATA as ureport attachment ATTACHMENT_TYPE (used only with -l|-L)")), OPT_END(), }; const char *program_usage_string = _( "& [-v] [-c FILE] [-u URL] [-k] [-t SOURCE] [-h CREDENTIALS]\n" " [-A -a bthash -B -b bug-id -E -e email -O -o comment] [-d DIR]\n" " [-A -a bthash -T ATTACHMENT_TYPE -r REPORT_RESULT_TYPE -L RESULT_FIELD] [-d DIR]\n" " [-A -a bthash -T ATTACHMENT_TYPE -l DATA] [-d DIR]\n" "& [-v] [-c FILE] [-u URL] [-k] [-t SOURCE] [-h CREDENTIALS] [-i AUTH_ITEMS] [-d DIR]\n" "\n" "Upload micro report or add an attachment to a micro report\n" "\n" "Reads the default configuration from "UREPORT_CONF_FILE_PATH ); unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); map_string_t *settings = new_map_string(); load_conf_file(conf_file, settings, /*skip key w/o values:*/ false); ureport_server_config_load(&config, settings); if (opts & OPT_u) ureport_server_config_set_url(&config, xstrdup(arg_server_url)); if (opts & OPT_k) config.ur_ssl_verify = !insecure; if (opts & OPT_t) ureport_server_config_set_client_auth(&config, client_auth); if (opts & OPT_h) ureport_server_config_load_basic_auth(&config, http_auth); if (opts & OPT_i) { g_list_free_full(config.ur_prefs.urp_auth_items, free); config.ur_prefs.urp_auth_items = auth_items; } if (!config.ur_url) ureport_server_config_set_url(&config, xstrdup(DEFAULT_WEB_SERVICE_URL)); if (ureport_hash && ureport_hash_from_rt) error_msg_and_die("You need to pass either -a bthash or -A"); if (rhbz_bug >= 0 && rhbz_bug_from_rt) error_msg_and_die("You need to pass either -b bug-id or -B"); if (email_address && email_address_from_env) error_msg_and_die("You need to pass either -e bthash or -E"); if (comment && comment_file) error_msg_and_die("You need to pass either -o comment or -O"); if (attach_value && attach_value_from_rt) error_msg_and_die("You need to pass either -l url or -L"); if ((attach_value || attach_value_from_rt) && attach_type == NULL) error_msg_and_die("You need to pass -T together with -l and -L"); if (attach_value_from_rt) { if (report_result_type == NULL) error_msg_and_die("You need to pass -r together with -L"); /* If you introduce a new recognized value, don't forget to update * the documentation and the conditions below. */ if (strcmp(attach_value_from_rt, "URL") != 0) error_msg_and_die("-L accepts only 'URL'"); } if (ureport_hash_from_rt || rhbz_bug_from_rt || comment_file || attach_value_from_rt) { dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY); if (!dd) xfunc_die(); if (ureport_hash_from_rt) { report_result_t *ureport_result = find_in_reported_to(dd, "uReport"); if (!ureport_result || !ureport_result->bthash) error_msg_and_die(_("This problem does not have an uReport assigned.")); /* sorry, this will be leaked */ ureport_hash = xstrdup(ureport_result->bthash); free_report_result(ureport_result); } if (rhbz_bug_from_rt) { report_result_t *bz_result = find_in_reported_to(dd, "Bugzilla"); if (!bz_result || !bz_result->url) error_msg_and_die(_("This problem has not been reported to Bugzilla.")); char *bugid_ptr = strstr(bz_result->url, "show_bug.cgi?id="); if (!bugid_ptr) error_msg_and_die(_("Unable to find bug ID in bugzilla URL '%s'"), bz_result->url); bugid_ptr += strlen("show_bug.cgi?id="); /* we're just reading int, sscanf works fine */ if (sscanf(bugid_ptr, "%d", &rhbz_bug) != 1) error_msg_and_die(_("Unable to parse bug ID from bugzilla URL '%s'"), bz_result->url); free_report_result(bz_result); } if (comment_file) { comment = dd_load_text(dd, FILENAME_COMMENT); if (comment == NULL) error_msg_and_die(_("Cannot attach comment from 'comment' file")); if (comment[0] == '\0') error_msg_and_die(_("'comment' file is empty")); } if (attach_value_from_rt) { report_result_t *result = find_in_reported_to(dd, report_result_type); if (!result) error_msg_and_die(_("This problem has not been reported to '%s'."), report_result_type); /* If you introduce a new attach_value_from_rt recognized value, * this condition will become invalid. */ if (!result->url) error_msg_and_die(_("The report result '%s' is missing URL."), report_result_type); /* Avoid the need to duplicate the string. */ attach_value = attach_value_from_rt_data = result->url; result->url = NULL; free_report_result(result); } dd_close(dd); } if (email_address_from_env) { UREPORT_OPTION_VALUE_FROM_CONF(settings, "ContactEmail", email_address, (const char *)); if (!email_address) error_msg_and_die(_("Neither environment variable 'uReport_ContactEmail' nor configuration option 'ContactEmail' is set")); } if (ureport_hash) { if (rhbz_bug < 0 && !email_address && !comment && !attach_value) error_msg_and_die(_("You need to specify bug ID, contact email, comment or all of them")); if (rhbz_bug >= 0) { if (ureport_attach_int(ureport_hash, "RHBZ", rhbz_bug, &config)) goto finalize; } if (email_address) { if (ureport_attach_string(ureport_hash, "email", email_address, &config)) goto finalize; } if (comment) { if (ureport_attach_string(ureport_hash, "comment", comment, &config)) goto finalize; } if (attach_value) { if (ureport_attach_string(ureport_hash, attach_type, attach_value, &config)) goto finalize; } ret = 0; goto finalize; } if (!ureport_hash && (rhbz_bug >= 0 || email_address)) error_msg_and_die(_("You need to specify bthash of the uReport to attach.")); struct ureport_preferences *prefs = &(config.ur_prefs); prefs->urp_flags |= UREPORT_PREF_FLAG_RETURN_ON_FAILURE; char *json_ureport = ureport_from_dump_dir_ext(dump_dir_path, prefs); if (!json_ureport) { error_msg(_("Failed to generate microreport from the problem data")); goto finalize; } struct ureport_server_response *response = ureport_submit(json_ureport, &config); free(json_ureport); if (!response) goto finalize; if (!response->urr_is_error) { log_notice("is known: %s", response->urr_value); ret = 0; /* "success" */ if (!ureport_server_response_save_in_dump_dir(response, dump_dir_path, &config)) xfunc_die(); /* If a reported problem is not known then emit NEEDMORE */ if (strcmp("true", response->urr_value) == 0) { log(_("This problem has already been reported.")); if (response->urr_message) log("%s", response->urr_message); ret = EXIT_STOP_EVENT_RUN; } } else error_msg(_("Server responded with an error: '%s'"), response->urr_value); ureport_server_response_free(response); finalize: free(attach_value_from_rt_data); if (config.ur_prefs.urp_auth_items == auth_items) config.ur_prefs.urp_auth_items = NULL; free_map_string(settings); ureport_server_config_destroy(&config); return ret; }
int main(int argc, char **argv) { abrt_init(argv); const char *dump_dir_name = "."; /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( "\b [-v] -d DIR\n" "\n" "Calculates and saves UUID of coredump in dump directory DIR" ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Dump directory")), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); export_abrt_envvars(0); /* Run unstrip -n and trim its output, leaving only sizes and build ids */ char *unstrip_n_output = run_unstrip_n(dump_dir_name, /*timeout_sec:*/ 30); if (!unstrip_n_output) return 1; /* bad dump_dir_name, can't run unstrip, etc... */ /* modifies unstrip_n_output in-place: */ trim_unstrip_output(unstrip_n_output, unstrip_n_output); /* Hash package + executable + unstrip_n_output and save it as UUID */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; char *executable = dd_load_text(dd, FILENAME_EXECUTABLE); char *package = dd_load_text(dd, FILENAME_PACKAGE); /* Package variable has "firefox-3.5.6-1.fc11[.1]" format */ /* Remove distro suffix and maybe least significant version number */ char *p = package; while (*p) { if (*p == '.' && (p[1] < '0' || p[1] > '9')) { /* We found "XXXX.nondigitXXXX", trim this part */ *p = '\0'; break; } p++; } char *first_dot = strchr(package, '.'); if (first_dot) { char *last_dot = strrchr(first_dot, '.'); if (last_dot != first_dot) { /* There are more than one dot: "1.2.3" * Strip last part, we don't want to distinquish crashes * in packages which differ only by minor release number. */ *last_dot = '\0'; } } char *string_to_hash = xasprintf("%s%s%s", package, executable, unstrip_n_output); /*free(package);*/ /*free(executable);*/ /*free(unstrip_n_output);*/ char hash_str[SHA1_RESULT_LEN*2 + 1]; create_hash(hash_str, string_to_hash); dd_save_text(dd, FILENAME_UUID, hash_str); dd_close(dd); return 0; }
static int SavePackageDescriptionToDebugDump(const char *dump_dir_name, const char *chroot) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; char *type = dd_load_text(dd, FILENAME_TYPE); if (!strcmp(type, "Kerneloops")) { dd_save_text(dd, FILENAME_PACKAGE, "kernel"); dd_save_text(dd, FILENAME_COMPONENT, "kernel"); dd_close(dd); free(type); return 0; } free(type); char *cmdline = NULL; char *executable = NULL; char *rootdir = NULL; char *package_short_name = NULL; struct pkg_envra *pkg_name = NULL; char *component = NULL; int error = 1; /* note: "goto ret" statements below free all the above variables, * but they don't dd_close(dd) */ cmdline = dd_load_text_ext(dd, FILENAME_CMDLINE, DD_FAIL_QUIETLY_ENOENT); executable = dd_load_text(dd, FILENAME_EXECUTABLE); if (chroot == NULL) chroot = rootdir = dd_load_text_ext(dd, FILENAME_ROOTDIR, DD_FAIL_QUIETLY_ENOENT | DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE); /* Close dd while we query package database. It can take some time, * don't want to keep dd locked longer than necessary */ dd_close(dd); if (is_path_blacklisted(executable)) { log("Blacklisted executable '%s'", executable); goto ret; /* return 1 (failure) */ } pkg_name = rpm_get_package_nvr(executable, chroot); if (!pkg_name) { if (settings_bProcessUnpackaged) { log_info("Crash in unpackaged executable '%s', " "proceeding without packaging information", executable); goto ret0; /* no error */ } log("Executable '%s' doesn't belong to any package" " and ProcessUnpackaged is set to 'no'", executable ); goto ret; /* return 1 (failure) */ } /* Check well-known interpreter names */ const char *basename = strrchr(executable, '/'); if (basename) basename++; else basename = executable; /* if basename is known interpreter, we want to blame the running script * not the interpreter */ if (g_list_find_custom(settings_Interpreters, basename, (GCompareFunc)g_strcmp0)) { struct pkg_envra *script_pkg = get_script_name(cmdline, &executable, chroot); /* executable may have changed, check it again */ if (is_path_blacklisted(executable)) { log("Blacklisted executable '%s'", executable); goto ret; /* return 1 (failure) */ } if (!script_pkg) { /* Script name is not absolute, or it doesn't * belong to any installed package. */ if (!settings_bProcessUnpackaged) { log("Interpreter crashed, but no packaged script detected: '%s'", cmdline); goto ret; /* return 1 (failure) */ } /* Unpackaged script, but the settings says we want to keep it. * BZ plugin wont allow to report this anyway, because component * is missing, so there is no reason to mark it as not_reportable. * Someone might want to use abrt to report it using ftp. */ goto ret0; } free_pkg_envra(pkg_name); pkg_name = script_pkg; } package_short_name = xasprintf("%s", pkg_name->p_name); log_info("Package:'%s' short:'%s'", pkg_name->p_nvr, package_short_name); if (g_list_find_custom(settings_setBlackListedPkgs, package_short_name, (GCompareFunc)g_strcmp0)) { log("Blacklisted package '%s'", package_short_name); goto ret; /* return 1 (failure) */ } if (settings_bOpenGPGCheck) { if (!rpm_chk_fingerprint(package_short_name)) { log("Package '%s' isn't signed with proper key", package_short_name); goto ret; /* return 1 (failure) */ } /* We used to also check the integrity of the executable here: * if (!CheckHash(package_short_name.c_str(), executable)) BOOM(); * Checking the MD5 sum requires to run prelink to "un-prelink" the * binaries - this is considered potential security risk so we don't * do it now, until we find some non-intrusive way. */ } component = rpm_get_component(executable, chroot); dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) goto ret; /* return 1 (failure) */ if (pkg_name) { dd_save_text(dd, FILENAME_PACKAGE, pkg_name->p_nvr); dd_save_text(dd, FILENAME_PKG_EPOCH, pkg_name->p_epoch); dd_save_text(dd, FILENAME_PKG_NAME, pkg_name->p_name); dd_save_text(dd, FILENAME_PKG_VERSION, pkg_name->p_version); dd_save_text(dd, FILENAME_PKG_RELEASE, pkg_name->p_release); dd_save_text(dd, FILENAME_PKG_ARCH, pkg_name->p_arch); } if (component) dd_save_text(dd, FILENAME_COMPONENT, component); dd_close(dd); ret0: error = 0; ret: free(cmdline); free(executable); free(rootdir); free(package_short_name); free_pkg_envra(pkg_name); free(component); return error; }
void load_problem_data_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd) { char *short_name; char *full_name; dd_init_next_file(dd); while (dd_get_next_file(dd, &short_name, &full_name)) { ssize_t sz = 4*1024; char *text = NULL; bool editable = is_editable_file(short_name); if (!editable) { text = is_text_file(full_name, &sz); if (!text) { add_to_problem_data_ext(problem_data, short_name, full_name, CD_FLAG_BIN + CD_FLAG_ISNOTEDITABLE ); free(short_name); free(full_name); continue; } } char *content; if (sz < 4*1024) /* did is_text_file read entire file? */ { content = text; /* Strip '\n' from one-line elements: */ char *nl = strchr(content, '\n'); if (nl && nl[1] == '\0') *nl = '\0'; } else { /* no, need to read it all */ free(text); content = dd_load_text(dd, short_name); } int flags = 0; if (editable) flags |= CD_FLAG_TXT | CD_FLAG_ISEDITABLE; else flags |= CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE; static const char *const list_files[] = { FILENAME_UID , FILENAME_PACKAGE , FILENAME_EXECUTABLE, FILENAME_TIME , FILENAME_COUNT , NULL }; if (is_in_string_list(short_name, (char**)list_files)) flags |= CD_FLAG_LIST; if (strcmp(short_name, FILENAME_TIME) == 0) flags |= CD_FLAG_UNIXTIME; add_to_problem_data_ext(problem_data, short_name, content, flags ); free(short_name); free(full_name); free(content); } }
static void set_settings(mantisbt_settings_t *m, map_string_t *settings, struct dump_dir *dd) { const char *environ; environ = getenv("Mantisbt_Login"); m->m_login = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Login")); environ = getenv("Mantisbt_Password"); m->m_password = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Password")); environ = getenv("Mantisbt_MantisbtURL"); m->m_mantisbt_url = environ ? environ : get_map_string_item_or_empty(settings, "MantisbtURL"); if (!m->m_mantisbt_url[0]) m->m_mantisbt_url = "http://localhost/mantisbt"; else { /* We don't want trailing '/': "https://host/dir/" -> "https://host/dir" */ char *last_slash = strrchr(m->m_mantisbt_url, '/'); if (last_slash && last_slash[1] == '\0') *last_slash = '\0'; } m->m_mantisbt_soap_url = concat_path_file(m->m_mantisbt_url, "api/soap/mantisconnect.php"); environ = getenv("Mantisbt_Project"); if (environ) { m->m_project = xstrdup(environ); environ = getenv("Mantisbt_ProjectVersion"); if (environ) m->m_project_version = xstrdup(environ); } else { const char *option = get_map_string_item_or_NULL(settings, "Project"); if (option) m->m_project = xstrdup(option); option = get_map_string_item_or_NULL(settings, "ProjectVersion"); if (option) m->m_project_version = xstrdup(option); } if (!m->m_project || !*m->m_project) /* if not overridden or empty... */ { free(m->m_project); free(m->m_project_version); if (dd != NULL) { map_string_t *osinfo = new_map_string(); char *os_info_data = dd_load_text(dd, FILENAME_OS_INFO); parse_osinfo(os_info_data, osinfo); free(os_info_data); parse_osinfo_for_mantisbt(osinfo, &m->m_project, &m->m_project_version); free_map_string(osinfo); } } environ = getenv("Mantisbt_SSLVerify"); m->m_ssl_verify = string_to_bool(environ ? environ : get_map_string_item_or_empty(settings, "SSLVerify")); environ = getenv("Mantisbt_DontMatchComponents"); m->m_DontMatchComponents = environ ? environ : get_map_string_item_or_empty(settings, "DontMatchComponents"); m->m_create_private = get_global_create_private_ticket(); if (!m->m_create_private) { environ = getenv("Mantisbt_CreatePrivate"); m->m_create_private = string_to_bool(environ ? environ : get_map_string_item_or_empty(settings, "CreatePrivate")); } log_notice("create private MantisBT ticket: '%s'", m->m_create_private ? "YES": "NO"); }
static int is_crash_a_dup(const char *dump_dir_name, void *param) { struct cdump_state *state = (struct cdump_state *)param; if (state->uuid) return 0; /* we already checked it, don't do it again */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 0; /* wtf? (error, but will be handled elsewhere later) */ state->uuid = dd_load_text_ext(dd, FILENAME_UUID, DD_FAIL_QUIETLY_ENOENT + DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE ); dd_close(dd); if (!state->uuid) { return 0; /* no uuid (yet), "run_event, please continue iterating" */ } /* Scan crash dumps looking for a dup */ //TODO: explain why this is safe wrt concurrent runs DIR *dir = opendir(DEBUG_DUMPS_DIR); if (dir != NULL) { struct dirent *dent; while ((dent = readdir(dir)) != NULL) { if (dot_or_dotdot(dent->d_name)) continue; /* skip "." and ".." */ int different; char *uid, *uuid; char *dump_dir_name2 = concat_path_file(DEBUG_DUMPS_DIR, dent->d_name); if (strcmp(dump_dir_name, dump_dir_name2) == 0) goto next; /* we are never a dup of ourself */ dd = dd_opendir(dump_dir_name2, /*flags:*/ DD_FAIL_QUIETLY_ENOENT); if (!dd) goto next; uid = dd_load_text(dd, FILENAME_UID); uuid = dd_load_text(dd, FILENAME_UUID); dd_close(dd); different = strcmp(state->uid, uid) || strcmp(state->uuid, uuid); free(uid); free(uuid); if (different) goto next; state->crash_dump_dup_name = dump_dir_name2; /* "run_event, please stop iterating": */ return 1; next: free(dump_dir_name2); } closedir(dir); } /* No dup found */ return 0; /* "run_event, please continue iterating" */ }
mw_result_t LoadDebugDump(const char *dump_dir_name, problem_data_t **problem_data) { mw_result_t res; struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return MW_ERROR; struct cdump_state state; state.uid = dd_load_text(dd, FILENAME_UID); state.uuid = NULL; state.crash_dump_dup_name = NULL; char *analyzer = dd_load_text(dd, FILENAME_ANALYZER); dd_close(dd); res = MW_ERROR; /* Run post-create event handler(s) */ struct run_event_state *run_state = new_run_event_state(); run_state->post_run_callback = is_crash_a_dup; run_state->post_run_param = &state; run_state->logging_callback = do_log; int r = run_event_on_dir_name(run_state, dump_dir_name, "post-create"); free_run_event_state(run_state); //TODO: consider this case: // new dump is created, post-create detects that it is a dup, // but then FillCrashInfo(dup_name) *FAILS*. // In this case, we later delete damaged dup_name (right?) // but new dump never gets its FILENAME_COUNT set! /* Is crash a dup? (In this case, is_crash_a_dup() should have * aborted "post-create" event processing as soon as it saw uuid * and determined that there is another crash with same uuid. * In this case it sets state.crash_dump_dup_name) */ if (!state.crash_dump_dup_name) { /* No. Was there error on one of processing steps in run_event? */ if (r != 0) goto ret; /* yes */ /* Was uuid created after all? (In this case, is_crash_a_dup() * should have fetched it and created state.uuid) */ if (!state.uuid) { /* no */ log("Dump directory '%s' has no UUID element", dump_dir_name); goto ret; } } else { dump_dir_name = state.crash_dump_dup_name; } /* Loads problem_data (from the *first debugdump dir* if this one is a dup) * Returns: * MW_OCCURRED: "crash count is != 1" (iow: it is > 1 - dup) * MW_OK: "crash count is 1" (iow: this is a new crash, not a dup) * else: an error code */ { dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) { res = MW_ERROR; goto ret; } /* Reset mode/uig/gid to correct values for all files created by event run */ dd_sanitize_mode_and_owner(dd); /* Update count */ char *count_str = dd_load_text_ext(dd, FILENAME_COUNT, DD_FAIL_QUIETLY_ENOENT); unsigned long count = strtoul(count_str, NULL, 10); count++; char new_count_str[sizeof(long)*3 + 2]; sprintf(new_count_str, "%lu", count); dd_save_text(dd, FILENAME_COUNT, new_count_str); dd_close(dd); *problem_data = FillCrashInfo(dump_dir_name); if (*problem_data != NULL) { res = MW_OK; if (count > 1) { log("Dump directory is a duplicate of %s", dump_dir_name); res = MW_OCCURRED; } } } ret: free(state.uuid); free(state.uid); free(state.crash_dump_dup_name); free(analyzer); return res; }