git-annex/standalone/android/haskell-patches/dns_use-android-net.dns1-command-instead-of-resolv.conf.patch

67 lines
2.5 KiB
Diff
Raw Normal View History

2014-07-03 23:47:49 +00:00
From aaef1aadb21a198475a656132ef4488b85b8fd1b Mon Sep 17 00:00:00 2001
2014-05-26 02:47:15 +00:00
From: dummy <dummy@example.com>
2014-07-03 23:47:49 +00:00
Date: Thu, 3 Jul 2014 23:22:47 +0000
Subject: [PATCH] use android net.dns1 command instead of resolv.conf file
Android has no /etc/resolv.conf. Some might have /system/etc/resolv.conf,
but even that does not seem likely.
This is likely a little slow, but is at least fine for git-annex's uses,
since it only uses this library for occasional SRV lookups.
---
2014-07-03 23:47:49 +00:00
Network/DNS/Resolver.hs | 11 +++++++++--
2014-05-26 02:47:15 +00:00
dns.cabal | 1 +
2014-07-03 23:47:49 +00:00
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/Network/DNS/Resolver.hs b/Network/DNS/Resolver.hs
2014-07-03 23:47:49 +00:00
index e4124b8..7aca431 100644
--- a/Network/DNS/Resolver.hs
+++ b/Network/DNS/Resolver.hs
2014-05-26 02:47:15 +00:00
@@ -19,7 +19,7 @@ module Network.DNS.Resolver (
) where
import Control.Applicative ((<$>), (<*>), pure)
-import Control.Exception (bracket)
+import Control.Exception (bracket, catch, IOException)
import qualified Data.ByteString.Char8 as BS
import Data.Char (isSpace)
import Data.List (isPrefixOf)
2014-07-03 23:47:49 +00:00
@@ -32,6 +32,7 @@ import Network.Socket (AddrInfoFlag(..), AddrInfo(..), SockAddr(..), PortNumber(
import Prelude hiding (lookup)
2014-05-26 02:47:15 +00:00
import System.Random (getStdRandom, randomR)
import System.Timeout (timeout)
+import System.Process
#if mingw32_HOST_OS == 1
import Network.Socket (send)
2014-07-03 23:47:49 +00:00
@@ -132,7 +133,13 @@ makeResolvSeed conf = ResolvSeed <$> addr
addr = case resolvInfo conf of
2014-07-03 23:47:49 +00:00
RCHostName numhost -> makeAddrInfo numhost Nothing
RCHostPort numhost mport -> makeAddrInfo numhost $ Just mport
- RCFilePath file -> toAddr <$> readFile file >>= \i -> makeAddrInfo i Nothing
+ RCFilePath file -> do
+ -- Android has no /etc/resolv.conf; use getprop command.
+ ls <- catch (lines <$> readProcess "getprop" ["net.dns1"] []) (const (return []) :: IOException -> IO [String])
2014-07-03 23:47:49 +00:00
+ let addr = case ls of
+ [] -> "8.8.8.8" -- google public dns as a fallback only
+ (l:_) -> l
2014-07-03 23:47:49 +00:00
+ makeAddrInfo addr Nothing
toAddr cs = let l:_ = filter ("nameserver" `isPrefixOf`) $ lines cs
in extract l
extract = reverse . dropWhile isSpace . reverse . dropWhile isSpace . drop 11
diff --git a/dns.cabal b/dns.cabal
2014-07-03 23:47:49 +00:00
index 0a08a9e..724a3e0 100644
--- a/dns.cabal
+++ b/dns.cabal
2014-07-03 23:47:49 +00:00
@@ -38,6 +38,7 @@ Library
, network >= 2.3
, random
2014-05-26 02:47:15 +00:00
, resourcet
+ , process
else
Build-Depends: base >= 4 && < 5
, attoparsec
--
2014-05-26 02:47:15 +00:00
1.7.10.4