3 # Copyright (C) 2008-2017 Team XBMC
6 # This Program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This Program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with XBMC; see the file COPYING. If not, write to
18 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 bin_name
=@APP_NAME_LC@
25 exec_prefix
="@exec_prefix@"
26 datarootdir
="@datarootdir@"
28 APP_BINARY
=$LIBDIR/${bin_name}/@APP_BINARY@
29 CRASHLOG_DIR
=${CRASHLOG_DIR:-$HOME}
30 KODI_DATA
=${KODI_DATA:-"${HOME}/.${bin_name}"} # mapped to special://home/
32 # Workaround for high CPU load with nvidia GFX
33 export __GL_YIELD
=USLEEP
35 # Fix wasting RAM due to fragmentation
36 export MALLOC_MMAP_THRESHOLD_
=131072
38 # Check for some options used by this script
39 while [ "$#" -gt "0" ]
52 KODI_BINARY
=${APP_BINARY}
54 if [ ! -x ${KODI_BINARY} ]; then
55 echo "Error: ${KODI_BINARY} not found"
59 APPORT_CORE
="/var/crash/$(echo -n ${KODI_BINARY}|tr / _).$(id -u).crash"
63 command -pv $1 >/dev
/null
2>&1
68 # core filename is either "core.$PID" or "core"
69 find "$1" -maxdepth $2 -name 'core*' |
while read core
; do
70 LC_ALL
=C gdb
--core="$core" --batch 2> /dev
/null |
grep -q "^Core was generated by \`${KODI_BINARY}" ||
continue
71 echo "=====> Core file: "$core" ($(stat -c%y "$core"))" >> $FILE
72 echo " =========================================" >> $FILE
73 gdb
"${KODI_BINARY}" --core="$core" --batch -ex "thread apply all bt" 2> /dev
/null
>> $FILE
80 FILE
="$CRASHLOG_DIR/${bin_name}_crashlog-`date +%Y%m%d_%H%M%S`.log"
81 echo "############## $APP CRASH LOG ###############" >> $FILE
83 echo "################ SYSTEM INFO ################" >> $FILE
84 printf " Date: " >> $FILE
86 echo " $APP Options: $*" >> $FILE
87 printf " Arch: " >> $FILE
89 printf " Kernel: " >> $FILE
91 printf " Release: " >> $FILE
92 if [ -f /etc
/os-release
]; then
94 echo $NAME $VERSION >> $FILE
95 elif command_exists lsb_release
; then
97 lsb_release
-a 2> /dev
/null |
sed -e 's/^/ /' >> $FILE
99 echo "lsb_release not available" >> $FILE
101 echo "############## END SYSTEM INFO ##############" >> $FILE
103 echo "############### STACK TRACE #################" >> $FILE
104 if command_exists gdb
; then
105 if command_exists systemd-coredumpctl
; then
106 systemd-coredumpctl dump
-o core $
(basename ${KODI_BINARY}) > /dev
/null
2>&1
107 elif command_exists coredumpctl
; then
108 coredumpctl dump
-o core $
(basename ${KODI_BINARY}) > /dev
/null
2>&1
109 elif command_exists apport-unpack
&& test -f "${APPORT_CORE}"; then
110 TMP_DIR
="$(mktemp -d -p ${HOME})"
111 if [ -d "${TMP_DIR}" ]; then
113 apport-unpack
"${APPORT_CORE}" "${TMP_DIR}"
114 mv "${TMP_DIR}/CoreDump" "${HOME}/core"
118 single_stacktrace
"$PWD" 1
119 # Find in plugins directories
120 if [ $KODI_HOME ]; then
123 BASEDIR
="$LIBDIR/${bin_name}/"
125 single_stacktrace
"$BASEDIR" 5
126 # find in userdata dir
127 single_stacktrace
"$HOME" 5
128 # try /proc/sys/kernel/core_pattern
129 # Check if it does not contain a pipe to a program (see man 5 core)
130 if [ "$(cat /proc/sys/kernel/core_pattern | cut -c 1)" != "|" ]; then
131 [ -d "$(dirname $(cat /proc/sys/kernel/core_pattern))" ] && single_stacktrace
"$(dirname $(cat /proc/sys/kernel/core_pattern))" 1
134 echo "gdb not installed, can't get stack trace." >> $FILE
136 echo "############# END STACK TRACE ###############" >> $FILE
138 echo "################# LOG FILE ##################" >> $FILE
140 if [ -f $KODI_TEMP/@APP_NAME_LC@.log
]
142 cat $KODI_TEMP/@APP_NAME_LC@.log
>> $FILE
144 elif [ -f $KODI_DATA/temp
/@APP_NAME_LC@.log
]
146 cat $KODI_DATA/temp
/@APP_NAME_LC@.log
>> $FILE
149 echo "Logfile not found in the usual place." >> $FILE
150 echo "Please attach it separately." >> $FILE
151 echo "Use pastebin.com or similar for forums or IRC." >> $FILE
154 echo "############### END LOG FILE ################" >> $FILE
156 echo "############ END $APP CRASH LOG #############" >> $FILE
157 echo "Crash report available at $FILE"
160 propagate_sigterm
() {
161 kill -TERM "$CHILD" 2>/dev
/null
164 trap propagate_sigterm TERM
166 if command_exists gdb
; then
167 # Output warning in case ulimit is unsupported by shell
168 eval ulimit -c unlimited
169 if [ ! $?
= "0" ]; then
170 echo "${bin_name}: ulimit is unsupported by this shell" 1>&2
175 while [ $
(( $LOOP )) = "1" ]
177 [ -f "${APPORT_CORE}" ] && rm -f "${APPORT_CORE}"
179 ${KODI_BINARY} $SAVED_ARGS &
183 if [ $
(( $RET == 65 )) = "1" ]
184 then # User requested to restart app
186 elif [ $
(( ($RET >= 131 && $RET <= 136) ||
$RET == 139 )) = "1" ]
187 then # Crashed with core dump