libc/netdb: Hold dns lock when operating with resolv.conf

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-04-01 12:05:22 +08:00 committed by Masayuki Ishikawa
parent cd695cd0d9
commit 499c450d36
2 changed files with 14 additions and 4 deletions

View File

@ -81,6 +81,8 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
return ret; return ret;
} }
dns_semtake();
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
/* Check for an IPv4 address */ /* Check for an IPv4 address */
@ -183,11 +185,17 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
goto errout; goto errout;
} }
dns_notify_nameserver(addr, addrlen);
ret = OK; ret = OK;
errout: errout:
dns_semgive();
fclose(stream); fclose(stream);
if (ret == OK)
{
dns_notify_nameserver(addr, addrlen);
}
return ret; return ret;
} }

View File

@ -96,6 +96,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
return ret; return ret;
} }
dns_semtake();
keylen = strlen(NETDB_DNS_KEYWORD); keylen = strlen(NETDB_DNS_KEYWORD);
while (fgets(line, DNS_MAX_LINE, stream) != NULL) while (fgets(line, DNS_MAX_LINE, stream) != NULL)
{ {
@ -218,14 +220,14 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
if (ret != OK) if (ret != OK)
{ {
fclose(stream); break;
return ret;
} }
} }
} }
dns_semgive();
fclose(stream); fclose(stream);
return OK; return ret;
} }
#else /* CONFIG_NETDB_RESOLVCONF */ #else /* CONFIG_NETDB_RESOLVCONF */