diff options
author | erkin <e.altunbas@vyos.io> | 2021-01-26 22:29:04 +0300 |
---|---|---|
committer | erkin <e.altunbas@vyos.io> | 2021-01-26 22:29:04 +0300 |
commit | 5e50f072478167a7e2027f39d4c8925c9c4fefde (patch) | |
tree | da23b08249b41ee43028bc0955663e4d4564c756 /src/op_mode | |
parent | cec848e4a668ed51868d5fa50504a2f8bb1b4eb7 (diff) | |
download | vyos-1x-5e50f072478167a7e2027f39d4c8925c9c4fefde.tar.gz vyos-1x-5e50f072478167a7e2027f39d4c8925c9c4fefde.zip |
op-mode: T3110: Gracefully handle SIGPIPE in show-interfaces
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/show_interfaces.py | 19 |
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 |