-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-debug.sh
executable file
·83 lines (68 loc) · 2.34 KB
/
run-debug.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Debug OSTRICH using coredumps
# Based on: https://github.com/dreamcat4/docker-images/blob/master/tvh/README.md#debugging-tvheadend
_cleanup () {
if [ "$core_pattern_orig" ]; then
# Restore core path
echo "$core_pattern_orig" > /proc/sys/kernel/core_pattern
fi
exit 0
}
trap _cleanup TERM INT QUIT HUP
# Remember the folder ownership for later
crash_uid="$(stat -c %u /crash)"
crash_gid="$(stat -c %g /crash)"
crash_rwx="$(stat -c %a /crash)"
# Enable core dumps
ulimit -c unlimited
echo "Set: ulimit -c unlimited"
# Override core path
mkdir /crash_tmp
core_pattern_orig=$(cat /proc/sys/kernel/core_pattern)
core_pattern="/crash_tmp/%e-ostrich.t%t.core.new"
echo "$core_pattern" > /proc/sys/kernel/core_pattern
# Make sure our core files get saved as '/crash/core*'
if [ "$?" -ne "0" ]; then
echo "error: can't modify /proc/sys/kernel/core_pattern
Did you run this image with --privileged=true flag?"
fi
if [ "$(cat /proc/sys/kernel/core_pattern | grep -v -e '^/crash_tmp/.*.core.new')" ]; then
echo "error: the save path of core files is not /crash_tmp/.*.core.new
Aborting."
exit 1
fi
echo "Set: core_pattern=$core_pattern"
# Run ostrich
/opt/ostrich/build/cobra-evaluate $@
# Restore core path
echo "$core_pattern_orig" > /proc/sys/kernel/core_pattern
# Make log file
uname -a > "/crash/ostrich.log"
echo /opt/cobra/build/cobra-evaluate "$@" >> "/crash/ostrich.log"
# Exit cleanly if there was no segfault crash
cp /crash_tmp/* /crash
core_file_new="$(find /crash -name '*core.new*' | tail -n 1)"
if [ ! "$core_file_new" ]; then
# Restore original file ownership and permissions
chown -R ${crash_uid}:${crash_gid} /crash && chmod ${crash_rwx} /crash
exit 0
fi
echo "Discovered a crash!"
# Rename files so they don't conflict with other sessions
file_prefix="${core_file_new%.core.new.*}"
core_file="${file_prefix}.core"
mv "$core_file_new" "$core_file"
echo "
***********************************************************************
GDB Backtrace
***********************************************************************
"
echo "set logging on ${file_prefix}.gdb.txt
set pagination off
bt full" | gdb /opt/cobra/build/cobra-evaluate "$core_file"
echo "
***********************************************************************
"
# Restore original file ownership and permissions
chown -R ${crash_uid}:${crash_gid} /crash && chmod ${crash_rwx} /crash
exit 1