summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/interfaces.py12
-rw-r--r--src/op_mode/tcpdump.py12
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)