Iterate the gateway's UDP socket inodes from a variable

shellcheck reports SC2013 on the for loop over a command substitution in
gateway_dns_held_by, and the OpenWrt Package workflow fails its lint step on
it. Capture the awk output in a variable and iterate that instead; the words
the loop sees are the same.

cat stays in front of awk because busybox awk gives up on a missing
/proc/net/udp6, and a while-read loop at the end of the pipe would run in a
subshell under ash, where returning from the function is not possible.
This commit is contained in:
Johnathan Corgan
2026-10-01 22:40:40 +00:00
parent 1d3c5f236c
commit 0f2ba939fd
@@ -185,11 +185,15 @@ dns_locked() {
# is among the process's open descriptors. Another process holding the port,
# such as an mDNS responder on 5353, does not count.
gateway_dns_held_by() {
local hex inode fd
local hex inodes inode fd
[ -n "$2" ] || return 1
hex="$(printf '%04X' "$1")"
for inode in $(cat /proc/net/udp /proc/net/udp6 2>/dev/null |
awk -v want=":$hex" 'substr($2, length($2) - 4) == want { print $10 }'); do
# cat rather than awk's own file arguments: busybox awk gives up on a
# missing /proc/net/udp6. A while-read loop on the pipe would run in a
# subshell under ash, where the return below could not leave this function.
inodes="$(cat /proc/net/udp /proc/net/udp6 2>/dev/null |
awk -v want=":$hex" 'substr($2, length($2) - 4) == want { print $10 }')"
for inode in $inodes; do
for fd in /proc/"$2"/fd/*; do
[ "$(readlink "$fd" 2>/dev/null)" = "socket:[$inode]" ] && return 0
done