From 2162ce1ae349d5a39364cc7e074a5b30ff12785c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 15 Apr 2012 10:35:19 +1200 Subject: Shut mitmdump down gracefully on SIGTERM. This is a hack at the moment, but needs must. --- libmproxy/dump.py | 5 +++++ mitmdump | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 253a22d7..a797efbf 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -214,6 +214,11 @@ class DumpMaster(flow.FlowMaster): self._process_flow(f) return f + def shutdown(self): + if self.o.wfile: + self.wfile.fo.close() + return flow.FlowMaster.shutdown(self) + # begin nocover def run(self): if self.o.rfile and not self.o.keepserving: diff --git a/mitmdump b/mitmdump index 83748c71..3c2b5fce 100755 --- a/mitmdump +++ b/mitmdump @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import sys +import sys, signal from libmproxy import proxy, dump, cmdline from libmproxy.version import VERSION from optparse import OptionParser @@ -62,9 +62,15 @@ if __name__ == '__main__': try: m = dump.DumpMaster(server, dumpopts, filt) + def cleankill(*args, **kwargs): + m.shutdown() + signal.signal(signal.SIGTERM, cleankill) m.run() except dump.DumpError, e: print >> sys.stderr, "mitmdump:", e sys.exit(1) except KeyboardInterrupt: pass + + + -- cgit v1.2.3