Date: Sat, 30 Jun 2012 14:08:45 +0000 From: tzabal@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r238632 - soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport Message-ID: <20120630140845.24C101065696@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: tzabal Date: Sat Jun 30 14:08:44 2012 New Revision: 238632 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238632 Log: Add the function clear_xml() that replaces the characters of the report that have special meaning in XML with the predefined entity references. Modified: soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Modified: soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh ============================================================================== --- soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Sat Jun 30 14:05:20 2012 (r238631) +++ soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Sat Jun 30 14:08:44 2012 (r238632) @@ -1,9 +1,9 @@ #!/bin/sh # -# Crashreport is a program that is responsible to locate, collect and send -# the debugging information of a FreeBSD kernel crash to a central machine -# that collects these reports for analysis from the FreeBSD community and -# the FreeBSD developers. +# Crashreport is a program that is responsible to locate, collect, form and +# transfer the debugging information of a FreeBSD kernel crash to a central +# machine that collects these reports for analysis from the FreeBSD community +# and the FreeBSD developers. # [ -f /etc/rc.conf ] && . /etc/rc.conf @@ -21,6 +21,28 @@ echo "${PROG}: Error: $*" 1>&2 } +# Replace the characters of the report that have special +# meaning in XML with the predefined entity references +clear_xml() +{ + local istag= + local linenumber=0 + while read line; do + istag='false' + linenumber=$((linenumber+1)) + echo "${line}" | egrep "${tags}" > /dev/null + if [ $? -eq 0 ]; then + istag='true' + fi + if [ "${istag}" == 'false' ]; then + echo "${line}" | grep '[&<>]' > /dev/null + if [ $? -eq 0 ]; then + sed -i '' "${linenumber}s/</\</g" ${data} + fi + fi + done < ${data} +} + # Default dump directory DUMPDIR='/var/crash' @@ -126,7 +148,7 @@ fi fi -# Check if the given email address is valid based on its format. +# Check if the given email address is valid based on its format echo "${_email}" | egrep '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$' \ > /dev/null 2>&1 @@ -138,14 +160,16 @@ ## 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" +tags="(<?xml)|(<crashreport>)|(<header>)|(<type>)|(</type>)|(<email>)\ +|(</email>)|(</header>)|(<body>)|(<command>)|(<name>)|(</name>)|(<result>)\ +|(</result>)|(</command>)|(</body>)|(</crashreport>)" start=3 +orig_IFS="${IFS}" +IFS=";" echo "<?xml version='1.0' encoding='UTF-8'?>" > ${data} echo "<crashreport>" >> ${data} @@ -172,7 +196,10 @@ echo "<body>" >> ${data} if [ "${type}" == 'vmcore' ]; then - # For: date, hostname, ostype, osrelease, version, machine + # A temporary-auxiliary file for the extraction + tmp_file=`mktemp /tmp/crashreport.XXXXXX` + + # For date, hostname, ostype, osrelease, version, machine for cmd in $commands1; do echo "<command>" >> ${data} echo "<name>" >> ${data} @@ -185,7 +212,7 @@ echo "</command>" >> ${data} done - # Panic Message (panic) + # Panic Message echo "<command>" >> ${data} echo "<name>" >> ${data} echo "panic" >> ${data} @@ -197,7 +224,7 @@ echo "</result>" >> ${data} echo "</command>" >> ${data} - # Backtrace (bt from kgdb) + # Backtrace echo "<command>" >> ${data} echo "<name>" >> ${data} echo "backtrace" >> ${data} @@ -227,7 +254,7 @@ echo "</result>" >> ${data} echo "</command>" >> ${data} - # From ps -axl until end + # For ps -axl until end for cmd in $commands2; do echo "<command>" >> ${data} echo "<name>" >> ${data} @@ -242,10 +269,13 @@ echo "</result>" >> ${data} echo "</command>" >> ${data} done + + clear_xml + rm "${tmp_file}" else # A temporary directory for the contents of the textdump tmp_dir=`mktemp -d /tmp/crashreport.XXXXXX` - tar -xvf "${_dumpdir}/${_file}" -C "${tmp_dir}" + tar -xf "${_dumpdir}/${_file}" -C "${tmp_dir}" # A valid textdump can contain up to 5 files with the following names: # ddb.txt, config.txt, msgbuf.txt, panic.txt and version.txt @@ -255,7 +285,7 @@ while read line; do echo "${line}" | egrep '^.+> [a-z ]+$' > /dev/null if [ $? -eq 0 ]; then - if [ ${flag} == false ]; then + if [ "${flag}" == false ]; then flag='true' echo "<command>" >> ${data} echo "<name>" >> ${data} @@ -276,7 +306,7 @@ else echo "${line}" >> ${data} fi - done < ${orig_file} + done < "${tmp_dir}/ddb.txt" echo "</result>" >> ${data} echo "</command>" >> ${data} fi @@ -324,7 +354,8 @@ echo "</result>" >> ${data} echo "</command>" >> ${data} fi - + + clear_xml rm -r "${tmp_dir}" fi @@ -346,7 +377,7 @@ exit 1 fi -rm -f "${data}" "${tmp_file}" +rm -f "${data}" ## Send the report to the Central Collector machine
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120630140845.24C101065696>