Permalink
Browse files

[droid] fix crash in network properties

We have no good access to a nameserver list, so we have to resort to popen.

Somehow this ends up being called from multiple threads, or back-to-back on the
same thread, and popen/fread get cranky about sharing. So we guard it with a
lock.
  • Loading branch information...
1 parent 8e9a218 commit 7decc93d9ad22176112a56f00de59a04656bf733 Cory Fields committed Jun 25, 2012
Showing with 24 additions and 2 deletions.
  1. +21 −2 xbmc/network/linux/NetworkLinux.cpp
  2. +3 −0 xbmc/network/linux/NetworkLinux.h
@@ -51,7 +51,6 @@
#include "NetworkLinux.h"
#include "Util.h"
#include "utils/log.h"
-
using namespace std;
CNetworkInterfaceLinux::CNetworkInterfaceLinux(CNetworkLinux* network, CStdString interfaceName, char interfaceMacAddrRaw[6])
@@ -460,7 +459,7 @@ std::vector<CStdString> CNetworkLinux::GetNameServers(void)
{
std::vector<CStdString> result;
-#if defined(TARGET_DARWIN) || defined(__ANDROID__)
+#if defined(TARGET_DARWIN)
//only finds the primary dns (0 :)
FILE* pipe = popen("scutil --dns | grep \"nameserver\\[0\\]\" | tail -n1", "r");
if (pipe)
@@ -478,6 +477,26 @@ std::vector<CStdString> CNetworkLinux::GetNameServers(void)
}
pclose(pipe);
}
+#elif defined(TARGET_ANDROID)
+ CSingleLock lock(m_critSection);
+ //only finds the primary dns (0 :)
+ FILE* pipe = popen("getprop net.dns1 | tail -n1", "r");
+ if (pipe)
+ {
+ CStdString tmpStr;
+ char buffer[256] = {'\0'};
+ if (fread(buffer, sizeof(char), sizeof(buffer), pipe) > 0 && !ferror(pipe))
+ {
+ tmpStr = buffer;
+ CLog::Log(LOGWARNING, "CNetworkLinux::GetNameServers: Got server: %s", tmpStr.c_str());
+ result.push_back(tmpStr);
+ }
+ else
+ {
+ CLog::Log(LOGWARNING, "Unable to determine nameserver");
+ }
+ pclose(pipe);
+ }
#else
res_init();
@@ -25,6 +25,8 @@
#include <vector>
#include "utils/StdString.h"
#include "network/Network.h"
+#include "threads/Thread.h"
+#include "threads/CriticalSection.h"
class CNetworkLinux;
@@ -89,6 +91,7 @@ class CNetworkLinux : public CNetwork
void queryInterfaceList();
std::vector<CNetworkInterface*> m_interfaces;
int m_sock;
+ CCriticalSection m_critSection;
};
#endif

0 comments on commit 7decc93

Please sign in to comment.