Skip to content

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
add sigint handler and cleanup on sigint
  • Loading branch information
tintinweb committed Oct 20, 2018
1 parent 82e3e78 commit 55a2127
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion utilities/fuzzer.py
Expand Up @@ -5,6 +5,7 @@
"""
import json, sys, os, time, collections, shutil
import signal
import argparse
import select
import docker
Expand Down Expand Up @@ -373,7 +374,7 @@ def __init__(self, config=None):
self._dockerclient = docker.from_env()

if config.docker_force_update_image is not None:
for imgage in config.docker_force_update_image:
for image in config.docker_force_update_image:
self.docker_remove_image(image=image, force=True)

def docker_remove_image(self, image, force=True):
Expand Down Expand Up @@ -405,6 +406,15 @@ def start_daemons(self):
else:
logger.warning("Not a docker client %s", client_name)

def stop_daemons(self):
# Start the processes
for (client_name, isDocker, cmd) in self._config.active_clients:
if isDocker:
logger.info("Stopping daemon for %s : %s", client_name, cmd)
self.kill_daemon(client_name)
else:
logger.warning("Not a docker client %s", client_name)

def start_daemon(self, clientname, imagename):
self._dockerclient.containers.run(image=imagename,
entrypoint="sleep",
Expand Down Expand Up @@ -670,6 +680,10 @@ def event_str(event):
return ' '.join(r)






def main():
### setup logging
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -723,6 +737,16 @@ def main():

fuzzer = Fuzzer(config=Config(args))

### setup signal handler (catches ctrl+c SIGINT)
def signal_handler(*args, **kwargs):
logger.warning("SIGINT - Aborting execution. please stand by until the docker instances are shut down.")
fuzzer.stop_daemons()
logger.info("BYE BYE.")
sys.exit(1)


signal.signal(signal.SIGINT, signal_handler)

# Start all docker daemons that we'll use during the execution
fuzzer.start_daemons()

Expand Down

0 comments on commit 55a2127

Please sign in to comment.