Skip to content

Commit

Permalink
Merge pull request #640 from sosy-lab/improvements_windows_support
Browse files Browse the repository at this point in the history
Avoid crash of benchexec on Windows due to SIGUSR1.
  • Loading branch information
PhilippWendler authored Oct 19, 2020
2 parents ee95c8a + 3052059 commit 0207553
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 1 addition & 4 deletions benchexec/benchexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import datetime
import logging
import os
import signal
import sys

from benchexec import __version__
Expand Down Expand Up @@ -475,9 +474,7 @@ def signal_stop(signum, frame):

# Handle termination-request signals that are available on the current platform
for signal_name in ["SIGINT", "SIGQUIT", "SIGTERM", "SIGBREAK"]:
sig = getattr(signal, signal_name, None)
if sig:
signal.signal(sig, signal_stop)
util.try_set_signal_handler(signal_name, signal_stop)

sys.exit(benchexec.start(argv or sys.argv))
except BenchExecException as e:
Expand Down
14 changes: 12 additions & 2 deletions benchexec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@ def kill_process(pid, sig=None):
)


def try_set_signal_handler(signal_name, handler):
"""
Set signal handler like signal.signal(), but only if signal name exists on this
platform. Signal name must be a string starting with "SIG".
"""
sig = getattr(_signal, signal_name, None)
if sig:
_signal.signal(sig, handler)


def dummy_fn(*args, **kwargs):
"""Dummy function that accepts all parameters but does nothing."""
pass
Expand Down Expand Up @@ -704,9 +714,9 @@ def _debug_current_process(sig, current_frame):

def activate_debug_shell_on_signal():
"""Install a signal handler for USR1 that dumps stack traces
and gives an interactive debugging shell.
and gives an interactive debugging shell. Does nothing on Windows.
"""
_signal.signal(_signal.SIGUSR1, _debug_current_process) # Register handler
try_set_signal_handler("SIGUSR1", _debug_current_process)


def get_capability(filename):
Expand Down

0 comments on commit 0207553

Please sign in to comment.