kodev: Avoid catchsegv via -S, --no-catchsegv (#7044)

This works around #7036 on my end (so far).

* Turns out we can actually ask os.exit to close the Lua state, wheee!
Thanks @Frenzie ;).
reviewable/pr7048/r1
NiLuJe 3 years ago committed by GitHub
parent 39c60ada20
commit 7bc8ed87d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

28
kodev

@ -621,7 +621,7 @@ OPTIONS:
-p, --graph graph memory use (requires gnuplot) -p, --graph graph memory use (requires gnuplot)
-v X, --valgrind=X run with valgrind (default: \"valgrind --tool=memcheck --trace-children=yes --leak-check=full --track-origins=yes --show-reachable=yes\") -v X, --valgrind=X run with valgrind (default: \"valgrind --tool=memcheck --trace-children=yes --leak-check=full --track-origins=yes --show-reachable=yes\")
-c, --callgrind run with valgrind's callgrind (valgrind --tool=callgrind --trace-children=yes) -c, --callgrind run with valgrind's callgrind (valgrind --tool=callgrind --trace-children=yes)
-r, --sane-return force KOReader to exit sanely, instead of calling os.exit. This ensures a saner teardown of the Lua state. (enabled by default when running under valgrind/gdb). -S, --no-catchsegv prevents wrapping by catchsegv
TARGET: TARGET:
@ -638,8 +638,8 @@ TARGET:
declare opt declare opt
declare -r E_OPTERR=85 declare -r E_OPTERR=85
declare -r short_opts="tbng::pv::cw:h:d:s:rH" declare -r short_opts="tbng::pv::cw:h:d:s:SH"
declare -r long_opts="disable-touch,no-build,gdb::,graph,valgrind::,callgrind,screen-width:,screen-height:,screen-dpi:,simulate:,sane-return,help" declare -r long_opts="disable-touch,no-build,gdb::,graph,valgrind::,callgrind,screen-width:,screen-height:,screen-dpi:,simulate:,no-catchsegv,help"
if ! opt=$(getopt -o "${short_opts}" --long "${long_opts}" --name "kodev" -- "${@}"); then if ! opt=$(getopt -o "${short_opts}" --long "${long_opts}" --name "kodev" -- "${@}"); then
echo "${RUN_HELP_MSG}" echo "${RUN_HELP_MSG}"
@ -663,7 +663,6 @@ TARGET:
export KODEBUG= export KODEBUG=
;; ;;
-g | --gdb) -g | --gdb)
export SANE_RETURN=1
if [ -n "${VALUE}" ]; then if [ -n "${VALUE}" ]; then
gdb="${VALUE}" gdb="${VALUE}"
else else
@ -691,7 +690,6 @@ TARGET:
graph_memory=1 graph_memory=1
;; ;;
-v | --valgrind) -v | --valgrind)
export SANE_RETURN=1
if [ -n "${VALUE}" ]; then if [ -n "${VALUE}" ]; then
valgrind="${VALUE}" valgrind="${VALUE}"
else else
@ -706,7 +704,6 @@ TARGET:
shift shift
;; ;;
-c | --callgrind) -c | --callgrind)
export SANE_RETURN=1
# Try to use sensible defaults for valgrind # Try to use sensible defaults for valgrind
if command -v valgrind >/dev/null; then if command -v valgrind >/dev/null; then
valgrind="valgrind --tool=callgrind --trace-children=yes" valgrind="valgrind --tool=callgrind --trace-children=yes"
@ -778,8 +775,8 @@ TARGET:
esac esac
shift shift
;; ;;
-r | --sane-return) -S | --no-catchsegv)
export SANE_RETURN=1 no_catchsegv=1
;; ;;
-H | --help) -H | --help)
echo "${RUN_HELP_MSG}" echo "${RUN_HELP_MSG}"
@ -841,18 +838,15 @@ TARGET:
gnuplot_wrapper "--parent $$" "reader.lua" gnuplot_wrapper "--parent $$" "reader.lua"
fi fi
if [ -n "${SANE_RETURN}" ]; then KOREADER_ARGS="-d"
KOREADER_ARGS="-d -t"
else
KOREADER_ARGS="-d"
fi
KOREADER_COMMAND="env LD_LIBRARY_PATH=${KO_LD_LIBRARY_PATH} ./reader.lua ${KOREADER_ARGS}" KOREADER_COMMAND="env LD_LIBRARY_PATH=${KO_LD_LIBRARY_PATH} ./reader.lua ${KOREADER_ARGS}"
# run with catchsegv by default when it is available # run with catchsegv by default when it is available (unless no-catchsegv is enabled, c.f., #7036)
# see https://github.com/koreader/koreader/issues/2878#issuecomment-326796777 # see https://github.com/koreader/koreader/issues/2878#issuecomment-326796777
if command -v catchsegv >/dev/null; then if [ -z "${no_catchsegv}" ]; then
KOREADER_COMMAND="$(command -v catchsegv) ${KOREADER_COMMAND}" if command -v catchsegv >/dev/null; then
KOREADER_COMMAND="$(command -v catchsegv) ${KOREADER_COMMAND}"
fi
fi fi
if [ -n "${valgrind}" ]; then if [ -n "${valgrind}" ]; then

@ -65,7 +65,6 @@ local longopts = {
debug = "d", debug = "d",
verbose = "d", verbose = "d",
profile = "p", profile = "p",
teardown = "t",
help = "h", help = "h",
} }
@ -76,7 +75,6 @@ local function showusage()
print("-d start in debug mode") print("-d start in debug mode")
print("-v debug in verbose mode") print("-v debug in verbose mode")
print("-p enable Lua code profiling") print("-p enable Lua code profiling")
print("-t teardown via a return instead of calling os.exit")
print("-h show this usage help") print("-h show this usage help")
print("") print("")
print("If you give the name of a directory instead of a file path, a file") print("If you give the name of a directory instead of a file path, a file")
@ -89,7 +87,6 @@ local function showusage()
end end
local Profiler = nil local Profiler = nil
local sane_teardown
local ARGV = arg local ARGV = arg
local argidx = 1 local argidx = 1
while argidx <= #ARGV do while argidx <= #ARGV do
@ -111,8 +108,6 @@ while argidx <= #ARGV do
elseif arg == "-p" then elseif arg == "-p" then
Profiler = require("jit.p") Profiler = require("jit.p")
Profiler.start("la") Profiler.start("la")
elseif arg == "-t" then
sane_teardown = true
else else
-- not a recognized option, should be a filename -- not a recognized option, should be a filename
argidx = argidx - 1 argidx = argidx - 1
@ -353,18 +348,10 @@ local function exitReader()
if type(exit_code) == "number" then if type(exit_code) == "number" then
return exit_code return exit_code
else else
return 0 return true
end end
end end
local ret = exitReader() local ret = exitReader()
-- Close the Lua state on exit
if not sane_teardown then os.exit(ret, true)
os.exit(ret)
else
-- NOTE: We can unfortunately not return with a custom exit code...
-- But since this should only really be used on the emulator,
-- to ensure a saner teardown of ressources when debugging,
-- it's not a great loss...
return
end

Loading…
Cancel
Save