From 4dc453c08796da93eaa82a0af36029c265893300 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 16 Feb 2007 19:17:05 +0000 Subject: add debug messages for fopen() failures --- ares/ares_gethostbyaddr.c | 19 ++++++++++++++++++- ares/ares_search.c | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'ares') diff --git a/ares/ares_gethostbyaddr.c b/ares/ares_gethostbyaddr.c index 41bf916bf..6c80eb941 100644 --- a/ares/ares_gethostbyaddr.c +++ b/ares/ares_gethostbyaddr.c @@ -216,9 +216,26 @@ static int file_lookup(union ares_addr *addr, int family, struct hostent **host) return ARES_ENOTFOUND; #endif + int error; + fp = fopen(PATH_HOSTS, "r"); if (!fp) - return ARES_ENOTFOUND; + { + error = ERRNO; + switch(error) + { + case ENOENT: + return ARES_ENOTFOUND; + break; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", + PATH_HOSTS)); + *host = NULL; + return ARES_EFILE; + } + } while ((status = ares__get_hostent(fp, family, host)) == ARES_SUCCESS) { if (family != (*host)->h_addrtype) diff --git a/ares/ares_search.c b/ares/ares_search.c index b05b4a833..e63afff05 100644 --- a/ares/ares_search.c +++ b/ares/ares_search.c @@ -216,6 +216,7 @@ static int single_domain(ares_channel channel, const char *name, char **s) char *line = NULL; int linesize, status; const char *p, *q; + int error; /* If the name contains a trailing dot, then the single query is the name * sans the trailing dot. @@ -265,6 +266,22 @@ static int single_domain(ares_channel channel, const char *name, char **s) if (status != ARES_SUCCESS) return status; } + else + { + error = ERRNO; + switch(error) + { + case ENOENT: + break; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", + hostaliases)); + *s = NULL; + return ARES_EFILE; + } + } } } -- cgit v1.2.3