Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions helpers/labgrid-raw-interface
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ def main(program, options):
args.append(str(options.count))

if options.timeout:
# The timeout is implemented by specifying the number of seconds before rotating the
# dump file, but limiting the number of files to 1
args.append("-G")
args.append(str(options.timeout))
args.append("-W")
args.append("1")
args = ["timeout", "--signal=INT", "--preserve-status", str(options.timeout)] + args

elif program == "ip":
args.append("link")
Expand Down Expand Up @@ -131,7 +126,7 @@ if __name__ == "__main__":
# tcpdump
tcpdump_parser = subparsers.add_parser("tcpdump")
tcpdump_parser.add_argument("ifname", type=str, help="interface name")
tcpdump_parser.add_argument("count", type=int, default=None, help="amount of frames to capture while recording")
tcpdump_parser.add_argument("count", type=int, nargs="?", default=None, help="amount of frames to capture while recording")
tcpdump_parser.add_argument(
"--timeout", type=int, default=None, help="Amount of time to capture while recording. 0 means capture forever"
)
Expand Down
22 changes: 21 additions & 1 deletion labgrid/driver/rawnetworkinterfacedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,30 @@ def start_record(self, filename, *, count=None, timeout=None):
cmd.append(str(timeout))
cmd = self._wrap_command(cmd)
if filename is None:
self._record_handle = subprocess.Popen(cmd, stdout=subprocess.PIPE)
self._record_handle = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
with open(filename, "wb") as outdata:
self._record_handle = subprocess.Popen(cmd, stdout=outdata, stderr=subprocess.PIPE)

# wait for capture start
stderr = b""
while True:
line = self._record_handle.stderr.readline()
if not line: # process ended prematurely
try:
self._stop(self._record_handle)
except subprocess.CalledProcessError as e:
# readd consumed stderr to exception
e.stderr = stderr
raise

if line.startswith(b"tcpdump: listening on"):
break

# collect and log other lines in stderr before capturing has started
stderr += line
self.logger.warning(line.decode().rstrip())

return self._record_handle

@Driver.check_active
Expand Down