exit gracefully on control-c and non-convergence

refs: #3672

Change-Id: I19df1a3318315b49816b3cf93c39bc95af52d0b3
diff --git a/bin/minindn b/bin/minindn
index c8530e6..324513b 100755
--- a/bin/minindn
+++ b/bin/minindn
@@ -76,6 +76,7 @@
 import datetime
 from os.path import expanduser
 import sys
+import signal
 from subprocess import call
 
 from ndn.nlsr import Nlsr, NlsrConfigGenerator
@@ -380,11 +381,19 @@
         print("Moving results to %s" % options.resultDir)
         os.system("sudo mv /%s/* %s" % (options.workDir, options.resultDir))
 
+def signal_handler(signal, frame):
+    print('Cleaning up...')
+    call(["nfd-stop"])
+    call(["sudo", "mn", "--clean"])
+    sys.exit(1)
+
 if __name__ == '__main__':
 
     hosts_conf = []
     links_conf = []
 
+    signal.signal(signal.SIGINT, signal_handler)
+
     options = parse_args()
 
     setLogLevel('info')