/tools/Linux/xbmc.sh.in

http://github.com/xbmc/xbmc · Autoconf · 145 lines · 113 code · 9 blank · 23 comment · 18 complexity · a8506b3c5cd65facdc1a92f63dd00e9b 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. # Check for some options used by this script
  25. while [ "$#" -gt "0" ]
  26. do
  27. case "$1" in
  28. --setlibdir)
  29. LIBDIR="$2"
  30. shift; shift
  31. ;;
  32. *)
  33. shift
  34. ;;
  35. esac
  36. done
  37. single_stacktrace()
  38. {
  39. # core filename is either "core.$PID" or "core"
  40. find "$1" -maxdepth $2 -name 'core*' | while read core; do
  41. LC_ALL=C gdb --core="$core" --batch 2> /dev/null | grep -q "^Core was generated by \`$LIBDIR/xbmc/xbmc.bin" || continue
  42. echo "=====> Core file: "$core" ($(stat -c%y "$core"))" >> $FILE
  43. echo " =========================================" >> $FILE
  44. gdb "$LIBDIR/xbmc/xbmc.bin" --core="$core" --batch -ex "thread apply all bt" 2> /dev/null >> $FILE
  45. rm -f "$core"
  46. done
  47. }
  48. print_crash_report()
  49. {
  50. FILE="$HOME/xbmc_crashlog-`date +%Y%m%d_%H%M%S`.log"
  51. echo "############## XBMC CRASH LOG ###############" >> $FILE
  52. echo >> $FILE
  53. echo "################ SYSTEM INFO ################" >> $FILE
  54. echo -n " Date: " >> $FILE
  55. date >> $FILE
  56. echo " XBMC Options: $*" >> $FILE
  57. echo -n " Arch: " >> $FILE
  58. uname -m >> $FILE
  59. echo -n " Kernel: " >> $FILE
  60. uname -rvs >> $FILE
  61. echo -n " Release: " >> $FILE
  62. if [ -f /etc/os-release ]; then
  63. . /etc/os-release
  64. echo $NAME $VERSION >> $FILE
  65. elif which lsb_release > /dev/null; then
  66. echo >> $FILE
  67. lsb_release -a 2> /dev/null | sed -e 's/^/ /' >> $FILE
  68. else
  69. echo "lsb_release not available" >> $FILE
  70. fi
  71. echo "############## END SYSTEM INFO ##############" >> $FILE
  72. echo >> $FILE
  73. echo "############### STACK TRACE #################" >> $FILE
  74. if which gdb >/dev/null 2>&1; then
  75. if which systemd-coredumpctl &> /dev/null; then
  76. systemd-coredumpctl dump -o core xbmc.bin &> /dev/null
  77. fi
  78. single_stacktrace "$PWD" 1
  79. # Find in plugins directories
  80. if [ $XBMC_HOME ]; then
  81. BASEDIR=$XBMC_HOME
  82. else
  83. BASEDIR="$LIBDIR/xbmc/"
  84. fi
  85. single_stacktrace "$BASEDIR" 5
  86. # find in user xbmc dir
  87. single_stacktrace $HOME/.xbmc/ 5
  88. else
  89. echo "gdb not installed, can't get stack trace." >> $FILE
  90. fi
  91. echo "############# END STACK TRACE ###############" >> $FILE
  92. echo >> $FILE
  93. echo "################# LOG FILE ##################" >> $FILE
  94. echo >> $FILE
  95. if [ -f ~/.xbmc/temp/xbmc.log ]
  96. then
  97. cat ~/.xbmc/temp/xbmc.log >> $FILE
  98. echo >> $FILE
  99. else
  100. echo "Logfile not found in the usual place." >> $FILE
  101. echo "Please attach it seperately." >> $FILE
  102. echo "Use pastebin.com or similar for forums or IRC." >> $FILE
  103. fi
  104. echo >> $FILE
  105. echo "############### END LOG FILE ################" >> $FILE
  106. echo >> $FILE
  107. echo "############ END XBMC CRASH LOG #############" >> $FILE
  108. echo "Crash report available at $FILE"
  109. }
  110. python @datadir@/xbmc/FEH.py $SAVED_ARGS
  111. RET=$?
  112. if [ $RET -ne 0 ]; then
  113. exit $RET
  114. fi
  115. if which gdb >/dev/null 2>&1; then
  116. # Output warning in case ulimit is unsupported by shell
  117. eval ulimit -c unlimited
  118. if [ ! $? = "0" ]; then
  119. echo "xbmc: ulimit is unsupported by this shell" 1>&2
  120. fi
  121. fi
  122. LOOP=1
  123. while [ $(( $LOOP )) = "1" ]
  124. do
  125. LOOP=0
  126. "$LIBDIR/xbmc/xbmc.bin" $SAVED_ARGS
  127. RET=$?
  128. if [ $(( $RET == 65 )) = "1" ]
  129. then # User requested to restart app
  130. LOOP=1
  131. elif [ $(( ($RET >= 131 && $RET <= 136) || $RET == 139 )) = "1" ]
  132. then # Crashed with core dump
  133. print_crash_report
  134. fi
  135. done
  136. exit $RET