diff options
Diffstat (limited to 'lib/Plugins/CCpp.cpp')
| -rw-r--r-- | lib/Plugins/CCpp.cpp | 212 |
1 files changed, 51 insertions, 161 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 3420117..40aadd2 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -87,6 +87,18 @@ static std::string CreateHash(const std::string& pInput) return hash_str; } +static std::string concat_str_vector(char **strings) +{ + std::string result; + while (*strings) + { + result += *strings++; + if (*strings) + result += ' '; + } + return result; +} + static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) { int pipeout[2]; @@ -107,11 +119,7 @@ static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) } if (child == 0) { - VERB1 log("Executing: %s %s %s %s", pArgs[0] - ,pArgs[1] ? pArgs[1] : "" - ,pArgs[1] && pArgs[2] ? pArgs[2] : "" - ,pArgs[1] && pArgs[2] && pArgs[3] ? pArgs[3] : "" - ); + VERB1 log("Executing: %s", concat_str_vector(pArgs).c_str()); close(pipeout[0]); /* read side of the pipe */ xmove_fd(pipeout[1], STDOUT_FILENO); /* Make sure stdin is safely open to nothing */ @@ -164,10 +172,10 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra char* args[9]; args[0] = (char*)"gdb"; args[1] = (char*)"-batch"; - // when/if we'll add support for networked debuginfos + // when/if gdb supports it: // (https://bugzilla.redhat.com/show_bug.cgi?id=528668): - //args[] = (char*)"-ex"; - //args[] = xasprintf("set debug-file-directory %s", dir); + //args[2] = (char*)"-ex"; + //args[3] = "set debug-file-directory /usr/lib/debug/.build-id:/var/cache/abrt-di/usr/lib/debug/.build-id"; /* * Unfortunately, "file BINARY_FILE" doesn't work well if BINARY_FILE * was deleted (as often happens during system updates): @@ -365,75 +373,9 @@ static std::string run_unstrip_n(const std::string& pDebugDumpDir) static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) { - log("Getting module names, file names, build IDs from core file"); - std::string unstrip_list = run_unstrip_n(pDebugDumpDir); - - log("Builting list of missing debuginfos"); - // lines look like this: - // 0x400000+0x209000 23c77451cf6adff77fc1f5ee2a01d75de6511dda@0x40024c - - [exe] - // 0x400000+0x209000 ab3c8286aac6c043fd1bb1cc2a0b88ec29517d3e@0x40024c /bin/sleep /usr/lib/debug/bin/sleep.debug [exe] - // 0x7fff313ff000+0x1000 389c7475e3d5401c55953a425a2042ef62c4c7df@0x7fff313ff2f8 . - linux-vdso.so.1 - vector_string_t missing; - char *dup = xstrdup(unstrip_list.c_str()); - char *p = dup; - char c; - do { - char* end = strchrnul(p, '\n'); - c = *end; - *end = '\0'; - char* word2 = strchr(p, ' '); - if (!word2) - continue; - word2++; - char* endsp = strchr(word2, ' '); - if (!endsp) - continue; - /* endsp points to 2nd space in the line now*/ - - /* This filters out linux-vdso.so, among others */ - if (strstr(endsp, "[exe]") == NULL && endsp[1] != '/') - continue; - *endsp = '\0'; - char* at = strchrnul(word2, '@'); - *at = '\0'; - - bool file_exists = 1; - if (word2[0] && word2[1] && is_hexstr(word2)) - { - struct stat sb; - char *fn = xasprintf("/usr/lib/debug/.build-id/%.2s/%s.debug", word2, word2 + 2); - /* Not lstat: this is a symlink and we want link's TARGET to exist */ - file_exists = stat(fn, &sb) == 0 && S_ISREG(sb.st_mode); - free(fn); - build_ids += "build-id "; - build_ids += word2; - build_ids += file_exists ? " (debuginfo present)\n" : " (debuginfo absent)\n"; - } - log("build_id:%s exists:%d", word2, (int)file_exists); - if (!file_exists) - missing.push_back(word2); - - p = end + 1; - } while (c); - free(dup); - - if (missing.size() == 0) - { - log("All debuginfos are present, not installing debuginfo packages"); - return; - } - //missing vector is unused for now, but TODO: use it to install only needed debuginfos - - std::string package; - { - CDebugDump dd; - dd.Open(pDebugDumpDir); - dd.LoadText(FILENAME_PACKAGE, package); - } - update_client(_("Searching for debug-info packages...")); - int pipein[2], pipeout[2]; + int pipein[2], pipeout[2]; //TODO: get rid of pipein xpipe(pipein); xpipe(pipeout); @@ -454,45 +396,18 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui /*close(STDERR_FILENO);*/ setsid(); -/* Honestly, I do not know what is worse, pk-debuginfo-install or debuginfo-install: - -# pk-debuginfo-install -y -- coreutils-7.2-4.fc11 -1. Getting sources list...OK. Found 16 enabled and 23 disabled sources. -2. Finding debugging sources...OK. Found 0 disabled debuginfo repos. -3. Enabling debugging sources...OK. Enabled 0 debugging sources. -4. Finding debugging packages...Failed to find the package : more than one package found for -Failed to find the package : more than one package found for -FAILED. Found no packages to install. -5. Disabling sources previously enabled...OK. Disabled 0 debugging sources. - -:( FAIL! - -# debuginfo-install -y -- coreutils-7.2-4.fc11 -Loaded plugins: refresh-packagekit -Another application is holding the yum lock, cannot continue -:( FAIL! - -# debuginfo-install -y -- coreutils-7.2-4.fc11 -(second time in a row - it worked) - -*/ + char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + char *tempdir = xasprintf("/tmp/abrt-%u-%lu", (int)getpid(), (long)time(NULL)); /* log() goes to stderr/syslog, it's ok to use it here */ - VERB1 log("Executing: %s %s %s %s", "pk-debuginfo-install", "-y", "--", package.c_str()); - execlp("pk-debuginfo-install", "pk-debuginfo-install", "-y", "--", package.c_str(), NULL); - /* fall back */ - VERB1 log("Executing: %s %s %s %s", "debuginfo-install", "-y", "--", package.c_str()); - execlp("debuginfo-install", "debuginfo-install", "-y", "--", package.c_str(), NULL); + VERB1 log("Executing: %s %s %s %s", "abrt-debuginfo-install", coredump, tempdir, "/"); // "/var/cache/abrt-di" + execlp("abrt-debuginfo-install", "abrt-debuginfo-install", coredump, tempdir, "/", NULL); exit(1); } close(pipein[0]); close(pipeout[1]); - /* Should not be needed (we use -y option), but just in case: */ - safe_write(pipein[1], "y\n", sizeof("y\n")-1); - close(pipein[1]); - update_client(_("Downloading and installing debug-info packages...")); FILE *pipeout_fp = fdopen(pipeout[0], "r"); @@ -503,50 +418,30 @@ Another application is holding the yum lock, cannot continue return; } -/* glx-utils, for example, do not have glx-utils-debuginfo package. - * Disabled code was causing failures in backtrace decoding. - * This does not seem to be useful. - */ -#ifdef COMPLAIN_IF_NO_DEBUGINFO - bool already_installed = false; -#endif char buff[1024]; - std::string packageName = package.substr(0, package.rfind("-", package.rfind("-")-1)); while (fgets(buff, sizeof(buff), pipeout_fp)) { int last = strlen(buff) - 1; if (last >= 0 && buff[last] == '\n') buff[last] = '\0'; - /* log(buff); - update_client logs it too */ - update_client(buff); /* maybe only if buff != ""? */ - -#ifdef COMPLAIN_IF_NO_DEBUGINFO - if (already_installed == false) + if (strncmp(buff, "MISSING:", 8) == 0) { - /* "Package foo-debuginfo-1.2-5.ARCH already installed and latest version" */ - char* pn = strstr(buff, packageName.c_str()); - if (pn) - { - char* already_str = strstr(pn, "already installed and latest version"); - if (already_str) - { - already_installed = true; - } - } + build_ids += "Debuginfo absent: "; + build_ids += buff + 8; + build_ids += "\n"; } - if (already_installed == false && - (strstr(buff, "No debuginfo packages available to install") != NULL || - strstr(buff, "Could not find debuginfo for main pkg") != NULL || - strstr(buff, "Could not find debuginfo pkg for dependency package") != NULL)) + const char *p = buff; + while (*p == ' ' || *p == '\t') { - fclose(pipeout_fp); - kill(child, SIGTERM); - wait(NULL); - throw CABRTException(EXCEP_PLUGIN, std::string(__func__) + ": cannot install debuginfos for " + pPackage); + p++; + } + if (*p) + { + /* log(buff); - update_client logs it too */ + update_client(buff); } -#endif } fclose(pipeout_fp); @@ -592,35 +487,29 @@ std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) static bool DebuginfoCheckPolkit(int uid) { - PolkitResult result; - int child_pid; - - child_pid = fork(); - + int child_pid = fork(); + if (child_pid < 0) + { + perror_msg_and_die("fork"); + } if (child_pid == 0) { //child - setuid(uid); - result = polkit_check_authorization(getpid(), + if (setuid(uid)) + exit(1); //paranoia + PolkitResult result = polkit_check_authorization(getpid(), "org.fedoraproject.abrt.install-debuginfos"); - if (result == PolkitYes) - { - exit(0); //authentication OK - } - exit(1); - } else - { - //parent - int status; - - waitpid(child_pid, &status, 0); - if (WEXITSTATUS(status) == 0) - { - return true; //authentication OK - } - return false; + exit(result != PolkitYes); //exit 1 (failure) if not allowed } + //parent + int status; + if (waitpid(child_pid, &status, 0) > 0 && WEXITSTATUS(status) == 0) + { + return true; //authorization OK + } + log("UID %d is not authorized to install debuginfos", uid); + return false; } void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) @@ -663,6 +552,7 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) dd.Open(pDebugDumpDir); dd.SaveText(FILENAME_BACKTRACE, build_ids + backtrace); +log("BACKTRACE:'%s'", (build_ids + backtrace).c_str()); if (m_bMemoryMap) { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); |
