collect_metadata() {
# Collect metadata information using apport's crash file format.
# See http://bazaar.launchpad.net/~apport-hackers/apport/trunk/view/head:/doc/data-format.tex
local coredump_file="$1"
. /etc/os-release
local executable_path=$(readlink /proc/$PID/exe)
local package=$(dpkg -S $executable_path | sed -s 's/:.*$//')
local package_version=$(dpkg -s $package | sed -n 's/Version: //p')
if dpkg -s $package | grep -q '^Source:'; then
local source_package=$(dpkg -s $package | sed -n 's/Source: //p')
else
local source_package=$package
fi
local dependencies=$(apt-cache --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances --recurse --installed depends ${package}=${package_version} | sed -n 's/.*: //p' | sort | uniq)
cat <<EOF
ProblemType: Crash
Architecture: $(dpkg --print-architecture)
Date: $(date -d @$TIMESTAMP -R)
DistroRelease: ${NAME} ${VERSION_ID}
ExecutablePath: ${executable_path}
Package: ${package} ${package_version}
SourcePackage: ${source_package}
ProcCmdline: $(sed 's/ /\\ /g' /proc/$PID/cmdline | tr '\0' ' ' | sed 's/ *$//')
Signal: ${SIGNAL}
Uname: $(uname -srm)
CoreDumpFile: ${coredump_file##*/}
Dependencies:
$(dpkg-query -f=' ${Package} ${Version}\n' -W $dependencies)
ProcStatus:
$(sed 's/^/ /' /proc/$PID/status)
ProcMaps:
$(sed 's/^/ /' /proc/$PID/maps)
EOF
}