From cde0b261b8976d168af0cfa05f68f0d2543c501e Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 27 Jan 2011 15:31:36 +0100 Subject: dnsproxy: Fallback to resolv.conf if dnsproxy fails In case dnsproxy can't create the socket listener we should fall back to resolv.conf. Reported by Kalle Valo --- src/connman.h | 2 +- src/dnsproxy.c | 12 ++---------- src/main.c | 2 -- src/resolver.c | 14 +++++++++++++- 4 files changed, 16 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/connman.h b/src/connman.h index 979c5646..bf31b62b 100644 --- a/src/connman.h +++ b/src/connman.h @@ -607,7 +607,7 @@ int __connman_iptables_command(const char *format, ...) __attribute__((format(printf, 1, 2))); int __connman_iptables_commit(const char *table_name); -int __connman_dnsproxy_init(connman_bool_t dnsproxy); +int __connman_dnsproxy_init(void); void __connman_dnsproxy_cleanup(void); int __connman_dnsproxy_append(const char *interface, const char *domain, const char *server); int __connman_dnsproxy_remove(const char *interface, const char *domain, const char *server); diff --git a/src/dnsproxy.c b/src/dnsproxy.c index 9c2f023e..b7667a61 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -114,7 +114,6 @@ struct request_data { gsize resplen; }; -static connman_bool_t dnsproxy_enabled = TRUE; static GSList *server_list = NULL; static GSList *request_list = NULL; static GSList *request_pending_list = NULL; @@ -1446,15 +1445,11 @@ static void destroy_listener(void) destroy_udp_listener(); } -int __connman_dnsproxy_init(connman_bool_t dnsproxy) +int __connman_dnsproxy_init(void) { int err; - DBG("dnsproxy %d", dnsproxy); - - dnsproxy_enabled = dnsproxy; - if (dnsproxy_enabled == FALSE) - return 0; + DBG(""); err = create_listener(); if (err < 0) @@ -1476,9 +1471,6 @@ void __connman_dnsproxy_cleanup(void) { DBG(""); - if (dnsproxy_enabled == FALSE) - return; - connman_notifier_unregister(&dnsproxy_notifier); destroy_listener(); diff --git a/src/main.c b/src/main.c index d8cc8eac..b64e4356 100644 --- a/src/main.c +++ b/src/main.c @@ -221,7 +221,6 @@ int main(int argc, char *argv[]) __connman_stats_init(); __connman_resolver_init(option_dnsproxy); - __connman_dnsproxy_init(option_dnsproxy); __connman_ipconfig_init(); __connman_rtnl_init(); __connman_task_init(); @@ -257,7 +256,6 @@ int main(int argc, char *argv[]) __connman_task_cleanup(); __connman_rtnl_cleanup(); __connman_ipconfig_cleanup(); - __connman_dnsproxy_cleanup(); __connman_resolver_cleanup(); __connman_stats_cleanup(); diff --git a/src/resolver.c b/src/resolver.c index 42be0304..73175b30 100644 --- a/src/resolver.c +++ b/src/resolver.c @@ -447,11 +447,23 @@ int __connman_resolver_init(connman_bool_t dnsproxy) { DBG("dnsproxy %d", dnsproxy); - dnsproxy_enabled = dnsproxy; + if (dnsproxy == FALSE) + return 0; + + if (__connman_dnsproxy_init() < 0) { + /* Fall back to resolv.conf */ + return 0; + } + + dnsproxy_enabled = TRUE; + return 0; } void __connman_resolver_cleanup(void) { DBG(""); + + if (dnsproxy_enabled == TRUE) + __connman_dnsproxy_cleanup(); } -- cgit v1.2.3