mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-15 17:11:30 +00:00
ci(e2e): fix Start Packet Capture EACCES + PID-tracking on tcpdump (siv-167)
Two bugs in afd63ed9:
1. `sudo mkdir` makes /tmp/spinifex-diag root-owned 0755. The
subsequent `> /tmp/spinifex-diag/tcpdump.log` is performed by
the calling tf-user shell BEFORE sudo gets the command, failing
with Permission denied. action shell runs with `set -e` so the
step aborts.
2. `sudo nohup ... &; echo $!` captures the wrong PID — `$!` is the
backgrounded sudo, which may exit when its target dies, leaving
stale tcpdump.pid.
Fixes:
- chmod 0777 on /tmp/spinifex-diag after creating it (next steps'
redirects from tf-user shell now work).
- Wrap the tcpdump launch in `sudo bash -c '...'` so backgrounding
and `$!` happen inside the sudo'd shell — `$!` is the actual
tcpdump PID (nohup execs, sudo bash holds it). Captures stdin
to /dev/null, stdout/stderr to /tmp/spinifex-diag/tcpdump.log.
- sleep 2 (was 1) — gives tcpdump time to fully init pcap header.
- Hard fail (exit 1) if PID is missing or process dead, so the
step's failure is visible instead of a silent green.
bash -n verified.
This commit is contained in:
+16
-10
@@ -87,18 +87,24 @@ jobs:
|
||||
ssh -o StrictHostKeyChecking=no -i "$SSH_KEY" tf-user@${WAN_IP} 'bash -s' <<'REMOTE'
|
||||
set -x
|
||||
sudo mkdir -p /tmp/spinifex-diag
|
||||
sudo rm -f /tmp/spinifex-diag/br-wan.pcap /tmp/spinifex-diag/tcpdump.pid
|
||||
sudo nohup tcpdump -i br-wan -nn -s 0 -U \
|
||||
-w /tmp/spinifex-diag/br-wan.pcap \
|
||||
'(tcp port 22 or tcp port 80 or tcp port 443 or tcp port 9999) or arp' \
|
||||
> /tmp/spinifex-diag/tcpdump.log 2>&1 &
|
||||
echo $! | sudo tee /tmp/spinifex-diag/tcpdump.pid
|
||||
sleep 1
|
||||
if sudo kill -0 "$(cat /tmp/spinifex-diag/tcpdump.pid)" 2>/dev/null; then
|
||||
echo "tcpdump running PID=$(cat /tmp/spinifex-diag/tcpdump.pid)"
|
||||
sudo chmod 0777 /tmp/spinifex-diag
|
||||
sudo rm -f /tmp/spinifex-diag/br-wan.pcap /tmp/spinifex-diag/tcpdump.pid /tmp/spinifex-diag/tcpdump.log
|
||||
sudo bash -c '
|
||||
nohup tcpdump -i br-wan -nn -s 0 -U \
|
||||
-w /tmp/spinifex-diag/br-wan.pcap \
|
||||
"(tcp port 22 or tcp port 80 or tcp port 443 or tcp port 9999) or arp" \
|
||||
</dev/null >/tmp/spinifex-diag/tcpdump.log 2>&1 &
|
||||
echo $! > /tmp/spinifex-diag/tcpdump.pid
|
||||
'
|
||||
sleep 2
|
||||
PID=$(cat /tmp/spinifex-diag/tcpdump.pid 2>/dev/null || echo "")
|
||||
if [ -n "$PID" ] && sudo kill -0 "$PID" 2>/dev/null; then
|
||||
echo "tcpdump running PID=$PID"
|
||||
ls -la /tmp/spinifex-diag/
|
||||
else
|
||||
echo "tcpdump failed to start"
|
||||
sudo cat /tmp/spinifex-diag/tcpdump.log
|
||||
cat /tmp/spinifex-diag/tcpdump.log 2>&1 || true
|
||||
exit 1
|
||||
fi
|
||||
REMOTE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user