Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jun 2012 16:57:03 +0000
From:      tzabal@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r238482 - in soc2012/tzabal: client-side/akcrs-head/usr.sbin/crashreport server-side/akcrs-release/9.0.0/etc/rc.d server-side/akcrs-release/9.0.0/usr.sbin/crashreportd
Message-ID:  <20120628165703.991941065676@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tzabal
Date: Thu Jun 28 16:57:02 2012
New Revision: 238482
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238482

Log:
  crashreport can form a XML report for minidumps and full memory dumps (vmcore) - textdump is remaining. Updated code for not writing same parts of code for every command that we need to execute.

Added:
  soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.py   (contents, props changed)
Deleted:
  soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.php
Modified:
  soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh
  soc2012/tzabal/server-side/akcrs-release/9.0.0/etc/rc.d/crashreportd
  soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/Makefile

Modified: soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh
==============================================================================
--- soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh	Thu Jun 28 15:38:14 2012	(r238481)
+++ soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh	Thu Jun 28 16:57:02 2012	(r238482)
@@ -138,98 +138,52 @@
 
 ## Form the report
 data=`mktemp /tmp/crashreport.XXXXXX`
+tmp_file=`mktemp /tmp/crashreport.XXXXXX`
+orig_IFS="${IFS}"
+IFS=";"
+commands1="date/3;hostname/5;ostype/6;osrelease/7;version/8;machine/9"
+commands2="ps -axl;vmstat -s;vmstat -m;vmstat -z;vmstat -i;pstat -T;pstat -s;\
+iostat;ipcs -a;ipcs -T;nfsstat;netstat -s;netstat -m;netstat -id;netstat -anr;\
+netstat -anA;netstat -aL;fstat;dmesg;kernel config;ddb capture buffer"
+start=3
 
 echo "<?xml version='1.0' encoding='UTF-8'?>" > ${data}
 echo "<crashreport>" >> ${data}
 echo "<header>" >> ${data}
-echo "<type>" >> ${data}
 
+echo "<type>" >> ${data}
 output=`file "${_dumpdir}/${_file}"`
-if [ "${output}" == "${_dumpdir}/${_file}: ASCII English text" ]; then
-	type='vmcore'
-elif [ "${output}" == "${_dumpdir}/${_file}: POSIX tar archive" ]; then
+if echo "${output}" | grep 'POSIX tar archive' > /dev/null; then
 	type='textdump'
+elif echo "${output}" | grep 'text' > /dev/null; then
+	type='vmcore'
 else
 	error 'Unknown type of debugging information.'
 	exit 1
 fi
-
 echo "${type}" >> ${data}
 echo "</type>" >> ${data}
+
 echo "<email>" >> ${data}
 echo "${_email}" >> ${data}
 echo "</email>" >> ${data}
-echo "</header>" >> ${data}
 
+echo "</header>" >> ${data}
 echo "<body>" >> ${data}
-tmp_file=`mktemp /tmp/crashreport.XXXXXX`
 
 if [ "${type}" == 'vmcore' ]; then
-	# Date (date)
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "date" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	result=`sed -n '3p' "${_dumpdir}/${_file}"`
-	echo "${result}" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# Hostname (hostname)
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "hostname" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	result=`sed -n '5p' "${_dumpdir}/${_file}"`
-	echo "${result}" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# Operating System (ostype)
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "ostype" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	result=`sed -n '6p' "${_dumpdir}/${_file}"`
-	echo "${result}" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# Operating System Release (osrelease)
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "osrelease" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	result=`sed -n '7p' "${_dumpdir}/${_file}"`
-	echo "${result}" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# Version (version)
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "version" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	result=`sed -n '8p' "${_dumpdir}/${_file}"`
-	echo "${result}" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# Architecture (machine)
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "machine" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	result=`sed -n '9p' "${_dumpdir}/${_file}"`
-	echo "${result}" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
+	# For: date, hostname, ostype, osrelease, version, machine
+	for cmd in $commands1; do
+		echo "<command>" >> ${data}
+		echo "<name>" >> ${data}
+		echo "${cmd%/*}" >> ${data}
+		echo "</name>" >> ${data}
+		echo "<result>" >> ${data}
+		result=`sed -n "${cmd##*/}p" "${_dumpdir}/${_file}"`
+		echo "${result}" >> ${data}
+		echo "</result>" >> ${data}
+		echo "</command>" >> ${data}
+	done
 
 	# Panic Message (panic)
 	echo "<command>" >> ${data}
@@ -273,89 +227,30 @@
 	echo "</result>" >> ${data}
 	echo "</command>" >> ${data}
 
