summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-04-22 02:38:45 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2011-04-22 02:38:45 +0200
commit345d57bc15bb90fe5f7db6d6a3d6898794682d36 (patch)
tree98c49615be0de1b3f2c4a5ac64d22886038049a2 /src
parent4b3cb55883bfcb90002da0c21a8c39ac79843b92 (diff)
downloadabrt-345d57bc15bb90fe5f7db6d6a3d6898794682d36.tar.gz
abrt-345d57bc15bb90fe5f7db6d6a3d6898794682d36.tar.xz
abrt-345d57bc15bb90fe5f7db6d6a3d6898794682d36.zip
Make abrt-action-list-dsos.py take -m maps -o dsos params; and abrt-action-analyze-core.py to take -o build_ids param
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/plugins/abrt-action-analyze-core.py124
-rwxr-xr-xsrc/plugins/abrt-action-install-debuginfo.py13
-rwxr-xr-xsrc/plugins/abrt-action-list-dsos.py100
-rw-r--r--src/plugins/ccpp_events.conf6
4 files changed, 158 insertions, 85 deletions
diff --git a/src/plugins/abrt-action-analyze-core.py b/src/plugins/abrt-action-analyze-core.py
index 8de79203..ae344681 100755
--- a/src/plugins/abrt-action-analyze-core.py
+++ b/src/plugins/abrt-action-analyze-core.py
@@ -1,25 +1,48 @@
-#! /usr/bin/python -u
+#!/usr/bin/python -u
# -*- coding: utf-8 -*-
+# WARNING: python -u means unbuffered I/O. Without it the messages are
+# passed to the parent asynchronously which looks bad in clients.
-# WARNING: python -u means unbuffered I/O without it the messages are
-# passed to the parent asynchronously which looks bad in clients..
from subprocess import Popen, PIPE
import sys
import os
import getopt
-# everything was ok
-RETURN_OK = 0
-# serious problem, should be logged somewhere
-RETURN_FAILURE = 2
-
-
GETTEXT_PROGNAME = "abrt"
import locale
import gettext
_ = lambda x: gettext.lgettext(x)
+
+verbose = 0
+
+def log(s):
+ sys.stderr.write("%s\n" % s)
+
+def log1(message):
+ if verbose > 0:
+ log(message)
+
+def log2(message):
+ if verbose > 1:
+ log(message)
+
+def error_msg(s):
+ sys.stderr.write("%s\n" % s)
+
+def error_msg_and_die(s):
+ sys.stderr.write("%s\n" % s)
+ exit(1)
+
+def xopen(name, mode):
+ try:
+ r = open(name, mode)
+ except IOError, e:
+ error_msg_and_die("Can't open '%s': %s" % (name, e));
+ return r
+
+
def init_gettext():
try:
locale.setlocale(locale.LC_ALL, "")
@@ -30,17 +53,6 @@ def init_gettext():
gettext.bindtextdomain(GETTEXT_PROGNAME, '/usr/share/locale')
gettext.textdomain(GETTEXT_PROGNAME)
-verbose = 0
-def log1(message):
- """ prints log message if verbosity > 0 """
- if verbose > 0:
- print "LOG1:", message
-
-def log2(message):
- """ prints log message if verbosity > 1 """
- if verbose > 1:
- print "LOG2:", message
-
#eu_unstrip_OUT=`eu-unstrip "--core=$core" -n 2>eu_unstrip.ERR`
def extract_info_from_core(coredump_name):
"""
@@ -53,7 +65,7 @@ def extract_info_from_core(coredump_name):
#SEP = 3
EXECUTABLE = 4
- print _("Analyzing coredump '%s'") % coredump_name
+ log(_("Analyzing coredump '%s'") % coredump_name)
eu_unstrip_OUT = Popen(["eu-unstrip","--core=%s" % coredump_name, "-n"], stdout=PIPE, bufsize=-1).communicate()[0]
# parse eu_unstrip_OUT and return the list of build_ids
@@ -74,8 +86,7 @@ def extract_info_from_core(coredump_name):
#print eu_unstrip_OUT
# we failed to get build ids from the core -> die
if not eu_unstrip_OUT:
- print "Can't get build ids from %s" % coredump_name
- exit(RETURN_FAILURE)
+ error_msg_and_die("Can't get build ids from %s" % coredump_name)
lines = eu_unstrip_OUT.split('\n')
# using set ensures the unique values
@@ -108,26 +119,7 @@ def build_ids_to_path(build_ids):
"""
return ["/usr/lib/debug/.build-id/%s/%s.debug" % (b_id[:2], b_id[2:]) for b_id in build_ids]
-def sigterm_handler(signum, frame):
- exit(RETURN_OK)
-
-def sigint_handler(signum, frame):
- print "\n", _("Exiting on user command")
- exit(RETURN_OK)
-
-import signal
-
if __name__ == "__main__":
- # abrt-server can send SIGTERM to abort the download
- signal.signal(signal.SIGTERM, sigterm_handler)
- # ctrl-c
- signal.signal(signal.SIGINT, sigint_handler)
- core = None
- cachedir = None
- tmpdir = None
- keeprpms = False
- output_file = "build_ids"
-
# localization
init_gettext()
@@ -138,32 +130,46 @@ if __name__ == "__main__":
except:
pass
- help_text = _("Usage: %s [-v] [-o OUTFILE] [-c COREFILE]") % sys.argv[0]
+ progname = os.path.basename(sys.argv[0])
+ help_text = _("Usage: %s [-v] [-o OUTFILE] -c COREFILE") % progname
try:
opts, args = getopt.getopt(sys.argv[1:], "vhc:o:", ["help", "core="])
except getopt.GetoptError, err:
- print str(err) # prints something like "option -a not recognized"
- exit(RETURN_FAILURE)
+ error_msg(err) # prints something like "option -a not recognized"
+ error_msg_and_die(help_text)
+
+ core = None
+ opt_o = None
for opt, arg in opts:
- if opt == "-v":
+ if opt in ("-h", "--help"):
+ print help_text
+ exit(0)
+ elif opt == "-v":
verbose += 1
elif opt == "-o":
- output_file = arg
- elif opt in ("--core", "-c"):
+ opt_o = arg
+ elif opt in ("-c", "--core"):
core = arg
- elif opt in ("-h", "--help"):
- print help_text
- exit()
if not core:
- print _("You have to specify the path to coredump")
- print help_text
- exit(RETURN_FAILURE)
+ error_msg(_("COREFILE is not specified"))
+ error_msg_and_die(help_text)
b_ids = extract_info_from_core(core)
- f_build_ids = open(output_file, "w")
-# TODO: check for open/write/close errors?
- for bid in b_ids:
- f_build_ids.write("%s\n" % bid)
- f_build_ids.close()
+
+ try:
+ # Note that we open -o FILE only when we reach the point
+ # when we are definitely going to write something to it
+ outfile = sys.stdout
+ outname = opt_o
+ for bid in b_ids:
+ if outname:
+ outfile = xopen(outname, "w")
+ outname = None
+ outfile.write("%s\n" % bid)
+ outfile.close()
+ except IOError, e:
+ if not opt_o:
+ opt_o = "<stdout>"
+ error_msg_and_die("Error writing to '%s': %s" % (opt_o, e))
diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py
index 83a82780..23b9d5ea 100755
--- a/src/plugins/abrt-action-install-debuginfo.py
+++ b/src/plugins/abrt-action-install-debuginfo.py
@@ -391,9 +391,10 @@ if __name__ == "__main__":
except:
pass
+ progname = os.path.basename(sys.argv[0])
help_text = _("Usage: %s --core=COREFILE "
"--tmpdir=TMPDIR "
- "--cache=CACHEDIR") % sys.argv[0]
+ "--cache=CACHEDIR") % progname
try:
opts, args = getopt.getopt(sys.argv[1:], "vyhc:", ["help", "core=",
"cache=", "tmpdir=",
@@ -403,11 +404,14 @@ if __name__ == "__main__":
exit(RETURN_FAILURE)
for opt, arg in opts:
- if opt == "-v":
+ if opt in ("-h", "--help"):
+ print help_text
+ exit(0)
+ elif opt == "-v":
verbose += 1
elif opt == "-y":
noninteractive = True
- elif opt in ("-i"):
+ elif opt == "-i":
core = arg
elif opt in ("--cache"):
cachedir = arg
@@ -415,9 +419,6 @@ if __name__ == "__main__":
tmpdir = arg
elif opt in ("--keeprpms"):
keeprpms = True
- elif opt in ("-h", "--help"):
- print help_text
- exit()
if not core:
print _("You have to specify the path to coredump.")
diff --git a/src/plugins/abrt-action-list-dsos.py b/src/plugins/abrt-action-list-dsos.py
index d73ed08d..db450ced 100755
--- a/src/plugins/abrt-action-list-dsos.py
+++ b/src/plugins/abrt-action-list-dsos.py
@@ -1,26 +1,92 @@
-#! /usr/bin/python -u
+#!/usr/bin/python -u
+# WARNING: python -u means unbuffered I/O. Without it the messages are
+# passed to the parent asynchronously which looks bad in clients.
+
+import sys
+import os
+import getopt
import rpm
-def list_dsos_rpm(dso_paths):
+GETTEXT_PROGNAME = "abrt"
+import locale
+import gettext
- ts = rpm.TransactionSet()
- for path in dso_paths:
- mi = ts.dbMatch('basenames', path)
- if len(mi):
- for h in mi:
- print "%s <> %s - (%s)" % (path, h[rpm.RPMTAG_NEVRA], h[rpm.RPMTAG_VENDOR])
- else:
- print "%s doesn't belong to any package" % (path)
+_ = lambda x: gettext.lgettext(x)
-def parse_maps(maps_path):
- f = open(maps_path, "r")
- return [x.strip()[x.find('/'):] for x in f.readlines() if x.find('/') > -1]
+def log(s):
+ sys.stderr.write("%s\n" % s)
+
+def error_msg(s):
+ sys.stderr.write("%s\n" % s)
+
+def error_msg_and_die(s):
+ sys.stderr.write("%s\n" % s)
+def xopen(name, mode):
+ try:
+ r = open(name, mode)
+ except IOError, e:
+ error_msg_and_die("Can't open '%s': %s" % (name, e));
+ return r
+
+
+def parse_maps(maps_path):
+ try:
+ f = xopen(maps_path, "r")
+ return [x.strip()[x.find('/'):] for x in f.readlines() if x.find('/') > -1]
+ except IOError, e:
+ error_msg_and_die("Can't read '%s': %s" % (name, e));
if __name__ == "__main__":
+ progname = os.path.basename(sys.argv[0])
+ help_text = _("Usage: %s [-o OUTFILE] -m PROC_PID_MAP_FILE") % progname
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "o:m:h", ["help"])
+ except getopt.GetoptError, err:
+ error_msg(err) # prints something like "option -a not recognized"
+ error_msg_and_die(help_text)
+
+ opt_o = None
+ memfile = None
+
+ for opt, arg in opts:
+ if opt in ("-h", "--help"):
+ print help_text
+ exit(0)
+ #elif opt == "-v":
+ # verbose += 1
+ elif opt == "-o":
+ opt_o = arg
+ elif opt == "-m":
+ memfile = arg
+
+ if not memfile:
+ error_msg(_("MAP_FILE is not specified"))
+ error_msg_and_die(help_text)
+
try:
- dsos = parse_maps("maps")
- list_dsos_rpm(dsos)
- except Exception, ex:
- print "Couldn't get the dsos list: %s", ex
+ # Note that we open -o FILE only when we reach the point
+ # when we are definitely going to write something to it
+ outfile = sys.stdout
+ outname = opt_o
+ try:
+ dso_paths = parse_maps(memfile)
+ for path in dso_paths:
+ ts = rpm.TransactionSet()
+ mi = ts.dbMatch('basenames', path)
+ if len(mi):
+ for h in mi:
+ if (outname)
+ outfile = xopen(outname, "w")
+ outname = None
+ outfile.write("%s %s (%s)\n" % (path, h[rpm.RPMTAG_NEVRA], h[rpm.RPMTAG_VENDOR]))
+
+ except Exception, ex:
+ error_msg_and_die("Can't get the DSO list: %s", ex)
+
+ outfile.close()
+ except:
+ if not opt_o:
+ opt_o = "<stdout>"
+ error_msg_and_die("Error writing to '%s'" % opt_o)
diff --git a/src/plugins/ccpp_events.conf b/src/plugins/ccpp_events.conf
index dcfab55e..1e111f04 100644
--- a/src/plugins/ccpp_events.conf
+++ b/src/plugins/ccpp_events.conf
@@ -1,13 +1,13 @@
EVENT=post-create analyzer=CCpp
abrt-action-analyze-c &&
- abrt-action-list-dsos.py >dsos
+ abrt-action-list-dsos.py -m maps -o dsos
# We run analyze_foo steps only if backtrace is empty (not yet generated):
# TODO: can we still specify additional directories to search for debuginfos,
# or was this ability lost with move to python installer?
EVENT=analyze_LocalGDB analyzer=CCpp backtrace=
abrt-action-trim-files -f 4096m:/var/cache/abrt-di &&
- abrt-action-analyze-core.py --core="$DUMP_DIR/coredump" &&
+ abrt-action-analyze-core.py --core=coredump -o build_ids &&
abrt-action-install-debuginfo &&
abrt-action-generate-backtrace &&
abrt-action-analyze-backtrace
@@ -20,7 +20,7 @@ EVENT=analyze_RetraceServer analyzer=CCpp backtrace=
# It doesn't check that backtrace is empty:
EVENT=reanalyze_LocalGDB analyzer=CCpp
abrt-action-trim-files -f 4096m:/var/cache/abrt-di &&
- abrt-action-analyze-core.py --core="$DUMP_DIR/coredump" &&
+ abrt-action-analyze-core.py --core=coredump -o build_ids &&
abrt-action-install-debuginfo &&
abrt-action-generate-backtrace &&
abrt-action-analyze-backtrace