This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5ce71c8252e5efe34fcb03915d52f347a0418ee5 Author: vela-autotest09 <[email protected]> AuthorDate: Mon Aug 3 18:40:35 2026 +0800 libc/netdb: Do not log an error when the hosts file does not exist. lib_hostfile_lookup() in lib_gethostentbynamer.c and lib_gethostbyaddrr.c logged an error with nerr() every time the hosts file (CONFIG_NETDB_HOSTCONF_PATH) could not be opened. A system without a static host table has no such file, so every lookup, for example the periodic lookup of an NTP server, logged an error although the lookup then goes on with DNS as intended. Log only open failures other than ENOENT. Return values and control flow are unchanged. Signed-off-by: dengwenqi <[email protected]> Signed-off-by: ganjing <[email protected]> --- libs/libc/netdb/lib_gethostbyaddrr.c | 13 ++++++++++--- libs/libc/netdb/lib_gethostentbynamer.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libs/libc/netdb/lib_gethostbyaddrr.c b/libs/libc/netdb/lib_gethostbyaddrr.c index ce39670a4db..dcb59678331 100644 --- a/libs/libc/netdb/lib_gethostbyaddrr.c +++ b/libs/libc/netdb/lib_gethostbyaddrr.c @@ -258,9 +258,16 @@ int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type, { int errcode = -get_errno(); - nerr("ERROR: Failed to open the hosts file %s: %d\n", - CONFIG_NETDB_HOSTCONF_PATH, errcode); - UNUSED(errcode); + /* ENOENT just means no static host table is present; fall back + * to DNS silently. Only log unexpected open failures so that + * repeated address lookups do not spam the console. + */ + + if (errcode != -ENOENT) + { + nerr("ERROR: Failed to open the hosts file %s: %d\n", + CONFIG_NETDB_HOSTCONF_PATH, errcode); + } herrnocode = NO_RECOVERY; goto errorout_with_herrnocode; diff --git a/libs/libc/netdb/lib_gethostentbynamer.c b/libs/libc/netdb/lib_gethostentbynamer.c index b3921f456a5..bf9d3478c5a 100644 --- a/libs/libc/netdb/lib_gethostentbynamer.c +++ b/libs/libc/netdb/lib_gethostentbynamer.c @@ -591,8 +591,16 @@ static int lib_hostfile_lookup(FAR const char *name, { int errcode = -get_errno(); - nerr("ERROR: Failed to open the hosts file %s: %d\n", - CONFIG_NETDB_HOSTCONF_PATH, errcode); + /* ENOENT just means no static host table is present; fall back + * to DNS silently. Only log unexpected open failures so that + * repeated name lookups do not spam the console. + */ + + if (errcode != -ENOENT) + { + nerr("ERROR: Failed to open the hosts file %s: %d\n", + CONFIG_NETDB_HOSTCONF_PATH, errcode); + } return errcode; }
