You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2022/04/04 10:48:43 UTC
[incubator-nuttx] branch master updated (9f7ecbd5b7 -> 499c450d36)
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
from 9f7ecbd5b7 syscall: Fix Makefile:69: target 'syscall_names.o' given more than once in the same rule
new a8cac59864 libc/netdb: Support the recursive lock
new cd695cd0d9 libc/netdb: Remove the temporary unlock in dns_foreach_nameserver
new 499c450d36 libc/netdb: Hold dns lock when operating with resolv.conf
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
libs/libc/netdb/lib_dnsaddserver.c | 10 +++++++++-
libs/libc/netdb/lib_dnsforeach.c | 12 +++++-------
libs/libc/netdb/lib_dnsinit.c | 27 +++++++++++++++++++++++++--
3 files changed, 39 insertions(+), 10 deletions(-)
[incubator-nuttx] 02/03: libc/netdb: Remove the temporary unlock in dns_foreach_nameserver
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit cd695cd0d978b6dd0bd2a0baf8da1f955220ba66
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 1 12:28:05 2022 +0800
libc/netdb: Remove the temporary unlock in dns_foreach_nameserver
since netdb support the recursive lock
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/netdb/lib_dnsforeach.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libs/libc/netdb/lib_dnsforeach.c b/libs/libc/netdb/lib_dnsforeach.c
index 1df7f7cb16..d93c323e65 100644
--- a/libs/libc/netdb/lib_dnsforeach.c
+++ b/libs/libc/netdb/lib_dnsforeach.c
@@ -253,9 +253,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
/* Perform the callback */
- dns_semgive();
ret = callback(arg, addr, sizeof(struct sockaddr_in));
- dns_semtake();
}
else
#endif
@@ -274,9 +272,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
/* Perform the callback */
- dns_semgive();
ret = callback(arg, addr, sizeof(struct sockaddr_in6));
- dns_semtake();
}
else
#endif
[incubator-nuttx] 03/03: libc/netdb: Hold dns lock when operating with resolv.conf
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 499c450d36955e53a9c822a45c137329c7484743
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 1 12:05:22 2022 +0800
libc/netdb: Hold dns lock when operating with resolv.conf
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/netdb/lib_dnsaddserver.c | 10 +++++++++-
libs/libc/netdb/lib_dnsforeach.c | 8 +++++---
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/libs/libc/netdb/lib_dnsaddserver.c b/libs/libc/netdb/lib_dnsaddserver.c
index e0f6adc843..f642e7bcb3 100644
--- a/libs/libc/netdb/lib_dnsaddserver.c
+++ b/libs/libc/netdb/lib_dnsaddserver.c
@@ -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;
}
diff --git a/libs/libc/netdb/lib_dnsforeach.c b/libs/libc/netdb/lib_dnsforeach.c
index d93c323e65..2857fd6ad5 100644
--- a/libs/libc/netdb/lib_dnsforeach.c
+++ b/libs/libc/netdb/lib_dnsforeach.c
@@ -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 */
[incubator-nuttx] 01/03: libc/netdb: Support the recursive lock
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit a8cac598647384069aa1a834cf9670318759b772
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 1 12:26:30 2022 +0800
libc/netdb: Support the recursive lock
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/netdb/lib_dnsinit.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/libs/libc/netdb/lib_dnsinit.c b/libs/libc/netdb/lib_dnsinit.c
index 5b07f5aa59..ae45b82142 100644
--- a/libs/libc/netdb/lib_dnsinit.c
+++ b/libs/libc/netdb/lib_dnsinit.c
@@ -30,6 +30,7 @@
#include <arpa/inet.h>
+#include <nuttx/sched.h>
#include <nuttx/semaphore.h>
#include "netdb/lib_dns.h"
@@ -40,7 +41,9 @@
/* Protects DNS cache, nameserver list and notify list. */
-static sem_t g_dns_sem = SEM_INITIALIZER(1);
+static sem_t g_dns_sem = SEM_INITIALIZER(1);
+static pid_t g_dns_holder = INVALID_PROCESS_ID;
+static int g_dns_count;
/****************************************************************************
* Public Data
@@ -143,9 +146,20 @@ bool dns_initialize(void)
void dns_semtake(void)
{
+ pid_t me = getpid();
int errcode = 0;
int ret;
+ /* Does this thread already hold the semaphore? */
+
+ if (g_dns_holder == me)
+ {
+ /* Yes.. just increment the reference count */
+
+ g_dns_count++;
+ return;
+ }
+
do
{
ret = _SEM_WAIT(&g_dns_sem);
@@ -156,6 +170,9 @@ void dns_semtake(void)
}
}
while (ret < 0 && errcode == EINTR);
+
+ g_dns_holder = me;
+ g_dns_count = 1;
}
/****************************************************************************
@@ -168,5 +185,11 @@ void dns_semtake(void)
void dns_semgive(void)
{
- DEBUGVERIFY(_SEM_POST(&g_dns_sem));
+ DEBUGASSERT(g_dns_holder == getpid() && g_dns_count > 0);
+
+ if (--g_dns_count == 0)
+ {
+ g_dns_holder = INVALID_PROCESS_ID;
+ DEBUGVERIFY(_SEM_POST(&g_dns_sem));
+ }
}