]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
testing: Fix vici updown script on Debian bookworm
authorTobias Brunner <tobias@strongswan.org>
Tue, 27 Jun 2023 16:45:53 +0000 (18:45 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 13 Jul 2023 08:48:53 +0000 (10:48 +0200)
OOM-killer is now already triggered with `import daemon`, so set the
limit before that.  Also some PEP8 fixes (including an exclusion for
the above fix as that causes imports to not be at the beginning of the
file).

testing/tests/route-based/net2net-xfrmi-ike/hosts/sun/etc/updown.py

index 4abc1aa5489e6aa5a67f4a844e007e9c4430a333..813a3e1ac0dd5143544ff543b3cf9d85063e603f 100755 (executable)
@@ -2,11 +2,18 @@
 
 import sys
 import vici
-import daemon
 import logging
 from logging.handlers import SysLogHandler
 import subprocess
+
+# the hard limit (second number) is the value used by python-daemon when closing
+# potentially open file descriptors while daemonizing or even triggered by the
+# import.  since the default limit is 524288 on newer systems, this can take
+# quite a while, and due to how this range of FDs is handled internally (as set)
+# it can even trigger the OOM killer
 import resource
+resource.setrlimit(resource.RLIMIT_NOFILE, (256, 256))  # noqa
+import daemon
 
 
 logger = logging.getLogger('updownLogger')
@@ -59,13 +66,6 @@ def install_routes(ike_sa):
         subprocess.call(["ip", "route", "add", ts, "dev", ifname_out])
 
 
-# the hard limit (second number) is the value used by python-daemon when closing
-# potentially open file descriptors while daemonizing.  since the default is
-# 524288 on newer systems, this can take quite a while, and due to how this
-# range of FDs is handled internally (as set) it can even trigger the OOM killer
-resource.setrlimit(resource.RLIMIT_NOFILE, (256, 256))
-
-
 # daemonize and run parallel to the IKE daemon
 with daemon.DaemonContext():
     setup_logger()
@@ -75,7 +75,7 @@ with daemon.DaemonContext():
         ver = {k: v.decode("UTF-8") for k, v in session.version().items()}
         logger.info("connected to {daemon} {version} ({sysname}, {release}, "
                     "{machine})".format(**ver))
-    except:
+    except BaseException:
         logger.error("failed to get status via vici")
         sys.exit(1)
 
@@ -95,6 +95,6 @@ with daemon.DaemonContext():
 
     except IOError:
         logger.error("daemon disconnected")
-    except:
+    except BaseException as e:
         logger.error("exception while listening for events " +
-                     repr(sys.exc_info()[1]))
+                     repr(e))