Skip to content

Commit 03429b4

Browse files
Bastian-KrauseEmantor
authored andcommitted
helpers/labgrid-raw-interface: fix tcpdump timeout handling
The current tcpdump timeout handling does not work. This is supposed to exit after 5 seconds: tcpdump --interface=eth0 -w - -G 5 -W 1 But that does not work if no packets are received. So in order to make the timeout actually work, prefix tcpdump with coreutils' timeout command instead: timeout --signal=INT --preserve-status <timeout> <tcpdump command> By sending SIGINT (`--signal=INT`), tcpdump exits gracefully and finishes writing received packets. Combined with `--preserve-status`, tcpdump's actual exit status is preserved, being 0 even on SIGINT if nothing else went wrong. An alternative would be to use subprocess, but that would prevent us from using `os.execvp()`, replacing the process. So the timeout command is the better approach here. Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent bf38749 commit 03429b4

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

helpers/labgrid-raw-interface

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ def main(program, options):
7373
args.append(str(options.count))
7474

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

8378
elif program == "ip":
8479
args.append("link")

0 commit comments

Comments
 (0)