From: John Admanski Subject: Re: [Autotest] [PATCH] Adding a userspace application crash handling system to autotest Date: Mon, 14 Sep 2009 07:39:35 -0700 Message-ID: <394b34480909140739l7acf833dod77fd75b53d6150e@mail.gmail.com> References: <1252418030-27982-1-git-send-email-lmr@redhat.com> <6ac58f4f0909132140u49a976e4xd58db60b7af69e1@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: autotest@test.kernel.org, kvm@vger.kernel.org To: Lucas Meneghel Rodrigues Return-path: Received: from smtp-out.google.com ([216.239.45.13]:33104 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755634AbZINOj4 convert rfc822-to-8bit (ORCPT ); Mon, 14 Sep 2009 10:39:56 -0400 Received: from wpaz37.hot.corp.google.com (wpaz37.hot.corp.google.com [172.24.198.101]) by smtp-out.google.com with ESMTP id n8EEdvZf018323 for ; Mon, 14 Sep 2009 07:39:58 -0700 Received: from iwn4 (iwn4.prod.google.com [10.241.68.68]) by wpaz37.hot.corp.google.com with ESMTP id n8EEdtJ9022235 for ; Mon, 14 Sep 2009 07:39:55 -0700 Received: by iwn4 with SMTP id 4so1215770iwn.12 for ; Mon, 14 Sep 2009 07:39:55 -0700 (PDT) In-Reply-To: <6ac58f4f0909132140u49a976e4xd58db60b7af69e1@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: Sorry, I haven't had time to take a look yet. Been busy. :( I'll try and get in a review some time today. -- John On Sun, Sep 13, 2009 at 9:40 PM, Lucas Meneghel Rodrigues wrote: > Hi John, do you think the code looks good enough for inclusion? > > On Tue, Sep 8, 2009 at 10:53 AM, Lucas Meneghel Rodrigues > wrote: >> This patch adds a system to watch user space segmentation >> faults, writing core dumps and some degree of core dump >> analysis report. We believe that such a system will be >> beneficial for autotest as a whole, since the ability to >> get core dumps and dump analysis for each app crashing >> during an autotest execution can help test engineers with >> richer debugging information. >> >> The system is comprised by 2 parts: >> >> =A0* Modifications on test code that enable core dumps >> generation, register a core handler script in the kernel >> and check by generated core files at the end of each >> test. >> >> =A0* A core handler script that is going to write the >> core on each test debug dir in a convenient way, with >> a report that currently is comprised by the process that >> died and a gdb stacktrace of the process. As the system >> gets in shape, we could add more scripts that can do >> fancier stuff (such as handlers that use frysk to get >> more info such as memory maps, provided that we have >> frysk installed in the machine). >> >> This is the proof of concept of the system. I am sending it >> to the mailing list on this early stage so I can get >> feedback on the feature. The system passes my basic >> tests: >> >> =A0* Run a simple long test, such as the kvm test, and >> then crash an application while the test is running. I >> get reports generated on test.debugdir >> >> =A0* Run a slightly more complex control file, with 3 parallel >> bonnie instances at once and crash an application while the >> test is running. I get reports generated on all >> test.debugdirs. >> >> 3rd try: >> =A0* Explicitely enable core dumps using the resource module >> =A0* Fixed a bug on the crash detection code, and factored >> =A0 it into a utility function. >> >> I believe we are good to go now. >> >> Signed-off-by: Lucas Meneghel Rodrigues >> --- >> =A0client/common_lib/test.py =A0 =A0 | =A0 66 +++++++++++++- >> =A0client/tools/crash_handler.py | =A0202 ++++++++++++++++++++++++++= +++++++++++++++ >> =A02 files changed, 266 insertions(+), 2 deletions(-) >> =A0create mode 100755 client/tools/crash_handler.py >> >> diff --git a/client/common_lib/test.py b/client/common_lib/test.py >> index 362c960..65b78a3 100644 >> --- a/client/common_lib/test.py >> +++ b/client/common_lib/test.py >> @@ -17,7 +17,7 @@ >> =A0# =A0 =A0 =A0 tmpdir =A0 =A0 =A0 =A0 =A0eg. tmp/_ >> >> =A0import fcntl, os, re, sys, shutil, tarfile, tempfile, time, trace= back >> -import warnings, logging >> +import warnings, logging, glob, resource >> >> =A0from autotest_lib.client.common_lib import error >> =A0from autotest_lib.client.bin import utils >> @@ -31,7 +31,6 @@ class base_test: >> =A0 =A0 =A0 =A0 self.job =3D job >> =A0 =A0 =A0 =A0 self.pkgmgr =3D job.pkgmgr >> =A0 =A0 =A0 =A0 self.autodir =3D job.autodir >> - >> =A0 =A0 =A0 =A0 self.outputdir =3D outputdir >> =A0 =A0 =A0 =A0 self.tagged_testname =3D os.path.basename(self.outpu= tdir) >> =A0 =A0 =A0 =A0 self.resultsdir =3D os.path.join(self.outputdir, 're= sults') >> @@ -40,6 +39,7 @@ class base_test: >> =A0 =A0 =A0 =A0 os.mkdir(self.profdir) >> =A0 =A0 =A0 =A0 self.debugdir =3D os.path.join(self.outputdir, 'debu= g') >> =A0 =A0 =A0 =A0 os.mkdir(self.debugdir) >> + =A0 =A0 =A0 =A0self.configure_crash_handler() >> =A0 =A0 =A0 =A0 self.bindir =3D bindir >> =A0 =A0 =A0 =A0 if hasattr(job, 'libdir'): >> =A0 =A0 =A0 =A0 =A0 =A0 self.libdir =3D job.libdir >> @@ -54,6 +54,66 @@ class base_test: >> =A0 =A0 =A0 =A0 self.after_iteration_hooks =3D [] >> >> >> + =A0 =A0def configure_crash_handler(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Configure the crash handler by: >> + =A0 =A0 =A0 =A0 * Setting up core size to unlimited >> + =A0 =A0 =A0 =A0 * Putting an appropriate crash handler on /proc/sy= s/kernel/core_pattern >> + =A0 =A0 =A0 =A0 * Create files that the crash handler will use to = figure which tests >> + =A0 =A0 =A0 =A0 =A0 are active at a given moment >> + >> + =A0 =A0 =A0 =A0The crash handler will pick up the core file and wr= ite it to >> + =A0 =A0 =A0 =A0self.debugdir, and perform analysis on it to genera= te a report. The >> + =A0 =A0 =A0 =A0program also outputs some results to syslog. >> + >> + =A0 =A0 =A0 =A0If multiple tests are running, an attempt to verify= if we still have >> + =A0 =A0 =A0 =A0the old PID on the system process table to determin= e whether it is a >> + =A0 =A0 =A0 =A0parent of the current test execution. If we can't d= etermine it, the >> + =A0 =A0 =A0 =A0core file and the report file will be copied to all= test debug dirs. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0self.pattern_file =3D '/proc/sys/kernel/core_patter= n' >> + =A0 =A0 =A0 =A0try: >> + =A0 =A0 =A0 =A0 =A0 =A0# Enable core dumps >> + =A0 =A0 =A0 =A0 =A0 =A0resource.setrlimit(resource.RLIMIT_CORE, (-= 1, -1)) >> + =A0 =A0 =A0 =A0 =A0 =A0# Trying to backup core pattern and registe= r our script >> + =A0 =A0 =A0 =A0 =A0 =A0self.core_pattern_backup =3D open(self.patt= ern_file, 'r').read() >> + =A0 =A0 =A0 =A0 =A0 =A0pattern_file =3D open(self.pattern_file, 'w= ') >> + =A0 =A0 =A0 =A0 =A0 =A0tools_dir =3D os.path.join(self.autodir, 't= ools') >> + =A0 =A0 =A0 =A0 =A0 =A0crash_handler_path =3D os.path.join(tools_d= ir, 'crash_handler.py') >> + =A0 =A0 =A0 =A0 =A0 =A0pattern_file.write('|' + crash_handler_path= + ' %p %t %u %s %h %e') >> + =A0 =A0 =A0 =A0 =A0 =A0# Writing the files that the crash handler = is going to use >> + =A0 =A0 =A0 =A0 =A0 =A0self.debugdir_tmp_file =3D ('/tmp/autotest_= results_dir.%s' % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0os.getpid()) >> + =A0 =A0 =A0 =A0 =A0 =A0utils.open_write_close(self.debugdir_tmp_fi= le, self.debugdir + "\n") >> + =A0 =A0 =A0 =A0except Exception, e: >> + =A0 =A0 =A0 =A0 =A0 =A0self.crash_handling_enabled =3D False >> + =A0 =A0 =A0 =A0 =A0 =A0logging.error('Crash handling system disabl= ed: %s' % e) >> + =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0self.crash_handling_enabled =3D True >> + =A0 =A0 =A0 =A0 =A0 =A0logging.debug('Crash handling system enable= d.') >> + >> + >> + =A0 =A0def crash_handler_report(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0If core dumps are found on the debugdir after the e= xecution of the >> + =A0 =A0 =A0 =A0test, let the user know. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0if self.crash_handling_enabled: >> + =A0 =A0 =A0 =A0 =A0 =A0core_dirs =3D glob.glob('%s/crash.*' % self= =2Edebugdir) >> + =A0 =A0 =A0 =A0 =A0 =A0if core_dirs: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.warning('Programs crashed d= uring test execution:') >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0for dir in core_dirs: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.warning('Please ver= ify %s for more info', dir) >> + =A0 =A0 =A0 =A0 =A0 =A0# Remove the debugdir info file >> + =A0 =A0 =A0 =A0 =A0 =A0os.unlink(self.debugdir_tmp_file) >> + =A0 =A0 =A0 =A0 =A0 =A0# Restore the core pattern backup >> + =A0 =A0 =A0 =A0 =A0 =A0try: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0utils.open_write_close(self.pattern= _file, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 self.core_pattern_backup) >> + =A0 =A0 =A0 =A0 =A0 =A0except EnvironmentError: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pass >> + >> + >> =A0 =A0 def assert_(self, expr, msg=3D'Assertion failed.'): >> =A0 =A0 =A0 =A0 if not expr: >> =A0 =A0 =A0 =A0 =A0 =A0 raise error.TestError(msg) >> @@ -377,6 +437,7 @@ class base_test: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 traceback.print_exc(= ) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 print 'Now raising t= he earlier %s error' % exc_info[0] >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 finally: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.crash_handler_report() >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 self.job.logging.restore() >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 try: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise exc_info[0], e= xc_info[1], exc_info[2] >> @@ -389,6 +450,7 @@ class base_test: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if run_cleanup: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _cherry_pick_call(se= lf.cleanup, *args, **dargs) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 finally: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.crash_handler_report() >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 self.job.logging.restore() >> =A0 =A0 =A0 =A0 except error.AutotestError: >> =A0 =A0 =A0 =A0 =A0 =A0 if self.network_destabilizing: >> diff --git a/client/tools/crash_handler.py b/client/tools/crash_hand= ler.py >> new file mode 100755 >> index 0000000..e281eb5 >> --- /dev/null >> +++ b/client/tools/crash_handler.py >> @@ -0,0 +1,202 @@ >> +#!/usr/bin/python >> +""" >> +Simple crash handling application for autotest >> + >> +@copyright Red Hat Inc 2009 >> +@author Lucas Meneghel Rodrigues >> +""" >> +import sys, os, commands, glob, tempfile, shutil, syslog >> + >> + >> +def get_parent_pid(pid): >> + =A0 =A0""" >> + =A0 =A0Returns the parent PID for a given PID, converted to an int= eger. >> + >> + =A0 =A0@param pid: Process ID. >> + =A0 =A0""" >> + =A0 =A0try: >> + =A0 =A0 =A0 =A0stat_file_contents =3D open('/proc/%s/stat' % pid, = 'r').readline() >> + =A0 =A0 =A0 =A0ppid =3D int(stat_file_contents.split(" ")[3]) >> + =A0 =A0except: >> + =A0 =A0 =A0 =A0# It is not possible to determine the parent becaus= e the process >> + =A0 =A0 =A0 =A0# already left the process table. >> + =A0 =A0 =A0 =A0ppid =3D 1 >> + >> + =A0 =A0return ppid >> + >> + >> +def pid_descends_from(pid_a, pid_b): >> + =A0 =A0""" >> + =A0 =A0Check whether pid_a descends from pid_b. >> + >> + =A0 =A0@param pid_a: Process ID. >> + =A0 =A0@param pid_b: Process ID. >> + =A0 =A0""" >> + =A0 =A0pid_a =3D int(pid_a) >> + =A0 =A0pid_b =3D int(pid_b) >> + =A0 =A0current_pid =3D pid_a >> + =A0 =A0while current_pid > 1: >> + =A0 =A0 =A0 =A0if current_pid =3D=3D pid_b: >> + =A0 =A0 =A0 =A0 =A0 =A0syslog.syslog(syslog.LOG_INFO, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"PID %s descend= s from PID %s!" % (pid_a, pid_b)) >> + =A0 =A0 =A0 =A0 =A0 =A0return True >> + =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0current_pid =3D get_parent_pid(current_pid) >> + =A0 =A0syslog.syslog(syslog.LOG_INFO, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"PID %s does not descend from P= ID %s" % (pid_a, pid_b)) >> + =A0 =A0return False >> + >> + >> +def write_to_file(file_path, contents): >> + =A0 =A0""" >> + =A0 =A0Write contents to a given file path specified. If not speci= fied, the file >> + =A0 =A0will be created. >> + >> + =A0 =A0@param file_path: Path to a given file. >> + =A0 =A0@param contents: File contents. >> + =A0 =A0""" >> + =A0 =A0file_object =3D open(file_path, 'w') >> + =A0 =A0file_object.write(contents) >> + =A0 =A0file_object.close() >> + >> + >> +def get_results_dir_list(pid, core_dir_basename): >> + =A0 =A0""" >> + =A0 =A0Get all valid output directories for the core file and the = report. It works >> + =A0 =A0by inspecting files created by each test on /tmp and verify= ing if the >> + =A0 =A0PID of the process that crashed is a child or grandchild of= the autotest >> + =A0 =A0test process. If it can't find any relationship (maybe a da= emon that died >> + =A0 =A0during a test execution), it will write the core file to th= e debug dirs >> + =A0 =A0of all tests currently being executed. If there are no acti= ve autotest >> + =A0 =A0tests at a particular moment, it will return a list with ['= /tmp']. >> + >> + =A0 =A0@param pid: PID for the process that generated the core >> + =A0 =A0@param core_dir_basename: Basename for the directory that w= ill hold both >> + =A0 =A0 =A0 =A0 =A0 =A0the core dump and the crash report. >> + =A0 =A0""" >> + =A0 =A0# Get all active test debugdir path files present >> + =A0 =A0debugdir_files =3D glob.glob("/tmp/autotest_results_dir.*") >> + =A0 =A0if debugdir_files: >> + =A0 =A0 =A0 =A0pid_dir_dict =3D {} >> + =A0 =A0 =A0 =A0for debugdir_file in debugdir_files: >> + =A0 =A0 =A0 =A0 =A0 =A0a_pid =3D debugdir_file.split('.')[-1] >> + =A0 =A0 =A0 =A0 =A0 =A0results_dir =3D open(debugdir_file, 'r').re= ad().strip() >> + =A0 =A0 =A0 =A0 =A0 =A0pid_dir_dict[a_pid] =3D os.path.join(result= s_dir, core_dir_basename) >> + >> + =A0 =A0 =A0 =A0results_dir_list =3D [] >> + =A0 =A0 =A0 =A0found_relation =3D False >> + =A0 =A0 =A0 =A0for a_pid, a_path in pid_dir_dict.iteritems(): >> + =A0 =A0 =A0 =A0 =A0 =A0if pid_descends_from(pid, a_pid): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0results_dir_list.append(a_path) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0found_relation =3D True >> + >> + =A0 =A0 =A0 =A0# If we could not find any relations between the pi= ds in the list with >> + =A0 =A0 =A0 =A0# the process that crashed, we can't tell for sure = which test spawned >> + =A0 =A0 =A0 =A0# the process (maybe it is a daemon and started eve= n before autotest >> + =A0 =A0 =A0 =A0# started), so we will have to output the core file= to all active test >> + =A0 =A0 =A0 =A0# directories. >> + =A0 =A0 =A0 =A0if not found_relation: >> + =A0 =A0 =A0 =A0 =A0 =A0return pid_dir_dict.values() >> + =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0return results_dir_list >> + >> + =A0 =A0else: >> + =A0 =A0 =A0 =A0path_inactive_autotest =3D os.path.join('/tmp', cor= e_dir_basename) >> + =A0 =A0 =A0 =A0return [path_inactive_autotest] >> + >> + >> +def get_info_from_core(path): >> + =A0 =A0""" >> + =A0 =A0Reads a core file and extracts a dictionary with useful cor= e information. >> + =A0 =A0Right now, the only information extracted is the full execu= table name. >> + >> + =A0 =A0@param path: Path to core file. >> + =A0 =A0""" >> + =A0 =A0# Here we are getting the executable full path in a very in= elegant way :( >> + =A0 =A0# Since the 'right' solution for it is to make a library to= get information >> + =A0 =A0# from core dump files, properly written, I'll leave this a= s it is for now. >> + =A0 =A0full_exe_path =3D commands.getoutput('strings %s | grep "_=3D= "' % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 path).strip("_=3D") >> + =A0 =A0if full_exe_path.startswith("./"): >> + =A0 =A0 =A0 =A0pwd =3D commands.getoutput('strings %s | grep "^PWD= =3D"' % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pa= th).strip("PWD=3D") >> + =A0 =A0 =A0 =A0full_exe_path =3D os.path.join(pwd, full_exe_path.s= trip("./")) >> + >> + =A0 =A0return {'core_file': path, 'full_exe_path': full_exe_path} >> + >> + >> +if __name__ =3D=3D "__main__": >> + =A0 =A0syslog.openlog('AutotestCrashHandler', 0, syslog.LOG_DAEMON= ) >> + =A0 =A0(crashed_pid, time, uid, signal, hostname, exe) =3D sys.arg= v[1:] >> + =A0 =A0core_name =3D 'core' >> + =A0 =A0report_name =3D 'report' >> + =A0 =A0core_dir_name =3D 'crash.%s.%s' % (exe, crashed_pid) >> + =A0 =A0core_tmp_dir =3D tempfile.mkdtemp(prefix=3D'core_', dir=3D'= /tmp') >> + =A0 =A0core_tmp_path =3D os.path.join(core_tmp_dir, core_name) >> + =A0 =A0gdb_command_path =3D os.path.join(core_tmp_dir, 'gdb_comman= d') >> + >> + =A0 =A0try: >> + =A0 =A0 =A0 =A0# Get the filtered results dir list >> + =A0 =A0 =A0 =A0current_results_dir_list =3D get_results_dir_list(c= rashed_pid, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0core_dir_name) >> + >> + =A0 =A0 =A0 =A0# Write the core file to the appropriate directory >> + =A0 =A0 =A0 =A0# (we are piping it to this script) >> + =A0 =A0 =A0 =A0core_file =3D sys.stdin.read() >> + =A0 =A0 =A0 =A0write_to_file(core_tmp_path, core_file) >> + >> + =A0 =A0 =A0 =A0# Write a command file for GDB >> + =A0 =A0 =A0 =A0gdb_command =3D 'bt full\n' >> + =A0 =A0 =A0 =A0write_to_file(gdb_command_path, gdb_command) >> + >> + =A0 =A0 =A0 =A0# Get full command path >> + =A0 =A0 =A0 =A0exe_path =3D get_info_from_core(core_tmp_path)['ful= l_exe_path'] >> + >> + =A0 =A0 =A0 =A0# Take a backtrace from the running program >> + =A0 =A0 =A0 =A0gdb_cmd =3D 'gdb -e %s -c %s -x %s -n -batch -quiet= ' % (exe_path, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0core_tmp_path, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gdb_command_pat= h) >> + =A0 =A0 =A0 =A0backtrace =3D commands.getoutput(gdb_cmd) >> + =A0 =A0 =A0 =A0# Sanitize output before passing it to the report >> + =A0 =A0 =A0 =A0backtrace =3D backtrace.decode('utf-8', 'ignore') >> + >> + =A0 =A0 =A0 =A0# Composing the format_dict >> + =A0 =A0 =A0 =A0format_dict =3D {} >> + =A0 =A0 =A0 =A0format_dict['program'] =3D exe_path >> + =A0 =A0 =A0 =A0format_dict['pid'] =3D crashed_pid >> + =A0 =A0 =A0 =A0format_dict['signal'] =3D signal >> + =A0 =A0 =A0 =A0format_dict['hostname'] =3D hostname >> + =A0 =A0 =A0 =A0format_dict['time'] =3D time >> + =A0 =A0 =A0 =A0format_dict['backtrace'] =3D backtrace >> + >> + =A0 =A0 =A0 =A0report =3D """Autotest crash report >> + >> +Program: %(program)s >> +PID: %(pid)s >> +Signal: %(signal)s >> +Hostname: %(hostname)s >> +Time of the crash: %(time)s >> +Program backtrace: >> +%(backtrace)s >> +""" % format_dict >> + >> + =A0 =A0 =A0 =A0syslog.syslog(syslog.LOG_INFO, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"Application %s, PID %s= crashed" % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(exe_path, crashed_pid)= ) >> + >> + =A0 =A0 =A0 =A0# Now, for all results dir, let's create the direct= ory if it doesn't >> + =A0 =A0 =A0 =A0# exist, and write the core file and the report to = it. >> + =A0 =A0 =A0 =A0syslog.syslog(syslog.LOG_INFO, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"Writing core files and= reports to %s" % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0current_results_dir_lis= t) >> + =A0 =A0 =A0 =A0for result_dir in current_results_dir_list: >> + =A0 =A0 =A0 =A0 =A0 =A0if not os.path.isdir(result_dir): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0os.makedirs(result_dir) >> + =A0 =A0 =A0 =A0 =A0 =A0core_path =3D os.path.join(result_dir, 'cor= e') >> + =A0 =A0 =A0 =A0 =A0 =A0write_to_file(core_path, core_file) >> + =A0 =A0 =A0 =A0 =A0 =A0report_path =3D os.path.join(result_dir, 'r= eport') >> + =A0 =A0 =A0 =A0 =A0 =A0write_to_file(report_path, report) >> + >> + =A0 =A0finally: >> + =A0 =A0 =A0 =A0# Cleanup temporary directories >> + =A0 =A0 =A0 =A0shutil.rmtree(core_tmp_dir) >> -- >> 1.6.2.5 >> >> _______________________________________________ >> Autotest mailing list >> Autotest@test.kernel.org >> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest >> > > > > -- > Lucas >