This patch fixes the problem with capturing data on configured
interfaces. The problem is that we start tcpdump inside shell. When we
stop the capture we call Popen.terminate() but this terminates the
shell process, not the tcpdump process. Until it's terminated the data are
not flushed to capture file and we transfer empty file to controller.
The fix for this problem is running without shell.
Additionally I'm removing the quotation marks around pcap filter as they
are not required and cause unnecessary entry in log when it is empty.
The last change in the patch is moving redirection of stderr to the code
where Popen is called. This is a must because of using shell=False.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
lnst/Common/PacketCapture.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lnst/Common/PacketCapture.py b/lnst/Common/PacketCapture.py
index f45dc99..2717200 100644
@@ -11,6 +11,7 @@ rpazdera(a)redhat.com (Radek Pazdera)
""" Capture/handle traffic that goes through a specific
@@ -49,14 +50,15 @@ class PacketCapture:
output_file = self._file
pcap_filter = self._filter
- self._cmd = "tcpdump -p -i %s -w %s \"%s\" 2>/dev/null" %
+ self._cmd = "tcpdump -p -i %s -w %s %s" % \
(interface, output_file, pcap_filter)
""" Start tcpdump in the background """
- cmd = self._cmd
- self._tcpdump = subprocess.Popen(cmd, shell=True, stdout=None,
+ cmd = self._cmd.split()
+ fnull = open(os.devnull, "w")
+ self._tcpdump = subprocess.Popen(cmd, shell=False, stdout=fnull,
Show replies by date