summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-01-22 17:19:50 +0100
committerChristian Breunig <christian@breunig.cc>2026-01-22 17:30:18 +0100
commit09855a7790d0a5a2eef4cbf6f60f84f2f9f8981e (patch)
tree46d4ca030a9961967cb5cd910373071fa8b8cf71
parent41aa42fec49399a3cee7c772d2799b1c17490401 (diff)
downloadvyos-1x-09855a7790d0a5a2eef4cbf6f60f84f2f9f8981e.tar.gz
vyos-1x-09855a7790d0a5a2eef4cbf6f60f84f2f9f8981e.zip
T8154: make catch_broken_pipe decorator to common vyos.utils.io function
This adds the capability to make it re-usable in other code paths.
-rw-r--r--python/vyos/utils/io.py11
-rwxr-xr-xsrc/op_mode/interfaces.py12
2 files changed, 12 insertions, 11 deletions
diff --git a/python/vyos/utils/io.py b/python/vyos/utils/io.py
index 0883376d1..3efb55ddc 100644
--- a/python/vyos/utils/io.py
+++ b/python/vyos/utils/io.py
@@ -111,3 +111,14 @@ def select_entry(l: list, list_msg: str = '', prompt_msg: str = '',
select = ask_input(prompt_msg, default=default_entry, numeric_only=True,
valid_responses=valid_entry)
return next(filter(lambda x: x[0] == select, en))[1]
+
+def catch_broken_pipe(func):
+ import os
+ import sys
+ def wrapped(*args, **kwargs):
+ try:
+ func(*args, **kwargs)
+ except (BrokenPipeError, KeyboardInterrupt):
+ # Flush output to /dev/null and bail out.
+ os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno()) # pylint: disable = no-member
+ return wrapped
diff --git a/src/op_mode/interfaces.py b/src/op_mode/interfaces.py
index ed36731e3..ecc4e73d2 100755
--- a/src/op_mode/interfaces.py
+++ b/src/op_mode/interfaces.py
@@ -13,9 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-import os
import re
import sys
import glob
@@ -30,6 +28,7 @@ from vyos.ifconfig import Section
from vyos.ifconfig import Interface
from vyos.ifconfig import VRRP
from vyos.utils.dict import dict_set_nested
+from vyos.utils.io import catch_broken_pipe
from vyos.utils.network import get_interface_vrf
from vyos.utils.network import interface_exists
from vyos.utils.process import cmd
@@ -37,15 +36,6 @@ from vyos.utils.process import rc_cmd
from vyos.utils.process import call
from vyos.configquery import op_mode_config_dict
-def catch_broken_pipe(func):
- def wrapped(*args, **kwargs):
- try:
- func(*args, **kwargs)
- except (BrokenPipeError, KeyboardInterrupt):
- # Flush output to /dev/null and bail out.
- os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno()) # pylint: disable = no-member
- return wrapped
-
# The original implementation of filtered_interfaces has signature:
# (ifnames: list, iftypes: typing.Union[str, list], vif: bool, vrrp: bool) -> intf: Interface:
# Arg types allowed in CLI (ifnames: str, iftypes: str) were manually