summaryrefslogtreecommitdiff
path: root/ares_init.c
diff options
context:
space:
mode:
authorYu Jiung <jiung.yu@samsung.com>2016-11-09 11:23:06 +0900
committerYu Jiung <jiung.yu@samsung.com>2016-11-09 11:23:15 +0900
commit8e609b5f488d486a9e066ed494218d966f489938 (patch)
tree0a169eb7025401e0a14ab5d5e74db5b27954f591 /ares_init.c
parenteb886f120599b2a184db20b527db6dfdfcb7852e (diff)
downloadc-ares-8e609b5f488d486a9e066ed494218d966f489938.tar.gz
c-ares-8e609b5f488d486a9e066ed494218d966f489938.tar.bz2
c-ares-8e609b5f488d486a9e066ed494218d966f489938.zip
Imported Upstream version 1.12.0upstream/1.12.0
Change-Id: I6a571bddd24d1cb7d64b74bc66e878ccba2ce638
Diffstat (limited to 'ares_init.c')
-rw-r--r--ares_init.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/ares_init.c b/ares_init.c
index 55d9327..f557947 100644
--- a/ares_init.c
+++ b/ares_init.c
@@ -112,7 +112,6 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
ares_channel channel;
int i;
int status = ARES_SUCCESS;
- int status2;
struct timeval now;
#ifdef CURLDEBUG
@@ -190,18 +189,17 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
* precedence to lowest.
*/
- if (status == ARES_SUCCESS) {
- status = init_by_options(channel, options, optmask);
- if (status != ARES_SUCCESS)
- DEBUGF(fprintf(stderr, "Error: init_by_options failed: %s\n",
- ares_strerror(status)));
- }
- if (status == ARES_SUCCESS) {
- status = init_by_environment(channel);
- if (status != ARES_SUCCESS)
- DEBUGF(fprintf(stderr, "Error: init_by_environment failed: %s\n",
- ares_strerror(status)));
+ status = init_by_options(channel, options, optmask);
+ if (status != ARES_SUCCESS) {
+ DEBUGF(fprintf(stderr, "Error: init_by_options failed: %s\n",
+ ares_strerror(status)));
+ /* If we fail to apply user-specified options, fail the whole init process */
+ goto done;
}
+ status = init_by_environment(channel);
+ if (status != ARES_SUCCESS)
+ DEBUGF(fprintf(stderr, "Error: init_by_environment failed: %s\n",
+ ares_strerror(status)));
if (status == ARES_SUCCESS) {
status = init_by_resolv_conf(channel);
if (status != ARES_SUCCESS)
@@ -213,13 +211,10 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
* No matter what failed or succeeded, seed defaults to provide
* useful behavior for things that we missed.
*/
- status2 = init_by_defaults(channel);
- if (status2 != ARES_SUCCESS) {
+ status = init_by_defaults(channel);
+ if (status != ARES_SUCCESS)
DEBUGF(fprintf(stderr, "Error: init_by_defaults failed: %s\n",
ares_strerror(status)));
- if (status == ARES_SUCCESS)
- status = status2;
- }
/* Generate random key */
@@ -232,6 +227,7 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
ares_strerror(status)));
}
+done:
if (status != ARES_SUCCESS)
{
/* Something failed; clean up memory we may have allocated. */
@@ -350,8 +346,8 @@ int ares_save_options(ares_channel channel, struct ares_options *options,
(*optmask) = (ARES_OPT_FLAGS|ARES_OPT_TRIES|ARES_OPT_NDOTS|
ARES_OPT_UDP_PORT|ARES_OPT_TCP_PORT|ARES_OPT_SOCK_STATE_CB|
ARES_OPT_SERVERS|ARES_OPT_DOMAINS|ARES_OPT_LOOKUPS|
- ARES_OPT_SORTLIST|ARES_OPT_TIMEOUTMS) |
- (channel->optmask & ARES_OPT_ROTATE);
+ ARES_OPT_SORTLIST|ARES_OPT_TIMEOUTMS);
+ (*optmask) |= (channel->rotate ? ARES_OPT_ROTATE : ARES_OPT_NOROTATE);
/* Copy easy stuff */
options->flags = channel->flags;
@@ -447,6 +443,8 @@ static int init_by_options(ares_channel channel,
channel->ndots = options->ndots;
if ((optmask & ARES_OPT_ROTATE) && channel->rotate == -1)
channel->rotate = 1;
+ if ((optmask & ARES_OPT_NOROTATE) && channel->rotate == -1)
+ channel->rotate = 0;
if ((optmask & ARES_OPT_UDP_PORT) && channel->udp_port == -1)
channel->udp_port = htons(options->udp_port);
if ((optmask & ARES_OPT_TCP_PORT) && channel->tcp_port == -1)
@@ -520,13 +518,14 @@ static int init_by_options(ares_channel channel,
}
/* copy sortlist */
- if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1) &&
- (options->nsort>0)) {
- channel->sortlist = ares_malloc(options->nsort * sizeof(struct apattern));
- if (!channel->sortlist)
- return ARES_ENOMEM;
- for (i = 0; i < options->nsort; i++)
- channel->sortlist[i] = options->sortlist[i];
+ if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1)) {
+ if (options->nsort > 0) {
+ channel->sortlist = ares_malloc(options->nsort * sizeof(struct apattern));
+ if (!channel->sortlist)
+ return ARES_ENOMEM;
+ for (i = 0; i < options->nsort; i++)
+ channel->sortlist[i] = options->sortlist[i];
+ }
channel->nsort = options->nsort;
}
@@ -1623,7 +1622,7 @@ static int config_lookup(ares_channel channel, const char *str,
channel->lookups = ares_strdup(lookups);
return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM;
}
-#endif /* !WIN32 & !WATT32 & !ANDROID & !__ANDROID__ */
+#endif /* !WIN32 & !WATT32 & !ANDROID & !__ANDROID__ & !CARES_USE_LIBRESOLV */
#ifndef WATT32
static int config_nameserver(struct server_state **servers, int *nservers,