#!/bin/sh
#
# Copyright (C) 2026 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
#
# Sourced by /bin/omr-schedule every minute.
#
# Fallback re-sync of net.ipv4.ip_local_reserved_ports. /etc/init.d/omr-reserved-ports
# already reacts to config changes, but it depends on reload_config's
# config.change event, which is occasionally lost - a stock ttyd missed the
# same port change on the bench. omr-reserved-ports touches its stamp after
# every sync, so this only runs when nothing has synced for 10 minutes: one
# find per minute, one ~50-fork pass every 10 minutes at most.

if [ -x /bin/omr-reserved-ports ] &&
   [ -z "$(find /tmp/omr-reserved-ports.stamp -mmin -10 2>/dev/null)" ]; then
	/bin/omr-reserved-ports --quiet >/dev/null 2>&1 ||
		_log "net.ipv4.ip_local_reserved_ports re-sync failed"
fi
