Changeset 49235 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Oct 22, 2013 6:56:03 PM (11 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/HostDnsService.cpp
r49228 r49235 26 26 #include <iprt/semaphore.h> 27 27 #include <iprt/critsect.h> 28 29 #include <algorithm> 30 #include <string> 31 #include <vector> 28 32 #include "HostDnsService.h" 33 34 35 static HostDnsMonitor *g_monitor; 36 29 37 30 38 /* Lockee */ … … 49 57 50 58 51 HostDnsService::HostDnsService(){} 52 53 HostDnsService::~HostDnsService () 54 { 55 int rc = RTCritSectDelete(&m_hCritSect); 56 AssertRC(rc); 57 } 58 59 60 HRESULT HostDnsService::init(const VirtualBox *aParent) 61 { 62 mParent = aParent; 63 64 int rc = RTCritSectInit(&m_hCritSect); 65 AssertRCReturn(rc, E_FAIL); 66 return S_OK; 67 } 68 69 HRESULT HostDnsService::start() 70 { 71 return S_OK; 72 } 73 74 void HostDnsService::stop() 75 { 76 } 77 78 HRESULT HostDnsService::update() 79 { 80 unconst(mParent)->onHostNameResolutionConfigurationChange(); 81 return S_OK; 82 } 83 84 STDMETHODIMP HostDnsService::COMGETTER(NameServers)(ComSafeArrayOut(BSTR, aNameServers)) 85 { 86 RTCritSectEnter(&m_hCritSect); 87 com::SafeArray<BSTR> nameServers(m_llNameServers.size()); 88 89 Utf8StrListIterator it; 59 60 inline static void detachVectorOfString(const std::vector<std::string>& v, 61 ComSafeArrayOut(BSTR, aBstrArray)) 62 { 63 com::SafeArray<BSTR> aBstr(v.size()); 64 65 std::vector<std::string>::const_iterator it; 66 90 67 int i = 0; 91 for (it = m_llNameServers.begin(); it != m_llNameServers.end(); ++it, ++i) 92 (*it).cloneTo(&nameServers[i]); 93 94 nameServers.detachTo(ComSafeArrayOutArg(aNameServers)); 95 96 RTCritSectLeave(&m_hCritSect); 97 98 return S_OK; 99 } 100 101 102 STDMETHODIMP HostDnsService::COMGETTER(DomainName)(BSTR *aDomainName) 103 { 104 RTCritSectEnter(&m_hCritSect); 105 106 m_DomainName.cloneTo(aDomainName); 107 108 RTCritSectLeave(&m_hCritSect); 109 110 return S_OK; 111 } 112 113 114 STDMETHODIMP HostDnsService::COMGETTER(SearchStrings)(ComSafeArrayOut(BSTR, aSearchStrings)) 115 { 116 RTCritSectEnter(&m_hCritSect); 117 118 com::SafeArray<BSTR> searchString(m_llSearchStrings.size()); 119 120 Utf8StrListIterator it; 121 int i = 0; 122 for (it = m_llSearchStrings.begin(); it != m_llSearchStrings.end(); ++it, ++i) 123 (*it).cloneTo(&searchString[i]); 124 125 126 searchString.detachTo(ComSafeArrayOutArg(aSearchStrings)); 127 128 RTCritSectLeave(&m_hCritSect); 129 130 return S_OK; 131 } 132 68 it = v.begin(); 69 for (; it != v.end(); ++it, ++i) 70 Utf8Str(it->c_str()).cloneTo(&aBstr[i]); 71 72 aBstr.detachTo(ComSafeArrayOutArg(aBstrArray)); 73 } 74 75 76 struct HostDnsMonitor::Data 77 { 78 std::vector<HostDnsMonitorProxy> proxies; 79 HostDnsInformation info; 80 }; 81 82 83 struct HostDnsMonitorProxy::Data 84 { 85 Data(const HostDnsMonitor* mon, const VirtualBox* vbox): 86 info(NULL), virtualbox(vbox), monitor(mon), fModified(true){} 87 88 virtual ~Data() {if (info) delete info;} 89 90 HostDnsInformation *info; 91 const VirtualBox *virtualbox; 92 const HostDnsMonitor* monitor; 93 bool fModified; 94 }; 95 96 97 HostDnsMonitor::HostDnsMonitor():m(NULL){} 98 99 100 HostDnsMonitor::~HostDnsMonitor(){if (m) delete m;} 101 102 103 const HostDnsMonitor* HostDnsMonitor::getHostDnsMonitor() 104 { 105 /* XXX: Moved initialization from HostImpl.cpp */ 106 if (!g_monitor) 107 { 108 g_monitor = 109 # if defined (RT_OS_DARWIN) 110 new HostDnsServiceDarwin(); 111 # elif defined(RT_OS_WINDOWS) 112 new HostDnsServiceWin(); 113 # elif defined(RT_OS_LINUX) 114 new HostDnsServiceLinux(); 115 # elif defined(RT_OS_SOLARIS) 116 new HostDnsServiceSolaris(); 117 # elif defined(RT_OS_OS2) 118 new HostDnsServiceOs2(); 119 # else 120 new HostDnsService(); 121 # endif 122 g_monitor->init(); 123 } 124 return g_monitor; 125 } 126 127 128 void HostDnsMonitor::addMonitorProxy(const HostDnsMonitorProxy& proxy) const 129 { 130 ALock l(this); 131 m->proxies.push_back(proxy); 132 133 proxy.notify(); 134 } 135 136 137 void HostDnsMonitor::releaseMonitorProxy(const HostDnsMonitorProxy& proxy) const 138 { 139 ALock l(this); 140 std::vector<HostDnsMonitorProxy>::iterator it; 141 it = std::find(m->proxies.begin(), m->proxies.end(), proxy); 142 143 if (it == m->proxies.end()) 144 return; 145 146 m->proxies.erase(it); 147 } 148 149 150 void HostDnsMonitor::shutdown() 151 { 152 if (g_monitor) 153 { 154 delete g_monitor; 155 g_monitor = NULL; 156 } 157 } 158 159 160 const HostDnsInformation& HostDnsMonitor::getInfo() const 161 { 162 ALock l(this); 163 return m->info; 164 } 165 166 167 void HostDnsMonitor::notifyAll() const 168 { 169 ALock l(this); 170 std::vector<HostDnsMonitorProxy>::const_iterator it; 171 for (it = m->proxies.begin(); it != m->proxies.end(); ++it) 172 it->notify(); 173 } 174 175 176 void HostDnsMonitor::setInfo(const HostDnsInformation& info) 177 { 178 ALock l(this); 179 m->info = info; 180 } 181 182 183 HRESULT HostDnsMonitor::init() 184 { 185 m = new HostDnsMonitor::Data(); 186 return S_OK; 187 } 188 189 /* HostDnsMonitorProxy */ 190 HostDnsMonitorProxy::HostDnsMonitorProxy():m(NULL){} 191 192 HostDnsMonitorProxy::~HostDnsMonitorProxy() 193 { 194 if (m && m->monitor) 195 { 196 m->monitor->releaseMonitorProxy(*this); 197 delete m; 198 } 199 } 200 201 202 void HostDnsMonitorProxy::init(const HostDnsMonitor* mon, const VirtualBox* aParent) 203 { 204 m = new HostDnsMonitorProxy::Data(mon, aParent); 205 m->monitor->addMonitorProxy(*this); 206 updateInfo(); 207 } 208 209 210 void HostDnsMonitorProxy::notify() const 211 { 212 m->fModified = true; 213 const_cast<VirtualBox *>(m->virtualbox)->onHostNameResolutionConfigurationChange(); 214 } 215 216 217 STDMETHODIMP HostDnsMonitorProxy::COMGETTER(NameServers)(ComSafeArrayOut(BSTR, aNameServers)) 218 { 219 AssertReturn(m && m->info, E_FAIL); 220 ALock l(this); 221 222 if (m->fModified) 223 updateInfo(); 224 225 detachVectorOfString(m->info->servers, ComSafeArrayOutArg(aNameServers)); 226 227 return S_OK; 228 } 229 230 231 STDMETHODIMP HostDnsMonitorProxy::COMGETTER(DomainName)(BSTR *aDomainName) 232 { 233 AssertReturn(m && m->info, E_FAIL); 234 ALock l(this); 235 236 if (m->fModified) 237 updateInfo(); 238 239 Utf8Str(m->info->domain.c_str()).cloneTo(aDomainName); 240 241 return S_OK; 242 } 243 244 245 STDMETHODIMP HostDnsMonitorProxy::COMGETTER(SearchStrings)(ComSafeArrayOut(BSTR, aSearchStrings)) 246 { 247 AssertReturn(m && m->info, E_FAIL); 248 ALock l(this); 249 250 if (m->fModified) 251 updateInfo(); 252 253 detachVectorOfString(m->info->searchList, ComSafeArrayOutArg(aSearchStrings)); 254 255 return S_OK; 256 } 257 258 259 bool HostDnsMonitorProxy::operator==(const HostDnsMonitorProxy& rhs) 260 { 261 if (!m || rhs.m) return false; 262 263 /** 264 * we've assigned to the same instance of VirtualBox. 265 */ 266 return m->virtualbox == rhs.m->virtualbox; 267 } 268 269 void HostDnsMonitorProxy::updateInfo() 270 { 271 HostDnsInformation *i = new HostDnsInformation(m->monitor->getInfo()); 272 HostDnsInformation *old = m->info; 273 274 if (old) 275 { 276 m->info = i; 277 delete old; 278 } 279 else 280 m->info = i; 281 282 m->fModified = false; 283 } -
trunk/src/VBox/Main/src-server/HostDnsService.h
r49228 r49235 54 54 55 55 56 class HostDnsService 57 { 58 public: 59 HostDnsService(); 60 virtual ~HostDnsService(); 61 virtual HRESULT init(const VirtualBox *aParent); 62 virtual HRESULT start(void); 63 virtual void stop(void); 56 struct HostDnsInformation 57 { 58 std::vector<std::string> servers; 59 std::string domain; 60 std::vector<std::string> searchList; 61 }; 62 63 64 class HostDnsMonitorProxy; 65 66 /** 67 * This class supposed to be a real DNS monitor object it should be singleton, 68 * it lifecycle starts and ends together with VBoxSVC. 69 * 70 */ 71 class HostDnsMonitor:public Lockee 72 { 73 public: 74 static const HostDnsMonitor* getHostDnsMonitor(); 75 static void shutdown(); 76 77 void addMonitorProxy(const HostDnsMonitorProxy&) const; 78 void releaseMonitorProxy(const HostDnsMonitorProxy&) const; 79 const HostDnsInformation& getInfo() const; 80 virtual HRESULT init(); 81 82 83 protected: 84 void notifyAll() const; 85 void setInfo(const HostDnsInformation&); 86 HostDnsMonitor(); 87 virtual ~HostDnsMonitor(); 88 89 private: 90 HostDnsMonitor(const HostDnsMonitor&); 91 HostDnsMonitor& operator= (const HostDnsMonitor&); 92 93 public: 94 struct Data; 95 Data *m; 96 }; 97 98 /** 99 * This class supposed to be a proxy for events on changing Host Name Resolving configurations. 100 */ 101 class HostDnsMonitorProxy: public Lockee 102 { 103 public: 104 HostDnsMonitorProxy(); 105 ~HostDnsMonitorProxy(); 106 void init(const HostDnsMonitor* mon, const VirtualBox* aParent); 107 void notify() const; 108 64 109 STDMETHOD(COMGETTER(NameServers))(ComSafeArrayOut(BSTR, aNameServers)); 65 110 STDMETHOD(COMGETTER(DomainName))(BSTR *aDomainName); 66 111 STDMETHOD(COMGETTER(SearchStrings))(ComSafeArrayOut(BSTR, aSearchStrings)); 67 112 113 bool operator==(const HostDnsMonitorProxy&); 114 115 private: 116 void updateInfo(); 117 118 private: 119 struct Data; 120 Data *m; 121 }; 122 123 # ifdef RT_OS_DARWIN 124 class HostDnsServiceDarwin: public HostDnsMonitor 125 { 126 public: 127 HostDnsServiceDarwin(); 128 ~HostDnsServiceDarwin(); 129 HRESULT init(); 130 131 private: 132 HRESULT updateInfo(); 133 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info); 134 }; 135 # endif 136 # ifdef RT_OS_WINDOWS 137 class HostDnsServiceWin: public HostDnsMonitor 138 { 139 public: 140 HostDnsServiceWin(); 141 ~HostDnsServiceWin(); 142 HRESULT init(); 143 144 private: 145 void strList2List(std::vector<std::string>& lst, char *strLst); 146 HRESULT updateInfo(); 147 }; 148 # endif 149 # if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) 150 class HostDnsServiceResolvConf: public HostDnsMonitor 151 { 152 public: 153 HostDnsServiceResolvConf():m(NULL){} 154 virtual ~HostDnsServiceResolvConf(); 155 virtual HRESULT init(const char *aResolvConfFileName); 156 const std::string& resolvConf(); 157 68 158 protected: 69 virtual HRESULT update(void); 70 71 /* XXX: hide it with struct Data together with <list> */ 72 Utf8StrList m_llNameServers; 73 Utf8StrList m_llSearchStrings; 74 com::Utf8Str m_DomainName; 75 RTCRITSECT m_hCritSect; 76 77 private: 78 const VirtualBox *mParent; 79 HostDnsService(const HostDnsService&); 80 HostDnsService& operator =(const HostDnsService&); 81 }; 82 83 # ifdef RT_OS_DARWIN 84 class HostDnsServiceDarwin: public HostDnsService 85 { 86 public: 87 HostDnsServiceDarwin(); 88 virtual ~HostDnsServiceDarwin(); 89 90 virtual HRESULT init(const VirtualBox *aParent); 91 virtual HRESULT start(void); 92 virtual void stop(void); 93 virtual HRESULT update(); 94 95 private: 96 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info); 97 98 }; 99 # endif 100 101 # ifdef RT_OS_WINDOWS 102 class HostDnsServiceWin: public HostDnsService 103 { 104 public: 105 HostDnsServiceWin(); 106 virtual ~HostDnsServiceWin(); 107 108 virtual HRESULT init(const VirtualBox *aParent); 109 virtual HRESULT start(void); 110 virtual void stop(void); 111 virtual HRESULT update(); 112 void strList2List(Utf8StrList& lst, char *strLst); 113 }; 114 # endif 115 116 #if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) 117 118 class HostDnsServiceResolvConf: public HostDnsService 119 { 120 public: 121 HostDnsServiceResolvConf(const char *aResolvConfFileName = "/etc/resolv.conf"); 122 virtual ~HostDnsServiceResolvConf(); 123 virtual HRESULT init(const VirtualBox *aParent); 124 virtual HRESULT update(); 125 const com::Utf8Str resolvConf() {return m_ResolvConfFilename; } 126 protected: 127 com::Utf8Str m_ResolvConfFilename; 128 RTFILE m_ResolvConfFile; 129 }; 130 159 HRESULT readResolvConf(); 160 161 protected: 162 struct Data; 163 Data *m; 164 }; 131 165 # if defined(RT_OS_SOLARIS) 132 166 /** … … 135 169 class HostDnsServiceSolaris: public HostDnsServiceResolvConf 136 170 { 137 public:171 public: 138 172 HostDnsServiceSolaris(){} 139 virtual ~HostDnsServiceSolaris(){} 140 }; 173 ~HostDnsServiceSolaris(){} 174 HRESULT init(){ return init("/etc/resolv.conf");} 175 }; 176 141 177 # elif defined(RT_OS_LINUX) 142 178 class HostDnsServiceLinux: public HostDnsServiceResolvConf … … 144 180 public: 145 181 HostDnsServiceLinux(){} 146 virtual ~HostDnsServiceLinux(){}147 virtual HRESULT init(const VirtualBox *aParent);148 virtual void stop(void);182 ~HostDnsServiceLinux(); 183 HRESULT init() {return init("/etc/resolv.conf");} 184 HRESULT init(const char *aResolvConfFileName); 149 185 150 186 static int hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser); … … 155 191 { 156 192 public: 157 HostDnsServiceOs2() 158 { 159 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */ 160 ::HostDnsServiceResolvConf("\\MPTN\\ETC\\RESOLV2"); 161 } 162 virtual ~HostDnsServiceOs2(){} 163 }; 193 HostDnsServiceOs2(){} 194 ~HostDnsServiceOs2(){} 195 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */ 196 HRESULT init(){ return init("\\MPTN\\ETC\\RESOLV2");} 197 }; 198 164 199 # endif 165 # endif200 # endif 166 201 167 202 #endif /* !___H_DNSHOSTSERVICE */ -
trunk/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp
r48955 r49235 3 3 #include <VBox/com/ptr.h> 4 4 5 #include "HostDnsService.h"6 5 7 6 #ifdef RT_OS_OS2 … … 19 18 #include <iprt/err.h> 20 19 #include <iprt/file.h> 20 #include <iprt/critsect.h> 21 21 22 22 #include <VBox/log.h> 23 24 #include <string> 25 #include <vector> 26 27 #include "HostDnsService.h" 28 29 30 struct HostDnsServiceResolvConf::Data 31 { 32 Data(const char *fileName):resolvConfFilename(fileName){}; 33 34 std::string resolvConfFilename; 35 }; 36 37 38 const std::string& HostDnsServiceResolvConf::resolvConf() 39 { 40 return m->resolvConfFilename; 41 } 23 42 24 43 … … 51 70 52 71 53 HostDnsServiceResolvConf:: HostDnsServiceResolvConf(const char* aResolvConfFilename)72 HostDnsServiceResolvConf::~HostDnsServiceResolvConf() 54 73 { 55 m_ResolvConfFilename = com::Utf8Str(aResolvConfFilename);74 if (m) delete m; 56 75 } 57 76 58 77 59 H ostDnsServiceResolvConf::~HostDnsServiceResolvConf()78 HRESULT HostDnsServiceResolvConf::init(const char *aResolvConfFileName) 60 79 { 61 m_ResolvConfFilename.setNull(); 62 RTFileClose(m_ResolvConfFile); 63 } 80 HostDnsMonitor::init(); 64 81 65 HRESULT HostDnsServiceResolvConf::init(const VirtualBox *aParent) 66 { 67 HRESULT hrc; 68 69 int rc = RTFileOpen(&m_ResolvConfFile, m_ResolvConfFilename.c_str(), 70 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 71 AssertRCReturn(rc, E_FAIL); 72 73 74 hrc = HostDnsService::init(aParent); 75 AssertComRCReturn(hrc, hrc); 76 77 78 79 hrc = update(); 80 AssertComRCReturn(hrc, hrc); 82 m = new Data(aResolvConfFileName); 83 readResolvConf(); 81 84 82 85 return S_OK; … … 84 87 85 88 86 HRESULT HostDnsServiceResolvConf:: update()89 HRESULT HostDnsServiceResolvConf::readResolvConf() 87 90 { 88 91 char buff[256]; … … 91 94 bool fWarnTooManyDnsServers = false; 92 95 struct in_addr tmp_addr; 93 int rc;94 96 size_t bytes; 97 HostDnsInformation info; 98 RTFILE resolvConfFile; 95 99 96 while ( RT_SUCCESS(rc = fileGets(m_ResolvConfFile, buff, sizeof(buff), &bytes)) 100 int rc = RTFileOpen(&resolvConfFile, m->resolvConfFilename.c_str(), 101 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 102 AssertRCReturn(rc, E_FAIL); 103 104 while ( RT_SUCCESS(rc = fileGets(resolvConfFile, buff, sizeof(buff), &bytes)) 97 105 && rc != VERR_EOF) 98 106 { … … 110 118 continue; 111 119 112 m_llNameServers.push_back(com::Utf8Str(buff2));120 info.servers.push_back(std::string(buff2)); 113 121 114 122 cNameserversFound++; … … 122 130 123 131 if (tok != NULL) 124 m_DomainName = com::Utf8Str(tok);132 info.domain = std::string(tok); 125 133 } 126 134 } 127 135 136 RTFileClose(resolvConfFile); 137 138 setInfo(info); 139 128 140 return S_OK; 129 130 141 } -
trunk/src/VBox/Main/src-server/HostImpl.cpp
r49132 r49235 23 23 24 24 #include "HostImpl.h" 25 #include "HostDnsService.h"26 25 27 26 #ifdef VBOX_WITH_USB … … 172 171 173 172 #include <algorithm> 173 #include <string> 174 #include <vector> 175 176 #include "HostDnsService.h" 174 177 175 178 //////////////////////////////////////////////////////////////////////////////// … … 225 228 HostPowerService *pHostPowerService; 226 229 /** Host's DNS informaton fetching */ 227 HostDns Service *pHostDnsService;230 HostDnsMonitorProxy hostDnsMonitorProxy; 228 231 }; 229 232 … … 292 295 updateNetIfList(); 293 296 294 # if defined (RT_OS_DARWIN) 295 m->pHostDnsService = new HostDnsServiceDarwin(); 296 # elif defined(RT_OS_WINDOWS) 297 m->pHostDnsService = new HostDnsServiceWin(); 298 # elif defined(RT_OS_LINUX) 299 m->pHostDnsService = new HostDnsServiceLinux(); 300 # elif defined(RT_OS_SOLARIS) 301 m->pHostDnsService = new HostDnsServiceSolaris(); 302 # elif defined(RT_OS_OS2) 303 m->pHostDnsService = new HostDnsServiceOs2(); 304 # else 305 m->pHostDnsService = new HostDnsService(); 306 # endif 307 308 hrc = m->pHostDnsService->init(m->pParent); 309 AssertComRCReturn(hrc, hrc); 310 311 hrc = m->pHostDnsService->start(); 312 AssertComRCReturn(hrc, hrc); 297 m->hostDnsMonitorProxy.init(HostDnsMonitor::getHostDnsMonitor(), m->pParent); 313 298 314 299 #if defined (RT_OS_WINDOWS) … … 513 498 #endif 514 499 515 m->pHostDnsService->stop();516 517 delete m->pHostDnsService;518 500 delete m; 519 501 m = NULL; … … 851 833 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 852 834 853 return m-> pHostDnsService->COMGETTER(NameServers)(ComSafeArrayOutArg(aNameServers));835 return m->hostDnsMonitorProxy.COMGETTER(NameServers)(ComSafeArrayOutArg(aNameServers)); 854 836 } 855 837 … … 866 848 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 867 849 868 return m-> pHostDnsService->COMGETTER(DomainName)(aDomainName);850 return m->hostDnsMonitorProxy.COMGETTER(DomainName)(aDomainName); 869 851 } 870 852 … … 882 864 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 883 865 884 return m-> pHostDnsService->COMGETTER(SearchStrings)(ComSafeArrayOutArg(aSearchStrings));866 return m->hostDnsMonitorProxy.COMGETTER(SearchStrings)(ComSafeArrayOutArg(aSearchStrings)); 885 867 } 886 868 -
trunk/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp
r48955 r49235 70 70 } 71 71 72 72 73 HostDnsServiceDarwin::HostDnsServiceDarwin(){} 74 75 73 76 HostDnsServiceDarwin::~HostDnsServiceDarwin() 74 77 { 78 if (g_RunLoopRef) 79 CFRunLoopStop(g_RunLoopRef); 80 75 81 CFRelease(g_DnsWatcher); 82 76 83 CFRelease(g_store); 77 84 } 85 78 86 79 87 void HostDnsServiceDarwin::hostDnsServiceStoreCallback(void *arg0, void *arg1, void *info) … … 85 93 86 94 RTCritSectEnter(&pThis->m_hCritSect); 87 pThis->update(); 95 pThis->updateInfo(); 96 pThis->notifyAll(); 88 97 RTCritSectLeave(&pThis->m_hCritSect); 89 98 } 99 90 100 91 101 HRESULT HostDnsServiceDarwin::init(const VirtualBox *aParent) … … 111 121 AssertRCReturn(rc, E_FAIL); 112 122 113 return update(); 114 } 115 116 117 118 HRESULT HostDnsServiceDarwin::start() 119 { 120 int rc = RTThreadCreate(&g_DnsMonitoringThread, hostMonitoringRoutine, 121 this, 128 * _1K, RTTHREADTYPE_IO, 0, "dns-monitor"); 123 rc = RTThreadCreate(&g_DnsMonitoringThread, hostMonitoringRoutine, 124 this, 128 * _1K, RTTHREADTYPE_IO, 0, "dns-monitor"); 122 125 AssertRCReturn(rc, E_FAIL); 123 126 124 127 RTSemEventWait(g_DnsInitEvent, RT_INDEFINITE_WAIT); 125 126 return S_OK; 127 } 128 129 130 void HostDnsServiceDarwin::stop() 131 { 132 133 if (g_RunLoopRef) 134 CFRunLoopStop(g_RunLoopRef); 135 } 136 137 138 HRESULT HostDnsServiceDarwin::update() 139 { 140 m_llNameServers.clear(); 141 m_llSearchStrings.clear(); 142 m_DomainName.setNull(); 143 128 return updateInfo(); 129 } 130 131 132 HRESULT HostDnsServiceDarwin::updateInfo() 133 { 144 134 CFPropertyListRef propertyRef = SCDynamicStoreCopyValue(g_store, 145 135 kStateNetworkGlobalDNSKey); … … 165 155 return S_OK; 166 156 157 HostDnsInformation info; 167 158 CFStringRef domainNameRef = (CFStringRef)CFDictionaryGetValue( 168 159 static_cast<CFDictionaryRef>(propertyRef), CFSTR("DomainName")); … … 172 163 CFStringGetSystemEncoding()); 173 164 if (pszDomainName) 174 m_DomainName = com::Utf8Str(pszDomainName);165 info.domain = pszDomainName; 175 166 } 176 167 … … 191 182 if (!pszServerAddress) 192 183 continue; 193 194 m_llNameServers.push_back(com::Utf8Str(pszServerAddress));184 185 info.servers.push_back(std::string(pszServerAddress)); 195 186 } 196 187 } … … 213 204 continue; 214 205 215 m_llSearchStrings.push_back(com::Utf8Str(pszSearchString));206 info.searchList.push_back(std::string(pszSearchString)); 216 207 } 217 208 } 218 209 219 210 CFRelease(propertyRef); 220 this->HostDnsService::update(); 211 212 setInfo(info); 221 213 222 214 return S_OK; -
trunk/src/VBox/Main/src-server/linux/HostDnsServiceLinux.cpp
r49201 r49235 26 26 #include <iprt/thread.h> 27 27 28 #include "../HostDnsService.h"29 30 28 #include <errno.h> 31 29 #include <poll.h> … … 40 38 41 39 #include <string> 40 #include <vector> 41 #include "../HostDnsService.h" 42 42 43 43 44 static RTTHREAD g_DnsMonitoringThread; … … 102 103 103 104 105 HostDnsServiceLinux::~HostDnsServiceLinux() 106 { 107 send(g_DnsMonitorStop[0], "", 1, 0); 108 } 109 110 104 111 int HostDnsServiceLinux::hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser) 105 112 { … … 140 147 if (polls[0].revents & POLLIN) 141 148 { 142 RTCritSectEnter(&dns->::HostDnsService::m_hCritSect); 143 dns->update(); 144 RTCritSectLeave(&dns->::HostDnsService::m_hCritSect); 149 dns->readResolvConf(); 150 /* notifyAll() takes required locks */ 151 dns->notifyAll(); 152 145 153 polls[0].revents = 0; 146 154 … … 153 161 154 162 155 HRESULT HostDnsServiceLinux::init(const VirtualBox *aParent)163 HRESULT HostDnsServiceLinux::init(const char *aResolvConfFileName) 156 164 { 157 HRESULT hrc = HostDnsServiceResolvConf::init(a Parent);165 HRESULT hrc = HostDnsServiceResolvConf::init(aResolvConfFileName); 158 166 AssertComRCReturnRC(hrc); 159 167 … … 169 177 return S_OK; 170 178 } 171 172 173 void HostDnsServiceLinux::stop()174 {175 send(g_DnsMonitorStop[0], "", 1, 0);176 } -
trunk/src/VBox/Main/src-server/win/HostDnsServiceWin.cpp
r48955 r49235 30 30 31 31 32 HRESULT HostDnsServiceWin::init( const VirtualBox *aParent)32 HRESULT HostDnsServiceWin::init() 33 33 { 34 HRESULT hrc; 35 hrc = HostDnsService::init(aParent); 34 HRESULT hrc = HostDnsMonitor::init(aParent); 36 35 AssertComRCReturn(hrc, hrc); 37 36 … … 40 39 41 40 return S_OK; 42 }43 44 45 HRESULT HostDnsServiceWin::start(void)46 {47 return S_OK;48 }49 50 51 void HostDnsServiceWin::stop(void)52 {53 41 } 54 42 … … 61 49 BYTE abNameServers[256]; 62 50 BYTE abSearchList[256]; 63 64 m_llNameServers.clear();65 m_llSearchStrings.clear();66 m_DomainName.setNull();67 68 RT_ZERO(abDomain);69 RT_ZERO(abNameServers);70 RT_ZERO(abSearchList);71 51 72 52 regIndex = 0; … … 115 95 /* OK, now parse and update DNS structures. */ 116 96 /* domain name */ 117 m_DomainName = com::Utf8Str((char *)abDomain); 97 HostDnsInformation info; 98 info.domain = static_cast<char*>(abDomain); 99 118 100 /* server list */ 119 strList2List( m_llNameServers, (char *)abNameServers);101 strList2List(info.servers, static_cast<char *>(abNameServers)); 120 102 /* search list */ 121 strList2List(m_llSearchStrings, (char *)abNameServers); 103 strList2List(info.searchList, static_cast<char *>(abSearchList)); 104 105 setInfo(info); 122 106 123 107 return S_OK; … … 126 110 127 111 128 void HostDnsServiceWin::strList2List( Utf8StrList& lst, char *strLst)112 void HostDnsServiceWin::strList2List(std::vector<std::string>& lst, char *strLst) 129 113 { 130 114 char *next, *current; … … 146 130 strcpy(address, current); 147 131 148 lst.push_back( com::Utf8Str(address));132 lst.push_back(std::string(address)); 149 133 150 134 current = next + 1;
Note:
See TracChangeset
for help on using the changeset viewer.