core: skip reset when gadget bound

This commit is contained in:
Brad Stein 2026-01-09 17:55:25 -03:00
parent 67cddf6a99
commit efa261ba48

View File

@ -96,7 +96,13 @@ case "${1:-}" in
;;
esac
cleanup() { echo "" >"$G/UDC" 2>/dev/null || true; }
cleanup() {
if [[ -n ${LESAVKA_ALLOW_GADGET_RESET:-} ]]; then
LESAVKA_DETACH_CLEAR_UDC=1 detach_gadget
else
detach_gadget
fi
}
DISABLE_UAC=${LESAVKA_DISABLE_UAC:-}
DISABLE_UVC=${LESAVKA_DISABLE_UVC:-}
@ -186,6 +192,17 @@ fi
[[ -n $UDC ]] || { log "❌ UDC not present after manual bind"; exit 1; }
log "✅ UDC detected: $UDC"
# Guard against lockups: if the gadget is already bound, don't reset unless forced.
BOUND_UDC=""
if [[ -r $G/UDC ]]; then
BOUND_UDC=$(cat "$G/UDC" 2>/dev/null || true)
fi
if [[ -n $BOUND_UDC && -z ${LESAVKA_ALLOW_GADGET_RESET:-} ]]; then
log "🔒 gadget already bound to '$BOUND_UDC' - refusing reset."
log " Set LESAVKA_ALLOW_GADGET_RESET=1 to force."
exit 0
fi
# Guard against lockups: don't reset gadget while host is attached unless forced.
UDC_STATE="$(udc_state "$UDC")"
if [[ -z ${LESAVKA_ALLOW_GADGET_RESET:-} ]] && is_attached_state "$UDC_STATE"; then