libc/netdb: Hold dns lock when operating with resolv.conf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
cd695cd0d9
commit
499c450d36
@ -81,6 +81,8 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
dns_semtake();
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
/* Check for an IPv4 address */
|
||||
|
||||
@ -183,11 +185,17 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
dns_notify_nameserver(addr, addrlen);
|
||||
ret = OK;
|
||||
|
||||
errout:
|
||||
dns_semgive();
|
||||
fclose(stream);
|
||||
|
||||
if (ret == OK)
|
||||
{
|
||||
dns_notify_nameserver(addr, addrlen);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
dns_semtake();
|
||||
|
||||
keylen = strlen(NETDB_DNS_KEYWORD);
|
||||
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)
|
||||
{
|
||||
fclose(stream);
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dns_semgive();
|
||||
fclose(stream);
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* CONFIG_NETDB_RESOLVCONF */
|
||||
|
Loading…
Reference in New Issue
Block a user