-	# ps -axl
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "ps -axl" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	cat "${_dumpdir}/${_file}" | \
-	 sed -E -n '/^ps -axl$/,/-{20,}/p' > ${tmp_file}
-	lines=`wc -l < ${tmp_file}`
-	start=3
-	end=$((lines-2))
-	cat ${tmp_file} | sed -E -n "${start},${end}p" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# vmstat -s
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "vmstat -s" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	cat "${_dumpdir}/${_file}" | \
-	 sed -E -n '/^vmstat -s$/,/-{20,}/p' > ${tmp_file}
-	lines=`wc -l < ${tmp_file}`
-	start=3
-	end=$((lines-2))
-	cat ${tmp_file} | sed -E -n "${start},${end}p" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# vmstat -m
-	echo "<command>" >> ${data}
-	echo "<name>" >> ${data}
-	echo "vmstat -m" >> ${data}
-	echo "</name>" >> ${data}
-	echo "<result>" >> ${data}
-	cat "${_dumpdir}/${_file}" | \
-	 sed -E -n '/^vmstat -m$/,/-{20,}/p' > ${tmp_file}
-	lines=`wc -l < ${tmp_file}`
-	start=3
-	end=$((lines-2))
-	cat ${tmp_file} | sed -E -n "${start},${end}p" >> ${data}
-	echo "</result>" >> ${data}
-	echo "</command>" >> ${data}
-
-	# vmstat -z
-
-	# vmstat -i
-
-	# pstat -T
-
-	# pstat -s
-
-	# iostat
-
-	# ipcs -a
-
-	# ipcs -T
-
-	# nfsstat
-
-	# netstat -s
-
-	# netstat -m
-
-	# netstat -id
-
-	# netstat -anr
-
-	# netstat -anA
-
-	# netstat -aL
-
-	# fstat
-
-	# dmesg
-
-	# kernel config
+	# From ps -axl until END
+	for cmd in $commands2; do
+		echo "<command>" >> ${data}
+		echo "<name>" >> ${data}
+		echo "${cmd}" >> ${data}
+		echo "</name>" >> ${data}
+		echo "<result>" >> ${data}
+		cat "${_dumpdir}/${_file}" | \
+		 sed -E -n "/^${cmd}$/,/-{20,}/p" > ${tmp_file}
+		lines=`wc -l < ${tmp_file}`
+		end=$((lines-2))
+		cat ${tmp_file} | sed -E -n "${start},${end}p" >> ${data}
+		echo "</result>" >> ${data}
+		echo "</command>" >> ${data}	
+	done
+else
+	# Code for textdump....
+	
+fi
 
-	# ddb capture buffer
+IFS="${orig_IFS}"
 
-	echo "</body>" >> ${data}
-	echo "</crashreport>" >> ${data}
+echo "</body>" >> ${data}
+echo "</crashreport>" >> ${data}
 
 
 ## Bundle the report

Modified: soc2012/tzabal/server-side/akcrs-release/9.0.0/etc/rc.d/crashreportd
==============================================================================
--- soc2012/tzabal/server-side/akcrs-release/9.0.0/etc/rc.d/crashreportd	Thu Jun 28 15:38:14 2012	(r238481)
+++ soc2012/tzabal/server-side/akcrs-release/9.0.0/etc/rc.d/crashreportd	Thu Jun 28 16:57:02 2012	(r238482)
@@ -9,7 +9,7 @@
 name="crashreportd"
 rcvar="crashreportd_enable"
 command="/usr/sbin/${name}"
-command_interpreter="/usr/local/bin/php"
+command_interpreter="/usr/local/bin/python"
 command_args="0<&- 1>/dev/null 2>&1 &"
 pidfile="/var/run/${name}.pid"
 

Modified: soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/Makefile
==============================================================================
--- soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/Makefile	Thu Jun 28 15:38:14 2012	(r238481)
+++ soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/Makefile	Thu Jun 28 16:57:02 2012	(r238482)
@@ -1,3 +1,3 @@
-SCRIPTS= crashreportd.php
+SCRIPTS= crashreportd.py
 
 .include <bsd.prog.mk>

Added: soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.py
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.py	Thu Jun 28 16:57:02 2012	(r238482)
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+
+import os
+import time
+import tarfile
+
+# Check if the given filename matches the pattern of a valid crash report
+# Return 1 in failure and 0 in success
+def check_filename(filename):
+    matchObj = re.match('^crashreport\.[A-Za-z0-9]{6}\.tar\.gz$', filename)
+    
+    if not matchObj:
+        return 1
+    
+    return 0
+
+
+def extract_file(filename):
+    try:
+        report = crashreports_dir + "/" + filename
+        tarfileObj = tarfile.open(report)
+    except ReadError:
+        return 1
+        
+    return 0
+
+
+def check_report(filename):
+    check_filename(filename)
+    
+    return 0;
+
+# Obtain the Process ID
+pid = os.getpid()
+
+# Create the pid file and write the Process ID inside
+#pid_file = '/var/run/crashreportd.pid'
+pid_file = '/home/tzabal/crashreportd.pid'
+f = open(pid_file, 'w')
+f.write(str(pid))
+f.close()
+
+# The infinite loop of the daemon
+crashreports_dir = '/home/tzabal/crashreports'
+dirlist = os.listdir(crashreports_dir)
+for filename in dirlist:
+    check_report(filename)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120628165703.991941065676>