#!/usr/bin/env bash
#
# Pre-test cleanup for sdr-log-default.  Defends against residue from a
# prior aborted run: kills any lingering ION processes, removes leaked
# SysV shared-memory segments owned by this user, and deletes the SDR
# artifacts the test writes into this directory.
#

killm f >/dev/null 2>&1
sleep 1

# Remove any SysV shm segments we created in earlier runs.  ipcs/ipcrm
# are best-effort: missing utilities or permission errors are ignored.
if command -v ipcs >/dev/null 2>&1 && command -v ipcrm >/dev/null 2>&1; then
    for key in $(ipcs -m 2>/dev/null | awk '/^0x/ {print $1}'); do
        ipcrm -M "$key" >/dev/null 2>&1 || true
    done
fi

rm -f log*.sdr log*.sdrlog ion_nodes ion.log
