diff options
| author | Nikola Pajkovsky <npajkovs@redhat.com> | 2010-08-30 19:28:08 +0200 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-08-30 19:28:08 +0200 |
| commit | eb6a80fe031f648d11344ed912e9a5e1e722545e (patch) | |
| tree | 837100d82635c022447ff1821f3dcdab4278e45e /lib/plugins | |
| parent | dac728745922a717db05f2e8dcbe6c533dc0df6f (diff) | |
| download | abrt-eb6a80fe031f648d11344ed912e9a5e1e722545e.tar.gz abrt-eb6a80fe031f648d11344ed912e9a5e1e722545e.tar.xz abrt-eb6a80fe031f648d11344ed912e9a5e1e722545e.zip | |
get rid of CDebugDump class
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib/plugins')
| -rw-r--r-- | lib/plugins/CCpp.cpp | 174 | ||||
| -rw-r--r-- | lib/plugins/Kerneloops.cpp | 11 | ||||
| -rw-r--r-- | lib/plugins/KerneloopsScanner.cpp | 18 | ||||
| -rw-r--r-- | lib/plugins/Python.cpp | 16 | ||||
| -rw-r--r-- | lib/plugins/RunApp.cpp | 9 | ||||
| -rw-r--r-- | lib/plugins/SOSreport.cpp | 9 |
6 files changed, 132 insertions, 105 deletions
diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp index 2ecf9308..7665cad3 100644 --- a/lib/plugins/CCpp.cpp +++ b/lib/plugins/CCpp.cpp @@ -186,18 +186,17 @@ static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs { update_client(_("Generating backtrace")); - string UID; - string executable; - CDebugDump dd; - if (!dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); - return false; + return NULL; } - dd.LoadText(FILENAME_EXECUTABLE, executable); - dd.LoadText(CD_UID, UID); - dd.Close(); + char *uid = dd_loadtxt(dd, CD_UID); + char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE); + dd_close(dd); // Workaround for // http://sourceware.org/bugzilla/show_bug.cgi?id=9622 @@ -248,7 +247,8 @@ static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs * BINARY_FILE if it is newer (to at least avoid gdb complaining). */ args[4] = (char*)"-ex"; - args[5] = xasprintf("file %s", executable.c_str()); + args[5] = xasprintf("file %s", executable); + free(executable); args[6] = (char*)"-ex"; args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir); @@ -277,7 +277,7 @@ static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs while (1) { args[9] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full); - bt = exec_vp(args, xatoi_u(UID.c_str()), /*redirect_stderr:*/ 1, NULL); + bt = exec_vp(args, xatoi_u(uid), /*redirect_stderr:*/ 1, NULL); if (bt && (bt_depth <= 64 || strlen(bt) < 256*1024)) { free(args[9]); @@ -300,6 +300,7 @@ static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs free(bt); free(args[9]); } + free(uid); free(args[5]); free(args[7]); return bt; @@ -334,16 +335,16 @@ static void GetIndependentBuildIdPC(const char *unstrip_n_output, static char* run_unstrip_n(const char *pDebugDumpDir) { - string UID; - CDebugDump dd; - if (!dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); return NULL; } - dd.LoadText(CD_UID, UID); - dd.Close(); + char *uid = dd_loadtxt(dd, CD_UID); + dd_close(dd); char* args[4]; args[0] = (char*)"eu-unstrip"; @@ -351,7 +352,8 @@ static char* run_unstrip_n(const char *pDebugDumpDir) args[2] = (char*)"-n"; args[3] = NULL; - char *out = exec_vp(args, xatoi_u(UID.c_str()), /*redirect_stderr:*/ 0, NULL); + char *out = exec_vp(args, xatoi_u(uid), /*redirect_stderr:*/ 0, NULL); + free(uid); free(args[1]); @@ -527,18 +529,17 @@ static void trim_debuginfo_cache(unsigned max_mb) string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) { - string executable; - string package; - CDebugDump dd; - if (!dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); return string(""); } - dd.LoadText(FILENAME_EXECUTABLE, executable); - dd.LoadText(FILENAME_PACKAGE, package); - dd.Close(); + char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE); + char *package = dd_loadtxt(dd, FILENAME_PACKAGE); + dd_close(dd); string independentBuildIdPC; char *unstrip_n_output = run_unstrip_n(pDebugDumpDir); @@ -551,8 +552,7 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) /* package variable has "firefox-3.5.6-1.fc11[.1]" format */ /* Remove distro suffix and maybe least significant version number */ - char *trimmed_package = xstrdup(package.c_str()); - char *p = trimmed_package; + char *p = package; while (*p) { if (*p == '.' && (p[1] < '0' || p[1] > '9')) @@ -563,7 +563,7 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) } p++; } - char *first_dot = strchr(trimmed_package, '.'); + char *first_dot = strchr(package, '.'); if (first_dot) { char *last_dot = strrchr(first_dot, '.'); @@ -576,26 +576,34 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) *last_dot = '\0'; } } - string hash_str = trimmed_package + executable + independentBuildIdPC; - free(trimmed_package); - return create_hash(hash_str.c_str()); + + char *hash_str = xasprintf("%s%s%s", package, executable, independentBuildIdPC.c_str()); + free(package); + free(executable); + + string hash = create_hash(hash_str); + free(hash_str); + + return hash; } string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) { - CDebugDump dd; - if (!dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); return string(""); } - if (dd.Exist(FILENAME_GLOBAL_UUID)) + if (dd_exist(dd, FILENAME_GLOBAL_UUID)) { - string uuid; - dd.LoadText(FILENAME_GLOBAL_UUID, uuid); - dd.Close(); - return uuid; + char *uuid = dd_loadtxt(dd, FILENAME_GLOBAL_UUID); + dd_close(dd); + string ret = uuid; + free(uuid); + return ret; } else { @@ -603,13 +611,10 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) // This whole block should be deleted for Fedora 14. log(_("Getting global universal unique identification...")); - string executable; - string package; - string uid_str; - dd.LoadText(FILENAME_EXECUTABLE, executable); - dd.LoadText(FILENAME_PACKAGE, package); - if (m_bBacktrace) - dd.LoadText(CD_UID, uid_str); + string backtrace_path = concat_path_file(pDebugDumpDir, FILENAME_BACKTRACE); + char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE); + char *package = dd_loadtxt(dd, FILENAME_PACKAGE); + char *uid_str = m_bBacktrace ? dd_loadtxt(dd, CD_UID) : xstrdup(""); string independent_backtrace; if (m_bBacktrace) @@ -641,7 +646,7 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) close(pipeout[0]); /* read side of the pipe */ /* abrt-backtrace is executed under the user's uid and gid. */ - uid_t uid = xatoi_u(uid_str.c_str()); + uid_t uid = xatoi_u(uid_str); struct passwd* pw = getpwuid(uid); gid_t gid = pw ? pw->pw_gid : uid; setgroups(1, &gid); @@ -707,12 +712,18 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) */ else { - dd.SaveText(FILENAME_RATING, "0"); + dd_savetxt(dd, FILENAME_RATING, "0"); } - dd.Close(); + dd_close(dd); + + char *hash_str = xasprintf("%s%s%s", package, executable, independent_backtrace.c_str()); + free(package); + free(executable); - string hash_base = package + executable + independent_backtrace; - return create_hash(hash_base.c_str()); + string hash = create_hash(hash_str); + free(hash_str); + + return hash; } } @@ -748,42 +759,50 @@ static bool DebuginfoCheckPolkit(uid_t uid) void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) { - string package, executable, UID; - - CDebugDump dd; - if (!dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); return; } /* Skip remote crashes. */ - if (dd.Exist(FILENAME_REMOTE)) + if (dd_exist(dd, FILENAME_REMOTE)) { - std::string remote_str; - dd.LoadText(FILENAME_REMOTE, remote_str); - bool remote = (remote_str.find('1') != std::string::npos); + char *remote_str = dd_loadtxt(dd, FILENAME_REMOTE); + bool remote = (remote_str[0] != '1'); + free(remote_str); if (remote && !m_bBacktraceRemotes) + { + dd_close(dd); return; + } } if (!m_bBacktrace) + { + dd_close(dd); return; + } if (!force) { - bool bt_exists = dd.Exist(FILENAME_BACKTRACE); + int bt_exists = dd_exist(dd, FILENAME_BACKTRACE); if (bt_exists) + { + dd_close(dd); return; /* backtrace already exists */ + } } - dd.LoadText(FILENAME_PACKAGE, package); - dd.LoadText(FILENAME_EXECUTABLE, executable); - dd.LoadText(CD_UID, UID); - dd.Close(); /* do not keep dir locked longer than needed */ + char *package = dd_loadtxt(dd, FILENAME_PACKAGE); + char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE); + char *uid = dd_loadtxt(dd, CD_UID); + dd_close(dd); /* do not keep dir locked longer than needed */ char *build_ids = NULL; - if (m_bInstallDebugInfo && DebuginfoCheckPolkit(xatoi_u(UID.c_str()))) + if (m_bInstallDebugInfo && DebuginfoCheckPolkit(xatoi_u(uid))) { if (m_nDebugInfoCacheMB > 0) trim_debuginfo_cache(m_nDebugInfoCacheMB); @@ -803,22 +822,25 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) char *bt_build_ids = xasprintf("%s%s", backtrace_str, (build_ids) ? build_ids : ""); free(build_ids); - if (!dd.Open(pDebugDumpDir)) + dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); return; } - dd.SaveText(FILENAME_BACKTRACE, bt_build_ids); + dd_savetxt(dd, FILENAME_BACKTRACE, bt_build_ids); free(bt_build_ids); if (m_bMemoryMap) - dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); + dd_savetxt(dd, FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); /* Compute and store UUID from the backtrace. */ char *backtrace_cpy = xstrdup(backtrace_str); struct backtrace *backtrace = backtrace_parse(backtrace_cpy, false, false); free(backtrace_cpy); + if (backtrace) { /* Get the quality of the full backtrace. */ @@ -846,9 +868,9 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) /* Compute UUID. */ struct strbuf *bt = backtrace_tree_as_str(backtrace, false); - strbuf_prepend_str(bt, executable.c_str()); - strbuf_prepend_str(bt, package.c_str()); - dd.SaveText(FILENAME_GLOBAL_UUID, create_hash(bt->buf).c_str()); + strbuf_prepend_str(bt, executable); + strbuf_prepend_str(bt, package); + dd_savetxt(dd, FILENAME_GLOBAL_UUID, create_hash(bt->buf).c_str()); strbuf_free(bt); /* Compute and store backtrace rating. */ @@ -864,7 +886,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) else if (qtot < 0.8f) rating = "2"; else if (qtot < 0.9f) rating = "3"; else rating = "4"; - dd.SaveText(FILENAME_RATING, rating); + dd_savetxt(dd, FILENAME_RATING, rating); /* Get the function name from the crash frame. */ if (crash_thread) @@ -874,7 +896,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) if (abort_frame) crash_frame = abort_frame->next; if (crash_frame && crash_frame->function && 0 != strcmp(crash_frame->function, "??")) - dd.SaveText(FILENAME_CRASH_FUNCTION, crash_frame->function); + dd_savetxt(dd, FILENAME_CRASH_FUNCTION, crash_frame->function); } backtrace_free(backtrace); @@ -886,17 +908,19 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) the parser never fails, and it will be possible to get rid of the independent_backtrace and backtrace_rate_old. */ struct strbuf *ibt = independent_backtrace(backtrace_str); - strbuf_prepend_str(ibt, executable.c_str()); - strbuf_prepend_str(ibt, package.c_str()); - dd.SaveText(FILENAME_GLOBAL_UUID, create_hash(ibt->buf).c_str()); + strbuf_prepend_str(ibt, executable); + strbuf_prepend_str(ibt, package); + dd_savetxt(dd, FILENAME_GLOBAL_UUID, create_hash(ibt->buf).c_str()); strbuf_free(ibt); /* Compute and store backtrace rating. */ /* Crash frame is not known so store nothing. */ - dd.SaveText(FILENAME_RATING, to_string(backtrace_rate_old(backtrace_str)).c_str()); + dd_savetxt(dd, FILENAME_RATING, to_string(backtrace_rate_old(backtrace_str)).c_str()); } + free(executable); + free(package); free(backtrace_str); - dd.Close(); + dd_close(dd); } /* diff --git a/lib/plugins/Kerneloops.cpp b/lib/plugins/Kerneloops.cpp index 2ffc2e34..f6fa2606 100644 --- a/lib/plugins/Kerneloops.cpp +++ b/lib/plugins/Kerneloops.cpp @@ -126,17 +126,18 @@ std::string CAnalyzerKerneloops::GetLocalUUID(const char *pDebugDumpDir) { VERB3 log("Getting local universal unique identification"); - std::string oops; - CDebugDump dd; - if (!dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); return std::string(""); } - dd.LoadText(FILENAME_BACKTRACE, oops); + char *oops = dd_loadtxt(dd, FILENAME_BACKTRACE); + unsigned hash = hash_oops_str(oops); + free(oops); - unsigned hash = hash_oops_str(oops.c_str()); hash &= 0x7FFFFFFF; return to_string(hash); diff --git a/lib/plugins/KerneloopsScanner.cpp b/lib/plugins/KerneloopsScanner.cpp index 8c25dff8..1621b04d 100644 --- a/lib/plugins/KerneloopsScanner.cpp +++ b/lib/plugins/KerneloopsScanner.cpp @@ -133,18 +133,18 @@ int save_oops_to_debug_dump(const vector_string_t& oopsList) char *second_line = (char*)strchr(first_line, '\n'); /* never NULL */ *second_line++ = '\0'; - CDebugDump dd; - if (dd.Create(path, /*uid:*/ 0)) + dump_dir_t *dd = dd_init(); + if (dd_create(dd, path, /*uid:*/ 0)) { - dd.SaveText(FILENAME_ANALYZER, "Kerneloops"); - dd.SaveText(FILENAME_EXECUTABLE, "kernel"); - dd.SaveText(FILENAME_KERNEL, first_line); - dd.SaveText(FILENAME_CMDLINE, "not_applicable"); - dd.SaveText(FILENAME_BACKTRACE, second_line); + dd_savetxt(dd, FILENAME_ANALYZER, "Kerneloops"); + dd_savetxt(dd, FILENAME_EXECUTABLE, "kernel"); + dd_savetxt(dd, FILENAME_KERNEL, first_line); + dd_savetxt(dd, FILENAME_CMDLINE, "not_applicable"); + dd_savetxt(dd, FILENAME_BACKTRACE, second_line); /* Optional, makes generated bz more informative */ strchrnul(second_line, '\n')[0] = '\0'; - dd.SaveText(FILENAME_REASON, second_line); - dd.Close(); + dd_savetxt(dd, FILENAME_REASON, second_line); + dd_close(dd); } else errors++; diff --git a/lib/plugins/Python.cpp b/lib/plugins/Python.cpp index 7b6e761a..d634e0c5 100644 --- a/lib/plugins/Python.cpp +++ b/lib/plugins/Python.cpp @@ -26,19 +26,18 @@ using namespace std; string CAnalyzerPython::GetLocalUUID(const char *pDebugDumpDir) { - CDebugDump dd; - if (!dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir); return string(""); } - string bt; - dd.LoadText(FILENAME_BACKTRACE, bt); - dd.Close(); + char *bt = dd_loadtxt(dd, FILENAME_BACKTRACE); + dd_close(dd); - const char *bt_str = bt.c_str(); - const char *bt_end = strchrnul(bt_str, '\n'); + const char *bt_end = strchrnul(bt, '\n'); char hash_str[MD5_RESULT_LEN*2 + 1]; unsigned char hash2[MD5_RESULT_LEN]; @@ -49,7 +48,8 @@ string CAnalyzerPython::GetLocalUUID(const char *pDebugDumpDir) //md5_hash(bt_str, bt_end - bt_str, &md5ctx); // For now using compat version: { - char *copy = xstrndup(bt_str, bt_end - bt_str); + char *copy = xstrndup(bt, bt_end - bt); + free(bt); char *s = copy; char *d = copy; unsigned colon_cnt = 0; diff --git a/lib/plugins/RunApp.cpp b/lib/plugins/RunApp.cpp index 632c26f1..f5833565 100644 --- a/lib/plugins/RunApp.cpp +++ b/lib/plugins/RunApp.cpp @@ -58,15 +58,16 @@ void CActionRunApp::Run(const char *pActionDir, const char *pArgs, int force) if (args.size() > FILENAME) { - CDebugDump dd; - if (!dd.Open(pActionDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pActionDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pActionDir); return; } - dd.SaveBinary(args[FILENAME].c_str(), cmd_out, cmd_out_size); - dd.Close(); + dd_savebin(dd, args[FILENAME].c_str(), cmd_out, cmd_out_size); + dd_close(dd); } free(cmd_out); diff --git a/lib/plugins/SOSreport.cpp b/lib/plugins/SOSreport.cpp index 4c9358da..5180266f 100644 --- a/lib/plugins/SOSreport.cpp +++ b/lib/plugins/SOSreport.cpp @@ -51,20 +51,21 @@ void CActionSOSreport::Run(const char *pActionDir, const char *pArgs, int force) { if (!force) { - CDebugDump dd; - if (!dd.Open(pActionDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pActionDir)) { + dd_close(dd); VERB1 log(_("Unable to open debug dump '%s'"), pActionDir); return; } - bool bt_exists = dd.Exist("sosreport.tar.bz2") || dd.Exist("sosreport.tar.xz"); + bool bt_exists = dd_exist(dd, "sosreport.tar.bz2") || dd_exist(dd, "sosreport.tar.xz"); if (bt_exists) { VERB3 log("%s already exists, not regenerating", "sosreport.tar.bz2"); return; } - dd.Close(); + dd_close(dd); } static const char command_default[] = |
