mirror of
https://github.com/jmcorgan/fips.git
synced 2026-10-05 19:18:25 +00:00
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:
@@ -185,11 +185,15 @@ dns_locked() {
|
|||||||
# is among the process's open descriptors. Another process holding the port,
|
# is among the process's open descriptors. Another process holding the port,
|
||||||
# such as an mDNS responder on 5353, does not count.
|
# such as an mDNS responder on 5353, does not count.
|
||||||
gateway_dns_held_by() {
|
gateway_dns_held_by() {
|
||||||
local hex inode fd
|
local hex inodes inode fd
|
||||||
[ -n "$2" ] || return 1
|
[ -n "$2" ] || return 1
|
||||||
hex="$(printf '%04X' "$1")"
|
hex="$(printf '%04X' "$1")"
|
||||||
for inode in $(cat /proc/net/udp /proc/net/udp6 2>/dev/null |
|
# cat rather than awk's own file arguments: busybox awk gives up on a
|
||||||
awk -v want=":$hex" 'substr($2, length($2) - 4) == want { print $10 }'); do
|
# 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
|
for fd in /proc/"$2"/fd/*; do
|
||||||
[ "$(readlink "$fd" 2>/dev/null)" = "socket:[$inode]" ] && return 0
|
[ "$(readlink "$fd" 2>/dev/null)" = "socket:[$inode]" ] && return 0
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user