diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-03 13:33:53 +0100 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-03 13:33:53 +0100 |
commit | 66fdda782198bd1c7b1c110d1337cd30a31206d9 (patch) | |
tree | 75aea4acc16cadaa78bc347617f6c34ca73f5fdd /lib/plugins | |
parent | 72fc15ea204311f061276d8a1df1489d720af61c (diff) | |
download | abrt-66fdda782198bd1c7b1c110d1337cd30a31206d9.tar.gz abrt-66fdda782198bd1c7b1c110d1337cd30a31206d9.tar.xz abrt-66fdda782198bd1c7b1c110d1337cd30a31206d9.zip |
switch "analyze" step processing to abrt_event.conf-driven way
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/CCpp.cpp | 294 | ||||
-rw-r--r-- | lib/plugins/CCpp.h | 1 | ||||
-rw-r--r-- | lib/plugins/Kerneloops.h | 1 | ||||
-rw-r--r-- | lib/plugins/Python.h | 1 |
4 files changed, 0 insertions, 297 deletions
diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp index 7415891f..ddc17206 100644 --- a/lib/plugins/CCpp.cpp +++ b/lib/plugins/CCpp.cpp @@ -74,197 +74,6 @@ static void create_hash(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *pInput //log("hash2:%s str:'%s'", hash_str, pInput); } -static void gen_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs, unsigned timeout_sec) -{ - update_client(_("Generating backtrace")); - - pid_t pid = fork(); - if (pid < 0) - { - perror_msg("fork"); - return; - } - if (pid == 0) /* child */ - { - char *argv[8]; /* abrt-action-generate-backtrace [-s] -tSEC -d DIR -i DIR1:DIR2 NULL */ - char **pp = argv; - *pp++ = (char*)"abrt-action-generate-backtrace"; - if (logmode & LOGMODE_SYSLOG) - *pp++ = (char*)"-s"; - *pp++ = xasprintf("-t%u", timeout_sec); - *pp++ = (char*)"-d"; - *pp++ = (char*)pDebugDumpDir; - *pp++ = (char*)"-i"; - *pp++ = (char*)pDebugInfoDirs; - *pp = NULL; - - execvp(argv[0], argv); - perror_msg_and_die("Can't execute '%s'", argv[0]); - } - /* parent */ - waitpid(pid, NULL, 0); -} - -/* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668 - * It is slated to be in F12/RHEL6. - * - * returned value must be freed - */ -static char *install_debug_infos(const char *pDebugDumpDir, const char *debuginfo_dirs) -{ - update_client(_("Starting the debuginfo installation")); - - int pipeout[2]; //TODO: can we use ExecVP? - xpipe(pipeout); - - fflush(NULL); - pid_t child = fork(); - if (child < 0) - { - /*close(pipeout[0]); - why bother */ - /*close(pipeout[1]); */ - perror_msg_and_die("fork"); - } - if (child == 0) - { - close(pipeout[0]); - xmove_fd(pipeout[1], STDOUT_FILENO); - xmove_fd(xopen("/dev/null", O_RDONLY), STDIN_FILENO); - - char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir); - /* SELinux guys are not happy with /tmp, using /var/run/abrt */ - char *tempdir = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu", (long)getpid(), (long)time(NULL)); - /* log() goes to stderr/syslog, it's ok to use it here */ - VERB1 log("Executing: %s %s %s %s", "abrt-action-install-debuginfo", coredump, tempdir, debuginfo_dirs); - /* We want parent to see errors in the same stream */ - xdup2(STDOUT_FILENO, STDERR_FILENO); - execlp("abrt-action-install-debuginfo", "abrt-action-install-debuginfo", coredump, tempdir, debuginfo_dirs, NULL); - perror_msg("Can't execute '%s'", "abrt-action-install-debuginfo"); - /* Serious error (1 means "some debuginfos not found") */ - exit(2); - } - - close(pipeout[1]); - - FILE *pipeout_fp = fdopen(pipeout[0], "r"); - if (pipeout_fp == NULL) /* never happens */ - { - close(pipeout[0]); - waitpid(child, NULL, 0); - return NULL; - } - - char *buff; - struct strbuf *buf_build_ids = strbuf_new(); - while ((buff = xmalloc_fgetline(pipeout_fp)) != NULL) - { - if (strncmp(buff, "MISSING:", 8) == 0) - { - strbuf_append_strf(buf_build_ids, "Debuginfo absent: %s\n", buff + 8); - free(buff); - continue; - } - - const char *p = buff; - while (*p == ' ' || *p == '\t') - { - p++; - } - - if (*p) - { - VERB1 log("%s", buff); - update_client("%s", buff); - } - free(buff); - } - fclose(pipeout_fp); - - int status = 0; - while (waitpid(child, &status, 0) < 0 && errno == EINTR) - continue; - if (WIFEXITED(status)) - { - if (WEXITSTATUS(status) > 1) - error_msg("%s exited with %u", "abrt-action-install-debuginfo", (int)WEXITSTATUS(status)); - } - else - { - error_msg("%s killed by signal %u", "abrt-action-install-debuginfo", (int)WTERMSIG(status)); - } - - return strbuf_free_nobuf(buf_build_ids); -} - -static double get_dir_size(const char *dirname, - string *worst_file, - double *maxsz) -{ - DIR *dp = opendir(dirname); - if (dp == NULL) - return 0; - - struct dirent *ep; - struct stat stats; - double size = 0; - while ((ep = readdir(dp)) != NULL) - { - if (dot_or_dotdot(ep->d_name)) - continue; - char *dname = concat_path_file(dirname, ep->d_name); - if (lstat(dname, &stats) != 0) - { - free(dname); - continue; - } - if (S_ISDIR(stats.st_mode)) - { - double sz = get_dir_size(dname, worst_file, maxsz); - size += sz; - } - else if (S_ISREG(stats.st_mode)) - { - double sz = stats.st_size; - size += sz; - - if (worst_file) - { - /* Calculate "weighted" size and age - * w = sz_kbytes * age_mins */ - sz /= 1024; - long age = (time(NULL) - stats.st_mtime) / 60; - if (age > 0) - sz *= age; - - if (sz > *maxsz) - { - *maxsz = sz; - *worst_file = dname; - } - } - } - free(dname); - } - closedir(dp); - return size; -} - -static void trim_debuginfo_cache(unsigned max_mb) -{ - while (1) - { - string worst_file; - double maxsz = 0; - double cache_sz = get_dir_size(DEBUGINFO_CACHE_DIR, &worst_file, &maxsz); - if (cache_sz / (1024 * 1024) < max_mb) - break; - VERB1 log("%s is %.0f bytes (over %u MB), deleting '%s'", - DEBUGINFO_CACHE_DIR, cache_sz, max_mb, worst_file.c_str()); - if (unlink(worst_file.c_str()) != 0) - perror_msg("Can't unlink '%s'", worst_file.c_str()); - } -} - string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) { struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0); @@ -402,109 +211,6 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) } } -static bool DebuginfoCheckPolkit(uid_t uid) -{ - fflush(NULL); - int child_pid = fork(); - if (child_pid < 0) - { - perror_msg_and_die("fork"); - } - - if (child_pid == 0) - { - //child - xsetreuid(uid, uid); - PolkitResult result = polkit_check_authorization(getpid(), - "org.fedoraproject.abrt.install-debuginfos"); - exit(result != PolkitYes); //exit 1 (failure) if not allowed - } - - //parent - int status; - if (waitpid(child_pid, &status, 0) > 0 - && WIFEXITED(status) - && WEXITSTATUS(status) == 0 - ) { - return true; //authorization OK - } - log("UID %d is not authorized to install debuginfos", uid); - return false; -} - -void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) -{ - if (!m_bBacktrace) - { - return; - } - - struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0); - if (!dd) - return; - - if (!force) - { - int bt_exists = dd_exist(dd, FILENAME_BACKTRACE); - if (bt_exists) - { - dd_close(dd); - return; /* backtrace already exists */ - } - } - - /* Skip remote crashes. */ - if (dd_exist(dd, FILENAME_REMOTE)) - { - char *remote_str = dd_load_text(dd, FILENAME_REMOTE); - bool remote = (remote_str[0] != '1'); - free(remote_str); - if (remote && !m_bBacktraceRemotes) - { - dd_close(dd); - return; - } - } - - char *uid = dd_load_text(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))) - { - if (m_nDebugInfoCacheMB > 0) - trim_debuginfo_cache(m_nDebugInfoCacheMB); - build_ids = install_debug_infos(pDebugDumpDir, m_sDebugInfoDirs.c_str()); - } - else - VERB1 log(_("Skipping the debuginfo installation")); - free(uid); - - /* Create and store backtrace and its hash. */ - gen_backtrace(pDebugDumpDir, m_sDebugInfoDirs.c_str(), m_nGdbTimeoutSec); - - dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0); - if (!dd) - { - free(build_ids); - return; - } - - /* Add build_ids to backtrace */ - char *backtrace_str = dd_load_text(dd, FILENAME_BACKTRACE); - char *bt_build_ids = xasprintf("%s%s", backtrace_str, (build_ids) ? build_ids : ""); - dd_save_text(dd, FILENAME_BACKTRACE, bt_build_ids); - free(build_ids); - free(bt_build_ids); - free(backtrace_str); - - /* TODO: remove, it's much easier to collect in the coredump helper */ - if (m_bMemoryMap) - dd_save_text(dd, FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); - - dd_close(dd); -} - /* this is just a workaround until kernel changes it's behavior when handling pipes in core_pattern diff --git a/lib/plugins/CCpp.h b/lib/plugins/CCpp.h index e8040449..dcd80982 100644 --- a/lib/plugins/CCpp.h +++ b/lib/plugins/CCpp.h @@ -42,7 +42,6 @@ class CAnalyzerCCpp : public CAnalyzer public: CAnalyzerCCpp(); virtual std::string GetGlobalUUID(const char *pDebugDumpDir); - virtual void CreateReport(const char *pDebugDumpDir, int force); virtual void Init(); virtual void DeInit(); virtual void SetSettings(const map_plugin_settings_t& pSettings); diff --git a/lib/plugins/Kerneloops.h b/lib/plugins/Kerneloops.h index 10253fe4..af6bef0e 100644 --- a/lib/plugins/Kerneloops.h +++ b/lib/plugins/Kerneloops.h @@ -35,7 +35,6 @@ class CAnalyzerKerneloops : public CAnalyzer { public: virtual std::string GetGlobalUUID(const char *pDebugDumpDir); - virtual void CreateReport(const char *pDebugDumpDir, int force) {} }; #endif diff --git a/lib/plugins/Python.h b/lib/plugins/Python.h index ebb1ec6f..c862ad45 100644 --- a/lib/plugins/Python.h +++ b/lib/plugins/Python.h @@ -27,7 +27,6 @@ class CAnalyzerPython : public CAnalyzer { public: virtual std::string GetGlobalUUID(const char *pDebugDumpDir); - virtual void CreateReport(const char *pDebugDumpDir, int force) {} virtual void Init(); virtual void DeInit(); }; |