From ea6bb5c255e2aeeffbc1748238058dea4faab2f7 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 2 May 2010 21:01:30 -0400 Subject: [PATCH] iptables: die quietly if parent process dies. If we can't communicate with the parent process, he's probably died unexpectedly; just shut down and don't bother people about it. --- iptables.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/iptables.py b/iptables.py index 3681b1b..92fd937 100644 --- a/iptables.py +++ b/iptables.py @@ -87,15 +87,27 @@ def main(port, subnets): # authentication as early in the startup process as possible). sys.stdin.readline(128) try: + debug1('iptables manager: starting transproxy.\n') do_it(port, subnets) sys.stdout.write('STARTED\n') - sys.stdout.flush() + + try: + sys.stdout.flush() + + # Now we wait until EOF or any other kind of exception. We need + # to stay running so that we don't need a *second* password + # authentication at shutdown time - that cleanup is important! + while sys.stdin.readline(128): + pass + except IOError: + # the parent process died for some reason; he's surely been loud + # enough, so no reason to report another error + return - # Now we wait until EOF or any other kind of exception. We need - # to stay running so that we don't need a *second* password - # authentication at shutdown time - that cleanup is important! - while sys.stdin.readline(128): - pass finally: + try: + debug1('iptables manager: undoing changes.\n') + except: + pass do_it(port, [])