/tools/Linux/xbmc.sh.in

https://github.com/Giftie/xbmc · Autoconf · 146 lines · 114 code · 9 blank · 23 comment · 18 complexity · 9dcce03e6334339a85e4ade5d205324e MD5 · raw file

  1. #!/bin/sh
  2. # Copyright (C) 2008-2013 Team XBMC
  3. # http://xbmc.org
  4. #
  5. # This Program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # any later version.
  9. #
  10. # This Program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with XBMC; see the file COPYING. If not, write to
  17. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. # http://www.gnu.org/copyleft/gpl.html
  19. SAVED_ARGS="$@"
  20. prefix="@prefix@"
  21. exec_prefix="@exec_prefix@"
  22. datarootdir="@datarootdir@"
  23. LIBDIR="@libdir@"
  24. CRASHLOG_DIR=${CRASHLOG_DIR:-$HOME}
  25. # Check for some options used by this script
  26. while [ "$#" -gt "0" ]
  27. do
  28. case "$1" in
  29. --setlibdir)
  30. LIBDIR="$2"
  31. shift; shift
  32. ;;
  33. *)
  34. shift
  35. ;;
  36. esac
  37. done
  38. single_stacktrace()
  39. {
  40. # core filename is either "core.$PID" or "core"
  41. find "$1" -maxdepth $2 -name 'core*' | while read core; do
  42. LC_ALL=C gdb --core="$core" --batch 2> /dev/null | grep -q "^Core was generated by \`$LIBDIR/xbmc/xbmc.bin" || continue
  43. echo "=====> Core file: "$core" ($(stat -c%y "$core"))" >> $FILE
  44. echo " =========================================" >> $FILE
  45. gdb "$LIBDIR/xbmc/xbmc.bin" --core="$core" --batch -ex "thread apply all bt" 2> /dev/null >> $FILE
  46. rm -f "$core"
  47. done
  48. }
  49. print_crash_report()
  50. {
  51. FILE="$CRASHLOG_DIR/xbmc_crashlog-`date +%Y%m%d_%H%M%S`.log"
  52. echo "############## XBMC CRASH LOG ###############" >> $FILE
  53. echo >> $FILE
  54. echo "################ SYSTEM INFO ################" >> $FILE
  55. echo -n " Date: " >> $FILE
  56. date >> $FILE
  57. echo " XBMC Options: $*" >> $FILE
  58. echo -n " Arch: " >> $FILE
  59. uname -m >> $FILE
  60. echo -n " Kernel: " >> $FILE
  61. uname -rvs >> $FILE
  62. echo -n " Release: " >> $FILE
  63. if [ -f /etc/os-release ]; then
  64. . /etc/os-release
  65. echo $NAME $VERSION >> $FILE
  66. elif which lsb_release > /dev/null; then
  67. echo >> $FILE
  68. lsb_release -a 2> /dev/null | sed -e 's/^/ /' >> $FILE
  69. else
  70. echo "lsb_release not available" >> $FILE
  71. fi
  72. echo "############## END SYSTEM INFO ##############" >> $FILE
  73. echo >> $FILE
  74. echo "############### STACK TRACE #################" >> $FILE
  75. if which gdb >/dev/null 2>&1; then
  76. if which systemd-coredumpctl &> /dev/null; then
  77. systemd-coredumpctl dump -o core xbmc.bin &> /dev/null
  78. fi
  79. single_stacktrace "$PWD" 1
  80. # Find in plugins directories
  81. if [ $XBMC_HOME ]; then
  82. BASEDIR=$XBMC_HOME
  83. else
  84. BASEDIR="$LIBDIR/xbmc/"
  85. fi
  86. single_stacktrace "$BASEDIR" 5
  87. # find in user xbmc dir
  88. single_stacktrace $HOME/.xbmc/ 5
  89. else
  90. echo "gdb not installed, can't get stack trace." >> $FILE
  91. fi
  92. echo "############# END STACK TRACE ###############" >> $FILE
  93. echo >> $FILE
  94. echo "################# LOG FILE ##################" >> $FILE
  95. echo >> $FILE
  96. if [ -f ~/.xbmc/temp/xbmc.log ]
  97. then
  98. cat ~/.xbmc/temp/xbmc.log >> $FILE
  99. echo >> $FILE
  100. else
  101. echo "Logfile not found in the usual place." >> $FILE
  102. echo "Please attach it seperately." >> $FILE
  103. echo "Use pastebin.com or similar for forums or IRC." >> $FILE
  104. fi
  105. echo >> $FILE
  106. echo "############### END LOG FILE ################" >> $FILE
  107. echo >> $FILE
  108. echo "############ END XBMC CRASH LOG #############" >> $FILE
  109. echo "Crash report available at $FILE"
  110. }
  111. python @datadir@/xbmc/FEH.py $SAVED_ARGS
  112. RET=$?
  113. if [ $RET -ne 0 ]; then
  114. exit $RET
  115. fi
  116. if which gdb >/dev/null 2>&1; then
  117. # Output warning in case ulimit is unsupported by shell
  118. eval ulimit -c unlimited
  119. if [ ! $? = "0" ]; then
  120. echo "xbmc: ulimit is unsupported by this shell" 1>&2
  121. fi
  122. fi
  123. LOOP=1
  124. while [ $(( $LOOP )) = "1" ]
  125. do
  126. LOOP=0
  127. "$LIBDIR/xbmc/xbmc.bin" $SAVED_ARGS
  128. RET=$?
  129. if [ $(( $RET == 65 )) = "1" ]
  130. then # User requested to restart app
  131. LOOP=1
  132. elif [ $(( ($RET >= 131 && $RET <= 136) || $RET == 139 )) = "1" ]
  133. then # Crashed with core dump
  134. print_crash_report
  135. fi
  136. done
  137. exit $RET