Skip to content

Commit 0da49e3

Browse files
committed
fix(avahi): avoid restart on transient iface loss
Purpose of the change: - Keep Avahi running when an allowed interface temporarily loses carrier or its address. Before this change: - rc.avahidaemon update recomputed active bindings and restarted Avahi whenever the active bind list differed from allow-interfaces. - DHCP/network hooks could therefore restart Avahi while a wireless interface was still down. Why that was a problem: - Avahi already observes interface loss and recovery while running. - Restarting during a temporary outage can start Avahi with no suitable network protocol, causing it to exit and remain stopped. What the new change accomplishes: - Avoids restarting Avahi when the only bind difference is an allowed interface that is currently inactive. - Still restarts when an active interface is newly added to the bind list or an active interface is deliberately removed. How it works: - rc.avahidaemon update compares current and recomputed bind lists. - The restart decision now checks whether changed interfaces are active before calling avahid_restart.
1 parent 982b3c2 commit 0da49e3

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

etc/rc.d/rc.avahidaemon

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,52 @@ avahid_reload(){
119119
fi
120120
}
121121

122+
# Avahi observes interface loss/recovery while running. Restart only for bind
123+
# changes that add an active interface or remove an interface that is still
124+
# active; do not restart just because an allowed interface temporarily vanished.
125+
csv_has(){
126+
local LIST=",$1,"
127+
[[ $LIST == *",$2,"* ]]
128+
}
129+
130+
iface_active(){
131+
[[ -n $(show dev "$1") ]]
132+
}
133+
134+
bind_adds_active_iface(){
135+
local CURRENT="$1" NEXT="$2" IFACE
136+
IFS=, read -ra IFACES <<< "$NEXT"
137+
for IFACE in "${IFACES[@]}"; do
138+
[[ -n $IFACE ]] || continue
139+
if ! csv_has "$CURRENT" "$IFACE"; then
140+
return 0
141+
fi
142+
done
143+
return 1
144+
}
145+
146+
bind_removes_active_iface(){
147+
local CURRENT="$1" NEXT="$2" IFACE
148+
IFS=, read -ra IFACES <<< "$CURRENT"
149+
for IFACE in "${IFACES[@]}"; do
150+
[[ -n $IFACE ]] || continue
151+
if ! csv_has "$NEXT" "$IFACE" && iface_active "$IFACE"; then
152+
return 0
153+
fi
154+
done
155+
return 1
156+
}
157+
158+
bind_requires_restart(){
159+
bind_adds_active_iface "$1" "$2" || bind_removes_active_iface "$1" "$2"
160+
}
161+
122162
avahid_update(){
123-
if avahid_running && check && [[ "$(this allow-interfaces)" != "$BIND" ]]; then
163+
local CURRENT
164+
if avahid_running && check; then
165+
CURRENT="$(this allow-interfaces)"
166+
[[ "$CURRENT" != "$BIND" ]] || return 0
167+
bind_requires_restart "$CURRENT" "$BIND" || return 0
124168
log "Updating $DAEMON..."
125169
avahid_restart # note we need restart here, not reload in order to update interfaces
126170
fi

0 commit comments

Comments
 (0)