From 0977486599769b9af8898764e721f213fdd04b62 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Dec 2009 20:56:53 +0100 Subject: abrt-debuginfo-install: better logging Signed-off-by: Denys Vlasenko --- src/Daemon/abrt-debuginfo-install | 52 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Daemon/abrt-debuginfo-install b/src/Daemon/abrt-debuginfo-install index 6278b63..4bb0cfb 100755 --- a/src/Daemon/abrt-debuginfo-install +++ b/src/Daemon/abrt-debuginfo-install @@ -21,8 +21,7 @@ # Output goes to GUI as debuginfo install log. The script should be careful # to give useful, but not overly cluttered info to stdout. # Additionally, abrt daemon handles "MISSING:xxxx" messages specially: -# xxxx will be prepended to backtrace. This is used to inform about -# missing debuginfos. +# it is used to inform about missing debuginfos. # # Exitcodes: # 0 - all debuginfos are installed @@ -64,18 +63,14 @@ debuginfodirs="${3//:/ }" cachedir="${3%%:*}" debug=false -exec 2>&1 -test -f "$core" || exit 2 -# cachedir is optional -test x"$cachedir" = x"" || test -d "$cachedir" || exit 2 -# tempdir must not exist -test -e "$tempdir" && exit 2 - -mkdir -- "$tempdir" || exit 2 -cd "$tempdir" || exit 2 -$debug && echo "Installing rpms to $tempdir" +# stderr may be used for status messages too +exec 2>&1 +error_msg_and_die() { + echo "$*" + exit 2 +} count_words() { echo $# @@ -99,6 +94,7 @@ print_missing_build_ids() { done } +# Note: it is run in `backticks`, use >&2 for error messages print_missing_debuginfos() { local build_id local build_id1 @@ -138,6 +134,7 @@ cleanup_and_report_missing() { } # $1: iteration (1,2...) +# Note: it is run in `backticks`, use >&2 for error messages print_package_names() { # We'll run something like: # yum --enablerepo=*debuginfo* --quiet provides \ @@ -154,8 +151,9 @@ print_package_names() { echo "$cmd" >"yum_provides.$1.OUT" local yum_provides_OUT="`$cmd 2>&1`" local err=$? - printf "%s\nexitcode:%s\n" "$yum_provides_OUT" $err >>"yum_provides.$1.OUT" - test $err = 0 || exit 2 + printf "%s\nyum exitcode:%s\n" "$yum_provides_OUT" $err >>"yum_provides.$1.OUT" + test $err = 0 || error_msg_and_die "yum provides... exited with $err: +`head yum_provides.$1.OUT`" >&2 # The output is pretty machine-unfriendly: # glibc-debuginfo-2.10.90-24.x86_64 : Debug information for package glibc @@ -190,7 +188,7 @@ download_packages() { ##yumdownloader --enablerepo=*debuginfo* --quiet $packages >yumdownloader.OUT 2>&1 ##err=$? ##echo "exitcode:$err" >>yumdownloader.OUT - ##test $err = 0 || exit 2 + ##test $err = 0 || error_msg_and_die ... >yumdownloader.OUT i=1 for pkg in $packages; do @@ -207,7 +205,7 @@ download_packages() { for file in *.rpm; do # Happens if no .rpm's were downloaded (yumdownloader problem) # In this case, $f is the literal "*.rpm" string - test -f "$file" || exit 2 + test -f "$file" || error_msg_and_die "not a rpm file: '$file'" echo "Unpacking: $file" echo "Processing: $file" >>unpack.OUT rpm2cpio <"$file" 2>>unpack.OUT | cpio -id >>unpack.OUT 2>&1 @@ -242,6 +240,18 @@ download_packages() { } +# Sanity checking +test -f "$core" || error_msg_and_die "not a file: '$core'" +# cachedir is optional +test x"$cachedir" = x"" || test -d "$cachedir" || error_msg_and_die "bad cachedir '$cachedir'" +# tempdir must not exist +test -e "$tempdir" && error_msg_and_die "tempdir exists: '$tempdir'" + +mkdir -- "$tempdir" || exit 2 +cd "$tempdir" || exit 2 +$debug && echo "Installing rpms to $tempdir" + + # eu-unstrip output example: # 0x400000+0x209000 23c77451cf6adff77fc1f5ee2a01d75de6511dda@0x40024c - - [exe] # or @@ -254,8 +264,9 @@ echo "Getting list of build IDs" # eu-unstrip: /var/cache/abrt/ccpp-1256301004-2754/coredump: Callback returned failure eu_unstrip_OUT=`eu-unstrip "--core=$core" -n 2>eu_unstrip.ERR` err=$? -printf "%s\nexitcode:%s\n" "$eu_unstrip_OUT" $err >eu_unstrip.OUT -test $err = 0 || exit 2 +printf "%s\neu-unstrip exitcode:%s\n" "$eu_unstrip_OUT" $err >eu_unstrip.OUT +test $err = 0 || error_msg_and_die "eu-unstrip exited with $err: +`head eu_unstrip.OUT`" # Get space-separated list of all build-ids # There can be duplicates (observed in real world) @@ -283,6 +294,8 @@ iter=0 while test $((++iter)) -le 2; do # Analyze $build_ids and check which debuginfos are present missing_debuginfo_files=`print_missing_debuginfos` + # Did print_missing_debuginfos fail? + test $? = 0 || exit 2 $debug && echo "missing_debuginfo_files:$missing_debuginfo_files" test x"$missing_debuginfo_files" = x"" && break @@ -290,6 +303,8 @@ while test $((++iter)) -le 2; do # Map $missing_debuginfo_files to package names. # yum is run here. packages=`print_package_names $iter` + # Did print_package_names fail? + test $? = 0 || exit 2 $debug && echo "packages ($iter):$packages" # yum may return "" here if it found no packages (say, if coredump @@ -304,4 +319,5 @@ done cleanup_and_report_missing test x"$missing_build_ids" != x"" && exit 1 +echo "All needed debuginfos are present" exit 0 -- cgit From 6e933d22b7b1f5a53690d1d5e8ce958c7948093d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Dec 2009 11:10:00 +0100 Subject: applet: reduce blinking time to 30 seconds Signed-off-by: Denys Vlasenko --- src/Applet/CCApplet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp index 5d13ab8..f9212b2 100644 --- a/src/Applet/CCApplet.cpp +++ b/src/Applet/CCApplet.cpp @@ -320,7 +320,7 @@ void CApplet::animate_icon() if (m_iAnimator == 0) { m_iAnimator = g_timeout_add(100, update_icon, this); - m_iAnimCountdown = 10 * 60; /* 60 sec */ + m_iAnimCountdown = 10 * 30; /* 30 sec */ } } -- cgit From 79be794ddb2182a7ce120e98df6cd01f1a188e0a Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 15 Dec 2009 15:46:01 +0100 Subject: GUI: autoscroll log window --- src/Gui/CCMainWindow.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Gui/CCMainWindow.py b/src/Gui/CCMainWindow.py index e429908..8544b24 100644 --- a/src/Gui/CCMainWindow.py +++ b/src/Gui/CCMainWindow.py @@ -167,7 +167,10 @@ class MainWindow(): self.wTree.get_widget("lStatus").set_text(message) buff = gtk.TextBuffer() buff.set_text(self.updates) - self.wTree.get_widget("tvUpdates").set_buffer(buff) + end = buff.get_insert() + tvUpdates = self.wTree.get_widget("tvUpdates") + tvUpdates.set_buffer(buff) + tvUpdates.scroll_mark_onscreen(end) # call to update the progressbar def progress_update_cb(self, *args): -- cgit From dd92fc9b28a88ba47560d923064f88e2e523c505 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 15 Dec 2009 18:01:28 +0100 Subject: don't blame python for every crash in /usr/bin/python rhbz#533521 trac#109 - when there is a bug in 3rd party python extension, the python binary creates the coredump, so ABRT always blames the python package, but we want to blame the app that uses the extension instead --- src/Daemon/MiddleWare.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index b597a41..98feb7b 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -781,6 +781,33 @@ std::string getDebugDumpDir(const char *pUUID, return row.m_sDebugDumpDir; } +static char *guess_app_path(const char* cmdline) +{ + const char *path_start = NULL; + char *app_path = NULL; + // +1 to skip the space + path_start = strchr(cmdline, ' '); + /* we found space in cmdline, so it might contain + path to some script like: + /usr/bin/python /usr/bin/system-control-network + */ + if(path_start != NULL) + { + // skip the space + path_start++; + /* if the string following the space doesn't start + with '/' it's probably not a full path to app and + we can't use it to determine the package name + */ + if(*path_start == '/'){ + int len = strchrnul(path_start,' ') - path_start; + // cut the cmdline arguments + app_path = xstrndup(path_start, len); + } + } + return app_path; +} + mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { @@ -788,6 +815,7 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, std::string time; std::string analyzer; std::string executable; + std::string cmdline; try { CDebugDump dd; @@ -796,6 +824,7 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, dd.LoadText(FILENAME_UID, UID); dd.LoadText(FILENAME_ANALYZER, analyzer); dd.LoadText(FILENAME_EXECUTABLE, executable); + dd.LoadText(FILENAME_CMDLINE, cmdline); } catch (CABRTException& e) { @@ -811,12 +840,31 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, { return MW_IN_DB; } - mw_result_t res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); + /* first try to find package for the application guessed from cmdline + this will work only of the cmdline contains the whole path to the aplication + like: + /usr/bin/python /usr/bin/system-control-network + */ + mw_result_t res = MW_PACKAGE_ERROR; + char *application = guess_app_path(cmdline.c_str()); + if(application != NULL) + { + res = SavePackageDescriptionToDebugDump(application, pDebugDumpDir); + free(application); + } + if(res != MW_OK) + /* we didn't find the package, so the guess was probably wrong + try again with the executable + */ + { + res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); + } if (res != MW_OK) { return res; } + std::string lUUID = GetLocalUUID(analyzer.c_str(), pDebugDumpDir); const char *uid_str = analyzer_has_InformAllUsers(analyzer.c_str()) ? "-1" -- cgit From 060f38febbd01f1bb7e343bb33c85ff0aa0f30cd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Dec 2009 18:05:51 +0100 Subject: move misplaced comment Signed-off-by: Denys Vlasenko --- src/Daemon/MiddleWare.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index 98feb7b..eb60ce4 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -783,23 +783,24 @@ std::string getDebugDumpDir(const char *pUUID, static char *guess_app_path(const char* cmdline) { - const char *path_start = NULL; + const char *path_start; char *app_path = NULL; - // +1 to skip the space + path_start = strchr(cmdline, ' '); - /* we found space in cmdline, so it might contain - path to some script like: - /usr/bin/python /usr/bin/system-control-network - */ - if(path_start != NULL) + if (path_start != NULL) { - // skip the space + /* we found space in cmdline, so it might contain + path to some script like: + /usr/bin/python /usr/bin/system-control-network + */ + /* +1 to skip the space */ path_start++; /* if the string following the space doesn't start with '/' it's probably not a full path to app and we can't use it to determine the package name */ - if(*path_start == '/'){ + if (*path_start == '/') + { int len = strchrnul(path_start,' ') - path_start; // cut the cmdline arguments app_path = xstrndup(path_start, len); -- cgit From 1e119f37b85b90c5a9a17fdcbc80625727b4ab66 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Dec 2009 19:54:51 +0100 Subject: fix all instances of atoi() usage Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 6 +++--- src/Daemon/MiddleWare.cpp | 2 +- src/Daemon/PluginManager.cpp | 6 +++--- src/Daemon/Settings.cpp | 2 +- src/Hooks/CCpp.cpp | 27 ++++++++++++++------------- 5 files changed, 22 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 153363d..db55f84 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -216,14 +216,14 @@ static int SetUpCron() std::string sM = ""; sH = it_c->first.substr(0, pos); - nH = atoi(sH.c_str()); + nH = xatou(sH.c_str()); nH = nH > 23 ? 23 : nH; nH = nH < 0 ? 0 : nH; nM = nM > 59 ? 59 : nM; nM = nM < 0 ? 0 : nM; timeout += nH * 60 * 60; sM = it_c->first.substr(pos + 1); - nM = atoi(sM.c_str()); + nM = xatou(sM.c_str()); timeout += nM * 60; } else @@ -231,7 +231,7 @@ static int SetUpCron() std::string sS = ""; sS = it_c->first; - nS = atoi(sS.c_str()); + nS = xatou(sS.c_str()); nS = nS <= 0 ? 1 : nS; timeout = nS; } diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index eb60ce4..fd2e86b 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -477,7 +477,7 @@ report_status_t Report(const map_crash_report_t& pCrashReport, if (pUID != "") { - home = get_home_dir(atoi(pUID.c_str())); + home = get_home_dir(xatoi_u(pUID.c_str())); if (home != "") { oldSettings = reporter->GetSettings(); diff --git a/src/Daemon/PluginManager.cpp b/src/Daemon/PluginManager.cpp index 82f22e8..b6a8b15 100644 --- a/src/Daemon/PluginManager.cpp +++ b/src/Daemon/PluginManager.cpp @@ -391,7 +391,7 @@ void CPluginManager::SetPluginSettings(const char *pName, return; } - std::string home = get_home_dir(atoi(pUID.c_str())); + std::string home = get_home_dir(xatoi_u(pUID.c_str())); if (home == "") { return; @@ -399,7 +399,7 @@ void CPluginManager::SetPluginSettings(const char *pName, std::string confDir = home + "/.abrt"; std::string confPath = confDir + "/" + pName + "."PLUGINS_CONF_EXTENSION; - uid_t uid = atoi(pUID.c_str()); + uid_t uid = xatoi_u(pUID.c_str()); struct passwd* pw = getpwuid(uid); gid_t gid = pw ? pw->pw_gid : uid; @@ -461,7 +461,7 @@ map_plugin_settings_t CPluginManager::GetPluginSettings(const char *pName, /* if (abrt_plugin->second->GetType() == REPORTER) { - std::string home = get_home_dir(atoi(pUID.c_str())); + std::string home = get_home_dir(xatoi_u(pUID.c_str())); if (home != "") { LoadPluginSettings(home + "/.abrt/" + pName + "."PLUGINS_CONF_EXTENSION, ret); diff --git a/src/Daemon/Settings.cpp b/src/Daemon/Settings.cpp index 327851f..d89bebf 100644 --- a/src/Daemon/Settings.cpp +++ b/src/Daemon/Settings.cpp @@ -176,7 +176,7 @@ static void ParseCommon() it = s_mapSectionCommon.find("MaxCrashReportsSize"); if (it != end) { - g_settings_nMaxCrashReportsSize = atoi(it->second.c_str()); + g_settings_nMaxCrashReportsSize = xatoi_u(it->second.c_str()); } it = s_mapSectionCommon.find("ActionsAndReporters"); if (it != end) diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index fd789cf..e38c4f7 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -202,25 +202,26 @@ int main(int argc, char** argv) logmode = LOGMODE_SYSLOG; const char* dddir = argv[1]; - pid_t pid = atoi(argv[2]); + pid_t pid = xatoi_u(argv[2]); const char* signal_str = argv[3]; - int signal = atoi(argv[3]); - uid_t uid = atoi(argv[4]); - - if (signal != SIGQUIT - && signal != SIGILL - && signal != SIGABRT - && signal != SIGFPE - && signal != SIGSEGV + int signal_no = xatoi_u(argv[3]); + uid_t uid = xatoi_u(argv[4]); + + if (signal_no != SIGQUIT + && signal_no != SIGILL + && signal_no != SIGABRT + && signal_no != SIGFPE + && signal_no != SIGSEGV ) { /* not an error, exit silently */ return 0; } - if (pid <= 0 || (int)uid < 0) + if (pid <= 0) { - error_msg_and_die("pid '%s' or uid '%s' are bogus", argv[2], argv[4]); + error_msg_and_die("pid '%s' is bogus", argv[2]); } + char *user_pwd = get_cwd(pid); /* may be NULL on error */ int core_fd = STDIN_FILENO; @@ -299,7 +300,7 @@ int main(int argc, char** argv) } char* cmdline = get_cmdline(pid); /* never NULL */ - const char *signame = strsignal(atoi(signal_str)); + const char *signame = strsignal(signal_no); char *reason = xasprintf("Process was terminated by signal %s (%s)", signal_str, signame ? signame : signal_str); snprintf(path, sizeof(path), "%s/ccpp-%ld-%u", dddir, (long)time(NULL), (int)pid); @@ -388,7 +389,7 @@ int main(int argc, char** argv) if (isdigit(*p)) /* x1.25: go a bit up, so that usual in-daemon trimming * kicks in first, and we don't "fight" with it. */ - setting_MaxCrashReportsSize = (unsigned long)atoi(p) * 5 / 4; + setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4; continue; } #undef DIRECTIVE -- cgit From 707f64b85c8a1b88923617ff72bd8a4ca562f3bd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Dec 2009 15:09:55 +0100 Subject: prevent destructors from throwing exceptions; check curl_easy_init errors Signed-off-by: Denys Vlasenko --- src/CLI/ABRTSocket.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/CLI/ABRTSocket.cpp b/src/CLI/ABRTSocket.cpp index d31c7a4..1353134 100644 --- a/src/CLI/ABRTSocket.cpp +++ b/src/CLI/ABRTSocket.cpp @@ -13,7 +13,17 @@ CABRTSocket::CABRTSocket() : m_nSocket(-1) CABRTSocket::~CABRTSocket() { - Disconnect(); + /* Paranoia. In C++, destructor will abort() if it was called while unwinding + * the stack and it throws an exception. + */ + try + { + Disconnect(); + } + catch (...) + { + error_msg_and_die("Internal error"); + } } void CABRTSocket::Send(const std::string& pMessage) -- cgit From 65f8b90b01693e467359b7258d98ac64d7807c3f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Dec 2009 16:10:12 +0100 Subject: change "python /path/to/script" code a bit: doesnt log false failures now Signed-off-by: Denys Vlasenko --- src/Daemon/MiddleWare.cpp | 120 ++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index fd2e86b..6b8bfcc 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -563,11 +563,38 @@ void LoadOpenGPGPublicKey(const char* key) * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return It return results of operation. See mw_result_t. */ -static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, - const char *pDebugDumpDir) +static char *get_argv1_if_full_path(const char* cmdline) +{ + char *argv1 = (char*) strchr(cmdline, ' '); + if (argv1 != NULL) + { + /* we found space in cmdline, so it might contain + * path to some script like: + * /usr/bin/python /usr/bin/system-control-network + */ + argv1++; + /* if the string following the space doesn't start + * with '/' it's probably not a full path to script + * and we can't use it to determine the package name + */ + if (*argv1 != '/') + { + return NULL; + } + int len = strchrnul(argv1, ' ') - argv1; + /* cut the cmdline arguments */ + argv1 = xstrndup(argv1, len); + } + return argv1; +} +static mw_result_t SavePackageDescriptionToDebugDump( + const char *pExecutable, + const char *cmdline, + const char *pDebugDumpDir) { std::string package; std::string packageName; + std::string scriptName; /* only if "interpreter /path/to/script" */ if (strcmp(pExecutable, "kernel") == 0) { @@ -582,6 +609,42 @@ static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, return MW_PACKAGE_ERROR; } + /* Check well-known interpreter names */ + + const char *basename = strrchr(pExecutable, '/'); + if (basename) basename++; else basename = pExecutable; + + /* Add "perl" and such as needed */ + if (strcmp(basename, "python") == 0) + { +// TODO: we don't verify that python executable is not modified +// or that python package is properly signed +// (see CheckFingerprint/CheckHash below) + + /* Try to find package for the script by looking at argv[1]. + * This will work only of the cmdline contains the whole path. + * Example: python /usr/bin/system-control-network + */ + char *script_name = get_argv1_if_full_path(cmdline); + if (script_name) + { + char *script_pkg = GetPackage(script_name); + if (script_pkg) + { + /* There is a well-formed script name in argv[1], + * and it does belong to some package. + * Replace interpreter's rpm_pkg and pExecutable + * with data pertaining to the script. + */ + free(rpm_pkg); + rpm_pkg = script_pkg; + scriptName = script_name; + pExecutable = scriptName.c_str(); + } + free(script_name); + } + } + package = rpm_pkg; packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1)); VERB2 log("Package:'%s' short:'%s'", rpm_pkg, packageName.c_str()); @@ -610,10 +673,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, } std::string description = GetDescription(packageName.c_str()); -//TODO: if executable in /usr/bin/python, /bin/sh and such, -//we need to extract component using argv[1] std::string component = GetComponent(pExecutable); - try { CDebugDump dd; @@ -781,34 +841,6 @@ std::string getDebugDumpDir(const char *pUUID, return row.m_sDebugDumpDir; } -static char *guess_app_path(const char* cmdline) -{ - const char *path_start; - char *app_path = NULL; - - path_start = strchr(cmdline, ' '); - if (path_start != NULL) - { - /* we found space in cmdline, so it might contain - path to some script like: - /usr/bin/python /usr/bin/system-control-network - */ - /* +1 to skip the space */ - path_start++; - /* if the string following the space doesn't start - with '/' it's probably not a full path to app and - we can't use it to determine the package name - */ - if (*path_start == '/') - { - int len = strchrnul(path_start,' ') - path_start; - // cut the cmdline arguments - app_path = xstrndup(path_start, len); - } - } - return app_path; -} - mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { @@ -841,31 +873,13 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, { return MW_IN_DB; } - /* first try to find package for the application guessed from cmdline - this will work only of the cmdline contains the whole path to the aplication - like: - /usr/bin/python /usr/bin/system-control-network - */ - mw_result_t res = MW_PACKAGE_ERROR; - char *application = guess_app_path(cmdline.c_str()); - if(application != NULL) - { - res = SavePackageDescriptionToDebugDump(application, pDebugDumpDir); - free(application); - } - if(res != MW_OK) - /* we didn't find the package, so the guess was probably wrong - try again with the executable - */ - { - res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); - } + + mw_result_t res = SavePackageDescriptionToDebugDump(executable.c_str(), cmdline.c_str(), pDebugDumpDir); if (res != MW_OK) { return res; } - std::string lUUID = GetLocalUUID(analyzer.c_str(), pDebugDumpDir); const char *uid_str = analyzer_has_InformAllUsers(analyzer.c_str()) ? "-1" -- cgit From 687be490d8092842f9a016132a4204023d9b8d6e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Dec 2009 19:22:00 +0100 Subject: src/Hooks/CCpp.cpp: use and honour %c (core limit size). Makes MakeCompatCore = yes much more frielndly - now users with ulimit -c 0 won't get unwanted coredumps. Signed-off-by: Denys Vlasenko --- src/Hooks/CCpp.cpp | 171 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 73 deletions(-) (limited to 'src') diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index e38c4f7..7a348e5 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -194,19 +194,26 @@ int main(int argc, char** argv) struct stat sb; const char* program_name = argv[0]; - if (argc < 4) + if (argc < 5) { - error_msg_and_die("Usage: %s: ", program_name); + error_msg_and_die("Usage: %s: DUMPDIR PID SIGNO UID CORE_SIZE_LIMIT", program_name); } openlog("abrt", 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; + errno = 0; const char* dddir = argv[1]; pid_t pid = xatoi_u(argv[2]); const char* signal_str = argv[3]; int signal_no = xatoi_u(argv[3]); uid_t uid = xatoi_u(argv[4]); + off_t ulimit_c = strtoull(argv[5], NULL, 10); + off_t core_size = 0; + if (errno || pid <= 0 || ulimit_c < 0) + { + error_msg_and_die("pid '%s' or limit '%s' is bogus", argv[2], argv[5]); + } if (signal_no != SIGQUIT && signal_no != SIGILL && signal_no != SIGABRT @@ -216,10 +223,6 @@ int main(int argc, char** argv) /* not an error, exit silently */ return 0; } - if (pid <= 0) - { - error_msg_and_die("pid '%s' is bogus", argv[2]); - } char *user_pwd = get_cwd(pid); /* may be NULL on error */ @@ -248,6 +251,65 @@ int main(int argc, char** argv) (int)pid, executable); } + /* Parse abrt.conf and plugins/CCpp.conf */ + unsigned setting_MaxCrashReportsSize = 0; + bool setting_MakeCompatCore = false; + bool abrt_conf = true; + FILE *fp = fopen(CONF_DIR"/abrt.conf", "r"); + if (fp) + { + char line[256]; + while (1) + { + if (fgets(line, sizeof(line), fp) == NULL) + { + /* Next .conf file plz */ + if (abrt_conf) + { + abrt_conf = false; + fp = fopen(CONF_DIR"/plugins/CCpp.conf", "r"); + if (fp) + continue; + } + break; + } + + unsigned len = strlen(line); + if (len > 0 && line[len-1] == '\n') + line[--len] = '\0'; + const char *p = skip_whitespace(line); +#undef DIRECTIVE +#define DIRECTIVE "MaxCrashReportsSize" + if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) + { + p = skip_whitespace(p + sizeof(DIRECTIVE)-1); + if (*p != '=') + continue; + p = skip_whitespace(p + 1); + if (isdigit(*p)) + /* x1.25: go a bit up, so that usual in-daemon trimming + * kicks in first, and we don't "fight" with it. */ + setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4; + continue; + } +#undef DIRECTIVE +#define DIRECTIVE "MakeCompatCore" + if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) + { + p = skip_whitespace(p + sizeof(DIRECTIVE)-1); + if (*p != '=') + continue; + p = skip_whitespace(p + 1); + setting_MakeCompatCore = string_to_bool(p); + continue; + } +#undef DIRECTIVE + /* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */ + } + fclose(fp); + } + + char path[PATH_MAX]; /* Check /var/cache/abrt/last-ccpp marker, do not dump repeated crashes @@ -268,7 +330,12 @@ int main(int argc, char** argv) { path[sz] = '\0'; if (strcmp(executable, path) == 0) - error_msg_and_die("not dumping repeating crash in '%s'", executable); + { + error_msg("not dumping repeating crash in '%s'", executable); + if (setting_MakeCompatCore) + goto create_user_core; + return 1; + } } lseek(fd, 0, SEEK_SET); } @@ -287,15 +354,15 @@ int main(int argc, char** argv) */ snprintf(path, sizeof(path), "%s/abrtd-coredump", dddir); core_fd = xopen3(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - off_t size = copyfd_eof(STDIN_FILENO, core_fd); - if (size < 0 || close(core_fd) != 0) + core_size = copyfd_eof(STDIN_FILENO, core_fd); + if (core_size < 0 || close(core_fd) != 0) { unlink(path); /* copyfd_eof logs the error including errno string, * but it does not log file name */ error_msg_and_die("error saving coredump to %s", path); } - log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)size); + log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)core_size); return 0; } @@ -326,8 +393,8 @@ int main(int argc, char** argv) dd.Close(); perror_msg_and_die("can't open '%s'", path); } - off_t size = copyfd_eof(STDIN_FILENO, core_fd); - if (size < 0 || fsync(core_fd) != 0) + core_size = copyfd_eof(STDIN_FILENO, core_fd); + if (core_size < 0 || fsync(core_fd) != 0) { unlink(path); dd.Delete(); @@ -338,7 +405,7 @@ int main(int argc, char** argv) } lseek(core_fd, 0, SEEK_SET); /* note: core_fd is still open, we may use it later to copy core to user's dir */ - log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)size); + log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)core_size); free(executable); free(cmdline); path[len] = '\0'; /* path now contains directory name */ @@ -351,64 +418,6 @@ int main(int argc, char** argv) */ dd.Close(); - /* Parse abrt.conf and plugins/CCpp.conf */ - unsigned setting_MaxCrashReportsSize = 0; - bool setting_MakeCompatCore = false; - bool abrt_conf = true; - FILE *fp = fopen(CONF_DIR"/abrt.conf", "r"); - if (fp) - { - char line[256]; - while (1) - { - if (fgets(line, sizeof(line), fp) == NULL) - { - /* Next .conf file plz */ - if (abrt_conf) - { - abrt_conf = false; - fp = fopen(CONF_DIR"/plugins/CCpp.conf", "r"); - if (fp) - continue; - } - break; - } - - unsigned len = strlen(line); - if (len > 0 && line[len-1] == '\n') - line[--len] = '\0'; - const char *p = skip_whitespace(line); -#undef DIRECTIVE -#define DIRECTIVE "MaxCrashReportsSize" - if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) - { - p = skip_whitespace(p + sizeof(DIRECTIVE)-1); - if (*p != '=') - continue; - p = skip_whitespace(p + 1); - if (isdigit(*p)) - /* x1.25: go a bit up, so that usual in-daemon trimming - * kicks in first, and we don't "fight" with it. */ - setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4; - continue; - } -#undef DIRECTIVE -#define DIRECTIVE "MakeCompatCore" - if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) - { - p = skip_whitespace(p + sizeof(DIRECTIVE)-1); - if (*p != '=') - continue; - p = skip_whitespace(p + 1); - setting_MakeCompatCore = string_to_bool(p); - continue; - } -#undef DIRECTIVE - /* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */ - } - fclose(fp); - } - /* rhbz#539551: "abrt going crazy when crashing process is respawned". * Do we want to protect against or ameliorate this? How? Ideas: * (1) nice ourself? @@ -448,7 +457,12 @@ int main(int argc, char** argv) error_msg_and_die("%s", e.what()); } + create_user_core: + /* note: core_size may be == 0 ("unknown") */ + if (core_size > ulimit_c || ulimit_c == 0) + return 0; + /* Write a core file for user */ struct passwd* pw = getpwuid(uid); @@ -521,8 +535,10 @@ int main(int argc, char** argv) perror_msg_and_die("%s/%s is not a regular file with link count 1", user_pwd, core_basename); } + /* Note: we do not copy more than ulimit_c */ + off_t size; if (ftruncate(usercore_fd, 0) != 0 - || copyfd_eof(core_fd, usercore_fd) < 0 + || (size = copyfd_size(core_fd, usercore_fd, ulimit_c)) < 0 || close(usercore_fd) != 0 ) { /* perror first, otherwise unlink may trash errno */ @@ -530,7 +546,16 @@ int main(int argc, char** argv) unlink(core_basename); return 1; } - log("saved core dump of pid %u to %s/%s", (int)pid, user_pwd, core_basename); + if (size == ulimit_c && size != core_size) + { + /* We copied exactly ulimit_c bytes (and it doesn't accidentally match + * core_size (imagine exactly 1MB coredump with "ulimit -c 1M" - that'd be ok)), + * it means that core is larger than ulimit_c. Abort and delete the dump. + */ + unlink(core_basename); + return 1; + } + log("saved core dump of pid %u to %s/%s (%llu bytes)", (int)pid, user_pwd, core_basename, (long long)size); return 0; } -- cgit From 480a51ae268f32d61b6c32afa8ba92ec56f512d9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Dec 2009 12:54:49 +0100 Subject: remove unsafe log() from signal handler Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index db55f84..8c7d009 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -400,7 +400,8 @@ static int Lock() static void handle_fatal_signal(int signo) { s_sig_caught = signo; - VERB3 log("Got signal %d", signo); + // Enable for debug only, malloc & printf are unsafe in signal handlers + //VERB3 log("Got signal %d", signo); if (s_signal_pipe_write >= 0) write(s_signal_pipe_write, &s_sig_caught, 1); } -- cgit From 1341f0c56cf70700e997075239b8ad7f108a611f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Dec 2009 13:54:23 +0100 Subject: further robustification of signal handler Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 8c7d009..5c1a7ac 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -399,11 +399,15 @@ static int Lock() static void handle_fatal_signal(int signo) { - s_sig_caught = signo; - // Enable for debug only, malloc & printf are unsafe in signal handlers + // Enable for debugging only, malloc/printf are unsafe in signal handlers //VERB3 log("Got signal %d", signo); + + uint8_t l_sig_caught; + s_sig_caught = l_sig_caught = signo; + /* Using local copy of s_sig_caught so that concurrent signal + * won't change it under us */ if (s_signal_pipe_write >= 0) - write(s_signal_pipe_write, &s_sig_caught, 1); + write(s_signal_pipe_write, &l_sig_caught, 1); } /* Signal pipe handler */ -- cgit From 21055615d919f784bef19df8956a67b577339162 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Dec 2009 16:11:23 +0100 Subject: delete obsolete comment from abrt-debuginfo-install Signed-off-by: Denys Vlasenko --- src/Daemon/abrt-debuginfo-install | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Daemon/abrt-debuginfo-install b/src/Daemon/abrt-debuginfo-install index 4bb0cfb..f7de842 100755 --- a/src/Daemon/abrt-debuginfo-install +++ b/src/Daemon/abrt-debuginfo-install @@ -45,20 +45,10 @@ # For better debuggability, eu_unstrip.OUT, yum_provides.OUT etc files # are saved in TEMPDIR, and TEMPDIR is not deleted if we exit with exitcode 2 # ("serious problem"). -# -# In the future, we may want to use a separate CACHEDIR (say, /var/cache/abrt-di) -# and use it with this gdb command: -# set debug-file-directory /usr/lib/debug/.build-id:CACHEDIR/usr/lib/debug/.build-id -# but current gdb can't handle DIR1:DIR2. -# So, currently we are called with CACHEDIR set to "/", and don't pass -# "set debug-file-directory" to gdb. -# This is ugly, since it messes up /usr/lib/debug/.build-id over time -# by piling up debuginfos there without any means to control their amount, -# but it's the only way to make it work with current gdb. - - -core=$1 -tempdir=$2 + + +core="$1" +tempdir="$2" debuginfodirs="${3//:/ }" cachedir="${3%%:*}" debug=false -- cgit From ae7218acd55d77d47d4631d58818af9f9986de85 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Dec 2009 16:40:07 +0100 Subject: abrt-debuginfo-install: fixes for runs w/o cachedir Signed-off-by: Denys Vlasenko --- src/Daemon/abrt-debuginfo-install | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/Daemon/abrt-debuginfo-install b/src/Daemon/abrt-debuginfo-install index f7de842..dcd3add 100755 --- a/src/Daemon/abrt-debuginfo-install +++ b/src/Daemon/abrt-debuginfo-install @@ -77,6 +77,9 @@ print_missing_build_ids() { build_id2=${build_id:2} file="usr/lib/debug/.build-id/$build_id1/$build_id2.debug" test -f "/$file" && continue + # On 2nd pass, we may already have some debuginfos in tempdir + test -f "$tempdir/$file" && continue + # Check cachedir if we have one for d in $debuginfodirs; do test -f "$d/$file" && continue 2 done @@ -96,6 +99,9 @@ print_missing_debuginfos() { build_id2=${build_id:2} file="usr/lib/debug/.build-id/$build_id1/$build_id2.debug" test -f "/$file" && continue + # On 2nd pass, we may already have some debuginfos in tempdir + test -f "$tempdir/$file" && continue + # Check cachedir if we have one if test x"$cachedir" != x""; then for d in $debuginfodirs; do test -f "$d/$file" && continue 2 @@ -199,6 +205,7 @@ download_packages() { echo "Unpacking: $file" echo "Processing: $file" >>unpack.OUT rpm2cpio <"$file" 2>>unpack.OUT | cpio -id >>unpack.OUT 2>&1 +#TODO: error check? done # Copy debuginfo files to cachedir @@ -223,6 +230,7 @@ download_packages() { # Note: this does not preserve symlinks. This is intentional $debug && echo Copying "$file" to "$cachedir/$file" >&2 cp --remove-destination "$file" "$cachedir/$file" +#TODO: error check? continue fi done @@ -256,6 +264,7 @@ eu_unstrip_OUT=`eu-unstrip "--core=$core" -n 2>eu_unstrip.ERR` err=$? printf "%s\neu-unstrip exitcode:%s\n" "$eu_unstrip_OUT" $err >eu_unstrip.OUT test $err = 0 || error_msg_and_die "eu-unstrip exited with $err: +`cat eu_unstrip.ERR` `head eu_unstrip.OUT`" # Get space-separated list of all build-ids -- cgit From 2adefe9ca05ec2854450cf5875a8e57159e6953f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Dec 2009 18:08:30 +0100 Subject: made s_signal_caught volatile Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 5c1a7ac..1e934bc 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -110,7 +110,7 @@ typedef struct cron_callback_data_t } cron_callback_data_t; -static uint8_t s_sig_caught; /* must be one byte */ +static volatile sig_atomic_t s_sig_caught; static int s_signal_pipe[2]; static int s_signal_pipe_write = -1; static unsigned s_timeout; -- cgit From c1766c339b99aa157c589a7e661b2fe3bd04501d Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Fri, 18 Dec 2009 16:56:12 +0100 Subject: large file support for whole abrt --- src/Hooks/CCpp.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src') diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index 7a348e5..a2db2ec 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -18,14 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - -/* Make all file ops "large" and make off_t 64-bit. - * No need to use O_LARGEFILE anywhere - */ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - #include "abrtlib.h" #include "DebugDump.h" #include "ABRTException.h" -- cgit From f0fe841b0f257ee288b6b88a32597a6282952d34 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Fri, 18 Dec 2009 17:03:20 +0100 Subject: moved get_cmdline() and daemon_is_ok() to abrtlib --- src/Hooks/CCpp.cpp | 122 ----------------------------------------------------- 1 file changed, 122 deletions(-) (limited to 'src') diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index a2db2ec..3a13358 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -24,11 +24,8 @@ #include #define FILENAME_EXECUTABLE "executable" -#define FILENAME_CMDLINE "cmdline" #define FILENAME_COREDUMP "coredump" -#define VAR_RUN_PID_FILE VAR_RUN"/abrt.pid" - using namespace std; static char* malloc_readlink(const char *linkname) @@ -61,125 +58,6 @@ static char* get_cwd(pid_t pid) return malloc_readlink(buf); } -static char *append_escaped(char *start, const char *s) -{ - char hex_char_buf[] = "\\x00"; - - *start++ = ' '; - char *dst = start; - const unsigned char *p = (unsigned char *)s; - - while (1) - { - const unsigned char *old_p = p; - while (*p > ' ' && *p <= 0x7e && *p != '\"' && *p != '\'' && *p != '\\') - p++; - if (dst == start) - { - if (p != (unsigned char *)s && *p == '\0') - { - /* entire word does not need escaping and quoting */ - strcpy(dst, s); - dst += strlen(s); - return dst; - } - *dst++ = '\''; - } - - strncpy(dst, s, (p - old_p)); - dst += (p - old_p); - - if (*p == '\0') - { - *dst++ = '\''; - *dst = '\0'; - return dst; - } - const char *a; - switch (*p) - { - case '\r': a = "\\r"; break; - case '\n': a = "\\n"; break; - case '\t': a = "\\t"; break; - case '\'': a = "\\\'"; break; - case '\"': a = "\\\""; break; - case '\\': a = "\\\\"; break; - case ' ': a = " "; break; - default: - hex_char_buf[2] = "0123456789abcdef"[*p >> 4]; - hex_char_buf[3] = "0123456789abcdef"[*p & 0xf]; - a = hex_char_buf; - } - strcpy(dst, a); - dst += strlen(a); - p++; - } -} - -// taken from kernel -#define COMMAND_LINE_SIZE 2048 -static char* get_cmdline(pid_t pid) -{ - char path[sizeof("/proc/%u/cmdline") + sizeof(int)*3]; - char cmdline[COMMAND_LINE_SIZE]; - char escaped_cmdline[COMMAND_LINE_SIZE*4 + 4]; - - escaped_cmdline[1] = '\0'; - sprintf(path, "/proc/%u/cmdline", (int)pid); - int fd = open(path, O_RDONLY); - if (fd >= 0) - { - int len = read(fd, cmdline, sizeof(cmdline) - 1); - close(fd); - - if (len > 0) - { - cmdline[len] = '\0'; - char *src = cmdline; - char *dst = escaped_cmdline; - while ((src - cmdline) < len) - { - dst = append_escaped(dst, src); - src += strlen(src) + 1; - } - } - } - - return xstrdup(escaped_cmdline + 1); /* +1 skips extraneous leading space */ -} - -static int daemon_is_ok() -{ - int fd = open(VAR_RUN_PID_FILE, O_RDONLY); - if (fd < 0) - { - return 0; - } - - char pid[sizeof(pid_t)*3 + 2]; - int len = read(fd, pid, sizeof(pid)-1); - close(fd); - if (len <= 0) - return 0; - - pid[len] = '\0'; - *strchrnul(pid, '\n') = '\0'; - /* paranoia: we don't want to check /proc//stat or /proc///stat */ - if (pid[0] == '\0' || pid[0] == '/') - return 0; - - /* TODO: maybe readlink and check that it is "xxx/abrt"? */ - char path[sizeof("/proc/%s/stat") + sizeof(pid)]; - sprintf(path, "/proc/%s/stat", pid); - struct stat sb; - if (stat(path, &sb) == -1) - { - return 0; - } - - return 1; -} - int main(int argc, char** argv) { int fd; -- cgit From 46b2fb8df8d4e025f5bbdd9f53be1f658a9e82c6 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Fri, 18 Dec 2009 17:09:33 +0100 Subject: cmdline and daemon checking is done by abrt-python-hook --- src/Hooks/abrt-hook-python.cpp | 20 ++++++++-------- src/Hooks/abrt_exception_handler.py.in | 1 - src/Hooks/sitecustomize.py | 42 ++++------------------------------ 3 files changed, 16 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/Hooks/abrt-hook-python.cpp b/src/Hooks/abrt-hook-python.cpp index cd17e40..3f79d28 100644 --- a/src/Hooks/abrt-hook-python.cpp +++ b/src/Hooks/abrt-hook-python.cpp @@ -34,21 +34,23 @@ static char *pid; static char *executable; static char *uuid; -static char *cmdline; int main(int argc, char** argv) { + // Error if daemon is not running. + if (!daemon_is_ok()) + error_msg_and_die("Daemon is not running."); + // 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' }, { 0 }, }; int opt; - while ((opt = getopt_long(argc, argv, "p:e:u:c:l:", longopts, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "p:e:u:l:", longopts, NULL)) != -1) { switch (opt) { @@ -61,9 +63,6 @@ int main(int argc, char** argv) case 'u': uuid = optarg; break; - case 'c': - cmdline = optarg; - break; default: usage: error_msg_and_die( @@ -72,7 +71,6 @@ int main(int argc, char** argv) " -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" ); } } @@ -103,8 +101,12 @@ int main(int argc, char** argv) dd.SaveText(FILENAME_ANALYZER, "Python"); if (executable) dd.SaveText(FILENAME_EXECUTABLE, executable); - if (cmdline) - dd.SaveText("cmdline", cmdline); + + pid_t pidt = xatoi(pid); + char *cmdline = get_cmdline(pidt); + dd.SaveText("cmdline", cmdline); + free(cmdline); + if (uuid) dd.SaveText("uuid", uuid); diff --git a/src/Hooks/abrt_exception_handler.py.in b/src/Hooks/abrt_exception_handler.py.in index b5ec35f..a0b0519 100644 --- a/src/Hooks/abrt_exception_handler.py.in +++ b/src/Hooks/abrt_exception_handler.py.in @@ -111,7 +111,6 @@ def write_dump(pid, tb_uuid, tb): command.append("--pid=%s" % pid) command.append("--executable=%s" % executable) command.append("--uuid=%s" % tb_uuid) - command.append("--cmdline=%s" % open("/proc/%s/cmdline" % pid).read().replace('\x00',' ')) helper = subprocess.Popen(command, stdin=subprocess.PIPE) helper.communicate(tb) diff --git a/src/Hooks/sitecustomize.py b/src/Hooks/sitecustomize.py index 8027726..1a01574 100644 --- a/src/Hooks/sitecustomize.py +++ b/src/Hooks/sitecustomize.py @@ -5,41 +5,9 @@ # and python interpreter runs it automatically everytime # some python script is executed. -def abrt_daemon_ok(): - try: - #FIXME: make it relocable! this will work only when installed in default path - #pidfile = open(VAR_RUN_PID_FILE, "r"); - pidfile = open("/var/run/abrt.pid", "r") - except Exception, ex: - # log the exception? - return False - - pid = pidfile.readline() - pidfile.close() - if not pid: - return False - - try: - # pid[:-1] strips the trailing '\n' - cmdline = open("/proc/%s/cmdline" % pid[:-1], "r").readline() - except Exception, ex: - # can't read cmdline - return False - if not ("abrtd" in cmdline): - return False - - return True - -if abrt_daemon_ok(): - # Prevent abrt exception handler from running when the abrtd daemon is - # not active. - try: - from abrt_exception_handler import installExceptionHandler - - installExceptionHandler(debug = 1) - except Exception, e: - # FIXME: log errors? - pass -else: - #FIXME: log something? +try: + from abrt_exception_handler import installExceptionHandler + installExceptionHandler(debug = 1) +except Exception, e: + # FIXME: log errors? pass -- cgit