- make a copy of CWD at exception handler installation time
- deficiencies:
* the CWD can be already changed by another .pth script
* I saw an AttributeError for missing getcwd() in os module but I
can't reproduce it
- this patch also fixes #611 because write_dump() stops using sys.argv
- closes #610
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/hooks/abrt_exception_handler.py.in | 31 +++++++++++++++----------------
tests/pyhook.at | 2 +-
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/src/hooks/abrt_exception_handler.py.in
b/src/hooks/abrt_exception_handler.py.in
index 710ebdc..66fab18 100644
--- a/src/hooks/abrt_exception_handler.py.in
+++ b/src/hooks/abrt_exception_handler.py.in
@@ -29,14 +29,7 @@ class RPMinfoError(Exception):
"""Exception class for RPMdb-querying related
errors"""
pass
-def write_dump(tb_text, tb):
- if sys.argv[0][0] == "/":
- executable = os.path.abspath(sys.argv[0])
- else:
- # We don't know the path.
- # (BTW, we *can't* assume the script is in current directory.)
- executable = sys.argv[0]
-
+def write_dump(executable, tb_text, tb):
dso_list = None
try:
import rpm
@@ -173,7 +166,7 @@ def conf_enabled(var_name):
file.close()
return -1
-def handleMyException((etype, value, tb)):
+def handleMyException((orig_pwd, etype, value, tb)):
"""
The exception handling function.
@@ -216,13 +209,19 @@ def handleMyException((etype, value, tb)):
syslog.syslog("detected unhandled Python exception")
raise Exception
- # Ignore scripts with relative path unless "RequireAbsolutePath = no".
- # (In this case we can't reliably determine package)
- syslog.syslog("detected unhandled Python exception in '%s'" %
sys.argv[0])
- if sys.argv[0][0] != "/":
- if conf_enabled("RequireAbsolutePath") != 0:
+ if sys.argv[0][0] == "/":
+ executable = os.path.abspath(sys.argv[0])
+ else:
+ # Ignore scripts with relative path unless "RequireAbsolutePath =
no".
+ # (In this case we can't reliably determine package)
+ if not conf_enabled("RequireAbsolutePath"):
+ executable = os.path.abspath(os.path.join(orig_pwd, sys.argv[0]))
+ else:
+ syslog.syslog("ignored unhandled Python exception in '%s'
because of relative path to script" % sys.argv[0])
raise Exception
+ syslog.syslog("detected unhandled Python exception in '%s'" %
executable)
+
import traceback
elist = traceback.format_exception(etype, value, tb)
@@ -263,7 +262,7 @@ def handleMyException((etype, value, tb)):
text += "".join(elist)
# Send data to the daemon
- write_dump(text, tb)
+ write_dump(executable, text, tb)
except:
# Silently ignore any error in this hook,
@@ -277,7 +276,7 @@ def installExceptionHandler():
"""
Install the exception handling function.
"""
- sys.excepthook = lambda etype, value, tb: handleMyException((etype, value, tb))
+ sys.excepthook = lambda etype, value, tb: handleMyException((os.getcwd(), etype,
value, tb))
# install the exception handler when the abrt_exception_handler
# module is imported
diff --git a/tests/pyhook.at b/tests/pyhook.at
index 92a23bd..3c314d0 100644
--- a/tests/pyhook.at
+++ b/tests/pyhook.at
@@ -9,7 +9,7 @@ import sys
sys.path.insert(0, "../../../src/hooks")
import abrt_exception_handler
sys.argv[0]="/...testsuite.../$1.py"
-def write_dump(tb_text, tb):
+def write_dump(executable, tb_text, tb):
print tb_text.splitlines()[0]
abrt_exception_handler.write_dump = write_dump
$2
--
1.8.1.4