diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-01-29 13:45:29 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-29 13:45:29 -0600 |
| commit | 1af4e423a17064e3e6d87b0c5df1c01688b6551a (patch) | |
| tree | ad9af31411eb033c32c47659461856c46bbfa3e8 /src | |
| parent | 8944d5e4aea06e0c501880204c49a32494df8966 (diff) | |
| parent | be6607c66e3414e3549d9568bb6840eee6f801be (diff) | |
| download | vyos-1x-1af4e423a17064e3e6d87b0c5df1c01688b6551a.tar.gz vyos-1x-1af4e423a17064e3e6d87b0c5df1c01688b6551a.zip | |
Merge pull request #4951 from c-po/broken-pipe
op-mode: T8154: fix tcpdump KeyboardInterrupt on Ctrl+C
Diffstat (limited to 'src')
| -rwxr-xr-x | src/op_mode/interfaces.py | 12 | ||||
| -rw-r--r-- | src/op_mode/tcpdump.py | 12 |
2 files changed, 8 insertions, 16 deletions
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 diff --git a/src/op_mode/tcpdump.py b/src/op_mode/tcpdump.py index fcdb23a81..351b3d520 100644 --- a/src/op_mode/tcpdump.py +++ b/src/op_mode/tcpdump.py @@ -16,6 +16,7 @@ import sys +from vyos.utils.io import catch_broken_pipe from vyos.utils.process import call options = { @@ -51,8 +52,6 @@ options = { }, } -tcpdump = 'sudo /usr/bin/tcpdump' - class List(list): def first(self): return self.pop(0) if self else '' @@ -92,7 +91,8 @@ def complete(prefix): return [o for o in options if o.startswith(prefix)] -def convert(command, args): +def convert(args): + command = 'sudo /usr/bin/tcpdump' while args: shortname = args.first() longnames = complete(shortname) @@ -109,6 +109,9 @@ def convert(command, args): command=command, value=args.first()) return command +@catch_broken_pipe +def run_tcpdump(command: str, ifname: str) -> None: + call(f'{command} -i {ifname}') if __name__ == '__main__': args = List(sys.argv[1:]) @@ -161,5 +164,4 @@ if __name__ == '__main__': sys.stdout.write(helplines) sys.exit(0) - command = convert(tcpdump, args) - call(f'{command} -i {ifname}') + run_tcpdump(convert(args), ifname) |
