summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2021-01-27 03:01:43 +0700
committerGitHub <noreply@github.com>2021-01-27 03:01:43 +0700
commitca1f38a189e2e5b82d0821455d7b64eb385ace22 (patch)
treeb475b38678f390ea2b0b0db51ab94001397f092b
parent458b24c3b365a1a6ea0b8e6b59a2baba2b24c7e6 (diff)
parent5e50f072478167a7e2027f39d4c8925c9c4fefde (diff)
downloadvyos-1x-ca1f38a189e2e5b82d0821455d7b64eb385ace22.tar.gz
vyos-1x-ca1f38a189e2e5b82d0821455d7b64eb385ace22.zip
Merge pull request #701 from erkin/current
op-mode: T3110: Gracefully handle SIGPIPE in show-interfaces
-rwxr-xr-xsrc/op_mode/show_interfaces.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/op_mode/show_interfaces.py b/src/op_mode/show_interfaces.py
index de41274a7..256c86d2a 100755
--- a/src/op_mode/show_interfaces.py
+++ b/src/op_mode/show_interfaces.py
@@ -35,14 +35,23 @@ glob_ifnames = '/sys/class/net/({})*'.format('|'.join(interfaces))
actions = {}
-def register (name):
+def register(name):
"""
- decorator to register a function into actions with a name
- it allows to use actions[name] to call the registered function
+ Decorator to register a function into actions with a name.
+ `actions[name]' can be used to call the registered functions.
+ We wrap each function in a SIGPIPE handler as all registered functions
+ can be subject to a broken pipe if there are a lot of interfaces.
"""
def _register(function):
- actions[name] = function
- return function
+ def handled_function(*args, **kwargs):
+ try:
+ function(*args, **kwargs)
+ except BrokenPipeError:
+ # Flush output to /dev/null and bail out.
+ os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno())
+ sys.exit(1)
+ actions[name] = handled_function
+ return handled_function
return _register