Skip to content

Commit

Permalink
Exit with proper exit code
Browse files Browse the repository at this point in the history
For each signal there is a reserved exit code:
http://www.tldp.org/LDP/abs/html/exitcodes.html

The signal numbers can be found here:
http://man7.org/linux/man-pages/man7/signal.7.html
  • Loading branch information
Gyorgy Orban committed Jul 3, 2019
1 parent bc6a5e6 commit cb68285
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions analyzer/codechecker_analyzer/analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ def start_workers(actions_map, actions, context, analyzer_config_map,
"""

# Handle SIGINT to stop this script running.
def signal_handler(*arg, **kwarg):
def signal_handler(signum, frame):
try:
pool.terminate()
manager.shutdown()
finally:
sys.exit(1)
sys.exit(128 + signum)

signal.signal(signal.SIGINT, signal_handler)

Expand Down
4 changes: 2 additions & 2 deletions analyzer/codechecker_analyzer/analyzers/analyzer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def run_proc(command, env=None, cwd=None, proc_callback=None):
and the stdout and stderr outputs of the process.
"""

def signal_handler(*args, **kwargs):
def signal_handler(signum, frame):
# Clang does not kill its child processes, so I have to.
try:
g_pid = proc.pid
os.killpg(g_pid, signal.SIGTERM)
finally:
sys.exit(os.EX_OK)
sys.exit(128 + signum)

signal.signal(signal.SIGINT, signal_handler)

Expand Down
4 changes: 2 additions & 2 deletions analyzer/codechecker_analyzer/pre_analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def run_pre_analysis(actions, context, analyzer_config_map,
if statistics_data:
LOG.info("Collecting data for statistical analysis.")

def signal_handler(*arg, **kwarg):
def signal_handler(signum, frame):
try:
pool.terminate()
manager.shutdown()
finally:
sys.exit(1)
sys.exit(128 + signum)

signal.signal(signal.SIGINT, signal_handler)

Expand Down
4 changes: 2 additions & 2 deletions bin/CodeChecker
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ def main(subcommand=None):
print('Saving original build environment failed.')
print(ex)

def signal_term_handler(sig, frame):
def signal_term_handler(signum, frame):
global proc_pid
if proc_pid:
os.kill(proc_pid, signal.SIGINT)

_remove_tmp()
sys.exit(0)
sys.exit(128 + signum)

signal.signal(signal.SIGTERM, signal_term_handler)
signal.signal(signal.SIGINT, signal_term_handler)
Expand Down
4 changes: 2 additions & 2 deletions bin/CodeChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def main(subcommands=None):
CodeChecker main command line.
"""

def signal_handler(sig, frame):
def signal_handler(signum, frame):
"""
Without this handler the PostgreSQL
server does not terminate at signal.
"""
sys.exit(1)
sys.exit(128 + signum)

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
Expand Down
3 changes: 2 additions & 1 deletion scripts/test/run_server_performance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ def finish_test(signum, frame):
pass

stat.print_stats(args.output)
sys.exit("Performance test has timed out or killed.")
print("Performance test has timed out or killed.")
sys.exit(128 + signum)

signal.signal(signal.SIGINT, finish_test)

Expand Down
4 changes: 2 additions & 2 deletions web/server/codechecker_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,15 +1002,15 @@ def start_server(config_directory, package_data, port, config_sql_server,
check_env,
manager)

def signal_handler(*args, **kwargs):
def signal_handler(signum, frame):
"""
Handle SIGTERM to stop the server running.
"""
LOG.info("Shutting down the WEB server on [%s:%d].",
listen_address, port)

http_server.terminate()
sys.exit(0)
sys.exit(128 + signum)

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

0 comments on commit cb68285

Please sign in to comment.