diff options
author | Avery Pennarun <apenwarr@gmail.com> | 2010-05-02 21:01:30 -0400 |
---|---|---|
committer | Avery Pennarun <apenwarr@gmail.com> | 2010-05-02 21:02:09 -0400 |
commit | ea6bb5c255e2aeeffbc1748238058dea4faab2f7 (patch) | |
tree | 7600feb123f2dc0e3bd9c23f0fcf2e50d7c12a0c | |
parent | 2c2bea80bc3164e080cfac9d4c4ca21b7a592c35 (diff) |
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.
-rw-r--r-- | iptables.py | 24 |
1 files 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, []) |