fix: ASW-65 停止捕包时等待 tcpdump 资源释放,防止 pcap 不全
This commit is contained in:
@@ -142,7 +142,7 @@ public class APIController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/pcap")
|
||||
public void stopTcpdump(@RequestParam String id,
|
||||
public synchronized void stopTcpdump(@RequestParam String id,
|
||||
@RequestParam(required = false, defaultValue = "false") Boolean returnFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
AdbUtil.CommandResult result = adbUtil.stopTcpdump(id);
|
||||
|
||||
@@ -641,6 +641,21 @@ public class AdbUtil {
|
||||
.serial(this.getSerial())
|
||||
.buildShellCommand(String.format("shell \"ps -ef | grep tcpdump | grep -v grep | grep %s | awk '{print $2}' | xargs kill -INT \"", id))
|
||||
.build());
|
||||
|
||||
// 等待 tcpdump 资源释放,避免出现错误:The capture file appears to have been cut short in the middle of a packet.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
T.ThreadUtil.sleep(500);
|
||||
|
||||
String str = CommandExec.exec(AdbCommandBuilder.builder()
|
||||
.serial(this.getSerial())
|
||||
.buildShellCommand(String.format("shell \"ps -ef | grep tcpdump | grep -v grep | grep %s \"", id))
|
||||
.build());
|
||||
log.info("[stopTcpdump] [id: {}] [is running: {}]", id, str);
|
||||
if (T.StrUtil.isEmpty(str)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("[stopTcpdump] [id: {}] [pcapFilePath: {}] [result: {}]", id, pcapFilePath, result);
|
||||
if (T.StrUtil.isEmpty(result)) {
|
||||
return new CommandResult(0, pcapFilePath);
|
||||
|
||||
Reference in New Issue
Block a user