[Subtitles] Partial fix for text/border color gap
[xbmc.git] / tools / Linux / kodi.sh.in
blob108c0b007b80205457d1396b625fd9120e8847bc
1 #!/bin/sh
3 # Copyright (C) 2008-2017 Team XBMC
4 # http://kodi.tv
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)
9 # any later version.
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
21 APP=@APP_NAME@
22 bin_name=@APP_NAME_LC@
23 SAVED_ARGS="$@"
24 prefix="@prefix@"
25 exec_prefix="@exec_prefix@"
26 datarootdir="@datarootdir@"
27 LIBDIR="@libdir@"
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" ]
41 case "$1" in
42 --setlibdir)
43 LIBDIR="$2"
44 shift; shift
47 shift
49 esac
50 done
52 KODI_BINARY=${APP_BINARY}
54 if [ ! -x ${KODI_BINARY} ]; then
55 echo "Error: ${KODI_BINARY} not found"
56 exit 2
59 APPORT_CORE="/var/crash/$(echo -n ${KODI_BINARY}|tr / _).$(id -u).crash"
61 command_exists()
63 command -pv $1 >/dev/null 2>&1
66 single_stacktrace()
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
74 rm -f "$core"
75 done
78 print_crash_report()
80 FILE="$CRASHLOG_DIR/${bin_name}_crashlog-`date +%Y%m%d_%H%M%S`.log"
81 echo "############## $APP CRASH LOG ###############" >> $FILE
82 echo >> $FILE
83 echo "################ SYSTEM INFO ################" >> $FILE
84 printf " Date: " >> $FILE
85 date >> $FILE
86 echo " $APP Options: $*" >> $FILE
87 printf " Arch: " >> $FILE
88 uname -m >> $FILE
89 printf " Kernel: " >> $FILE
90 uname -rvs >> $FILE
91 printf " Release: " >> $FILE
92 if [ -f /etc/os-release ]; then
93 . /etc/os-release
94 echo $NAME $VERSION >> $FILE
95 elif command_exists lsb_release; then
96 echo >> $FILE
97 lsb_release -a 2> /dev/null | sed -e 's/^/ /' >> $FILE
98 else
99 echo "lsb_release not available" >> $FILE
101 echo "############## END SYSTEM INFO ##############" >> $FILE
102 echo >> $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
112 rm -f "${HOME}/core"
113 apport-unpack "${APPORT_CORE}" "${TMP_DIR}"
114 mv "${TMP_DIR}/CoreDump" "${HOME}/core"
115 rm -rf "${TMP_DIR}"
118 single_stacktrace "$PWD" 1
119 # Find in plugins directories
120 if [ $KODI_HOME ]; then
121 BASEDIR=$KODI_HOME
122 else
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
133 else
134 echo "gdb not installed, can't get stack trace." >> $FILE
136 echo "############# END STACK TRACE ###############" >> $FILE
137 echo >> $FILE
138 echo "################# LOG FILE ##################" >> $FILE
139 echo >> $FILE
140 if [ -f $KODI_TEMP/@APP_NAME_LC@.log ]
141 then
142 cat $KODI_TEMP/@APP_NAME_LC@.log >> $FILE
143 echo >> $FILE
144 elif [ -f $KODI_DATA/temp/@APP_NAME_LC@.log ]
145 then
146 cat $KODI_DATA/temp/@APP_NAME_LC@.log >> $FILE
147 echo >> $FILE
148 else
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
153 echo >> $FILE
154 echo "############### END LOG FILE ################" >> $FILE
155 echo >> $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
174 LOOP=1
175 while [ $(( $LOOP )) = "1" ]
177 [ -f "${APPORT_CORE}" ] && rm -f "${APPORT_CORE}"
178 LOOP=0
179 ${KODI_BINARY} $SAVED_ARGS &
180 CHILD=$!
181 wait "${CHILD}"
182 RET=$?
183 if [ $(( $RET == 65 )) = "1" ]
184 then # User requested to restart app
185 LOOP=1
186 elif [ $(( ($RET >= 131 && $RET <= 136) || $RET == 139 )) = "1" ]
187 then # Crashed with core dump
188 print_crash_report
190 done
192 exit $RET