summaryrefslogtreecommitdiff
path: root/src/op_mode/show_interfaces.py
diff options
context:
space:
mode:
authorerkin <e.altunbas@vyos.io>2021-01-26 22:29:04 +0300
committererkin <e.altunbas@vyos.io>2021-01-26 22:29:04 +0300
commit5e50f072478167a7e2027f39d4c8925c9c4fefde (patch)
treeda23b08249b41ee43028bc0955663e4d4564c756 /src/op_mode/show_interfaces.py
parentcec848e4a668ed51868d5fa50504a2f8bb1b4eb7 (diff)
downloadvyos-1x-5e50f072478167a7e2027f39d4c8925c9c4fefde.tar.gz
vyos-1x-5e50f072478167a7e2027f39d4c8925c9c4fefde.zip
op-mode: T3110: Gracefully handle SIGPIPE in show-interfaces
Diffstat (limited to 'src/op_mode/show_interfaces.py')
-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