Skip to content
Permalink
Browse files

Merge pull request #2645 from psyke83/joy2key_exception_fix

joy2key: fix sys.exit() by avoiding naked exceptions
  • Loading branch information...
joolswills committed Mar 11, 2019
2 parents 37b53c1 + f614804 commit 8a11e00b9e3da01ed2cf32e45ce49cdcb36aa4a9
@@ -44,6 +44,7 @@ function printHeading() {
function fatalError() {
printHeading "Error"
echo -e "$1"
joy2keyStop
exit 1
}

@@ -1043,9 +1044,8 @@ function joy2keyStart() {
[[ -z "$__joy2key_dev" ]] || pgrep -f joy2key.py >/dev/null && return 1
# if joy2key.py is installed run it with cursor keys for axis/dpad, and enter + space for buttons 0 and 1
if "$scriptdir/scriptmodules/supplementary/runcommand/joy2key.py" "$__joy2key_dev" "${params[@]}" & 2>/dev/null; then
if __joy2key_ppid=$$ "$scriptdir/scriptmodules/supplementary/runcommand/joy2key.py" "$__joy2key_dev" "${params[@]}" & 2>/dev/null; then
__joy2key_pid=$!
sleep 1
return 0
fi
@@ -1056,8 +1056,7 @@ function joy2keyStart() {
## @brief Stop previously started joy2key.py process.
function joy2keyStop() {
if [[ -n $__joy2key_pid ]]; then
kill -INT $__joy2key_pid 2>/dev/null
sleep 1
kill $__joy2key_pid 2>/dev/null
fi
}
@@ -125,13 +125,14 @@ def get_button_codes(dev_path):
if btn_codes[btn_num['a']] == '\n' and ini_get('menu_swap_ok_cancel_buttons', RETROARCH_CFG) == 'true':
btn_codes[btn_num['a']] = btn_codes[btn_num['b']]
btn_codes[btn_num['b']] = '\n'
except:
except ValueError:
pass

return btn_codes

def signal_handler(signum, frame):
close_fds(js_fds)
if (js_fds):
close_fds(js_fds)
sys.exit(0)

def get_hex_chars(key_str):
@@ -159,7 +160,7 @@ def open_devices():
try:
fds.append(os.open(dev, os.O_RDONLY | os.O_NONBLOCK ))
js_button_codes[fds[-1]] = get_button_codes(dev)
except:
except (OSError, ValueError):
pass

return devs, fds
@@ -214,6 +215,7 @@ def process_event(event):
return False

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

js_button_codes = {}
button_codes = []
@@ -235,14 +237,15 @@ def process_event(event):
event_size = struct.calcsize(event_format)

try:
tty_fd = open('/dev/tty', 'w')
except:
tty_fd = open('/dev/tty', 'a')
except IOError:
print 'Unable to open /dev/tty'
sys.exit(1)

js_fds = []
rescan_time = time.time()
while True:
prev_parent = int(os.getenv("__joy2key_ppid", os.getppid()))
while prev_parent == os.getppid():
do_sleep = True
if not js_fds:
js_devs, js_fds = open_devices()
@@ -282,3 +285,5 @@ def process_event(event):

if do_sleep:
time.sleep(0.01)

signal_handler(0, 0)
@@ -115,14 +115,14 @@ function start_joy2key() {

# call joy2key.py: arguments are curses capability names or hex values starting with '0x'
# see: http://pubs.opengroup.org/onlinepubs/7908799/xcurses/terminfo.html
"$ROOTDIR/supplementary/runcommand/joy2key.py" "$JOY2KEY_DEV" kcub1 kcuf1 kcuu1 kcud1 0x0a 0x09 &
__joy2key_ppid=$$ "$ROOTDIR/supplementary/runcommand/joy2key.py" "$JOY2KEY_DEV" kcub1 kcuf1 kcuu1 kcud1 0x0a 0x09 &
JOY2KEY_PID=$!
fi
}

function stop_joy2key() {
if [[ -n "$JOY2KEY_PID" ]]; then
kill -INT "$JOY2KEY_PID"
kill "$JOY2KEY_PID"
fi
}

@@ -595,6 +595,7 @@ function choose_emulator() {
done < <(sort "$EMU_SYS_CONF")
if [[ -z "${options[*]}" ]]; then
dialog --msgbox "No emulator options found for $SYSTEM - Do you have a valid $EMU_SYS_CONF ?" 20 60 >/dev/tty
stop_joy2key
exit 1
fi
local cmd=(dialog $cancel --default-item "$default_id" --menu "Choose default emulator" 22 76 16 )
@@ -846,6 +847,7 @@ function restore_governor() {
function get_sys_command() {
if [[ ! -f "$EMU_SYS_CONF" ]]; then
echo "No config found for system $SYSTEM"
stop_joy2key
exit 1
fi

0 comments on commit 8a11e00

Please sign in to comment.
You can’t perform that action at this time.