Changeset 77984 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Apr 2, 2019 2:06:13 PM (6 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/HostDnsService.cpp
r77666 r77984 78 78 } 79 79 80 struct HostDns Monitor::Data80 struct HostDnsServiceBase::Data 81 81 { 82 82 Data(bool aThreaded) 83 : proxy(NULL),84 fThreaded(aThreaded)83 : pProxy(NULL) 84 , fThreaded(aThreaded) 85 85 {} 86 86 87 HostDnsMonitorProxy *proxy; 88 89 const bool fThreaded; 90 RTSEMEVENT hDnsInitEvent; 91 RTTHREAD hMonitoringThread; 92 93 HostDnsInformation info; 87 /** Weak pointer to parent proxy object. */ 88 HostDnsMonitorProxy *pProxy; 89 /** Whether the DNS monitor implementation has a dedicated monitoring thread. Optional. */ 90 const bool fThreaded; 91 /** Event for the monitor thread, if any. */ 92 RTSEMEVENT hMonitorThreadEvent; 93 /** Handle of the monitor thread, if any. */ 94 RTTHREAD hMonitorThread; 95 /** Generic host DNS information. */ 96 HostDnsInformation info; 94 97 }; 95 98 96 99 struct HostDnsMonitorProxy::Data 97 100 { 98 Data(HostDns Monitor*aMonitor, VirtualBox *aParent)99 : virtualbox(aParent),100 monitor(aMonitor),101 uLastExtraDataPoll(0),102 fLaxComparison(0),103 info()101 Data(HostDnsServiceBase *aMonitor, VirtualBox *aParent) 102 : pVirtualBox(aParent) 103 , pMonitorImpl(aMonitor) 104 , uLastExtraDataPoll(0) 105 , fLaxComparison(0) 106 , info() 104 107 {} 105 108 106 VirtualBox * virtualbox;107 HostDns Monitor *monitor;109 VirtualBox *pVirtualBox; 110 HostDnsServiceBase *pMonitorImpl; 108 111 109 112 uint64_t uLastExtraDataPoll; … … 113 116 114 117 115 HostDns Monitor::HostDnsMonitor(bool fThreaded)116 : m(NULL)117 { 118 m = new HostDnsMonitor::Data(fThreaded);119 } 120 121 HostDns Monitor::~HostDnsMonitor()118 HostDnsServiceBase::HostDnsServiceBase(bool fThreaded) 119 : m(NULL) 120 { 121 m = new HostDnsServiceBase::Data(fThreaded); 122 } 123 124 HostDnsServiceBase::~HostDnsServiceBase() 122 125 { 123 126 if (m) … … 128 131 } 129 132 130 HostDns Monitor *HostDnsMonitor::createHostDnsMonitor()131 { 132 HostDns Monitor *monitor = NULL;133 HostDnsServiceBase *HostDnsServiceBase::createHostDnsMonitor(void) 134 { 135 HostDnsServiceBase *pMonitor = NULL; 133 136 134 137 #if defined (RT_OS_DARWIN) 135 monitor = new HostDnsServiceDarwin();138 pMonitor = new HostDnsServiceDarwin(); 136 139 #elif defined(RT_OS_WINDOWS) 137 monitor = new HostDnsServiceWin();140 pMonitor = new HostDnsServiceWin(); 138 141 #elif defined(RT_OS_LINUX) 139 monitor = new HostDnsServiceLinux();142 pMonitor = new HostDnsServiceLinux(); 140 143 #elif defined(RT_OS_SOLARIS) 141 monitor = new HostDnsServiceSolaris();144 pMonitor = new HostDnsServiceSolaris(); 142 145 #elif defined(RT_OS_FREEBSD) 143 monitor = new HostDnsServiceFreebsd();146 pMonitor = new HostDnsServiceFreebsd(); 144 147 #elif defined(RT_OS_OS2) 145 monitor = new HostDnsServiceOs2();148 pMonitor = new HostDnsServiceOs2(); 146 149 #else 147 monitor = new HostDnsService();150 pMonitor = new HostDnsServiceBase(); 148 151 #endif 149 152 150 return monitor; 151 } 152 153 154 void HostDnsMonitor::shutdown() 153 return pMonitor; 154 } 155 156 void HostDnsServiceBase::shutdown(void) 155 157 { 156 158 monitorThreadShutdown(); 157 int rc = RTThreadWait(m->hMonitor ingThread, 5000, NULL);159 int rc = RTThreadWait(m->hMonitorThread, 5000, NULL); 158 160 AssertRCSuccess(rc); 159 161 } 160 162 161 163 162 void HostDns Monitor::setInfo(const HostDnsInformation &info)163 { 164 if (m->p roxy != NULL)165 m->p roxy->notify(info);166 } 167 168 HRESULT HostDns Monitor::init(HostDnsMonitorProxy *proxy)169 { 170 m->p roxy = proxy;164 void HostDnsServiceBase::setInfo(const HostDnsInformation &info) 165 { 166 if (m->pProxy != NULL) 167 m->pProxy->notify(info); 168 } 169 170 HRESULT HostDnsServiceBase::init(HostDnsMonitorProxy *pProxy) 171 { 172 m->pProxy = pProxy; 171 173 172 174 if (m->fThreaded) 173 175 { 174 int rc = RTSemEventCreate(&m->h DnsInitEvent);176 int rc = RTSemEventCreate(&m->hMonitorThreadEvent); 175 177 AssertRCReturn(rc, E_FAIL); 176 178 177 rc = RTThreadCreate(&m->hMonitor ingThread,178 HostDns Monitor::threadMonitoringRoutine,179 rc = RTThreadCreate(&m->hMonitorThread, 180 HostDnsServiceBase::threadMonitoringRoutine, 179 181 this, 128 * _1K, RTTHREADTYPE_IO, 180 182 RTTHREADFLAGS_WAITABLE, "dns-monitor"); 181 183 AssertRCReturn(rc, E_FAIL); 182 184 183 RTSemEventWait(m->h DnsInitEvent, RT_INDEFINITE_WAIT);185 RTSemEventWait(m->hMonitorThreadEvent, RT_INDEFINITE_WAIT); 184 186 } 185 187 return S_OK; 186 188 } 187 189 188 189 void HostDnsMonitorProxy::pollGlobalExtraData() 190 { 191 VirtualBox *virtualbox = m->virtualbox; 192 if (RT_UNLIKELY(virtualbox == NULL)) 190 void HostDnsMonitorProxy::pollGlobalExtraData(void) 191 { 192 VirtualBox *pVirtualBox = m->pVirtualBox; 193 if (RT_UNLIKELY(pVirtualBox == NULL)) 193 194 return; 194 195 … … 203 204 const com::Bstr bstrHostDNSOrderIgnoreKey("VBoxInternal2/HostDNSOrderIgnore"); 204 205 com::Bstr bstrHostDNSOrderIgnore; 205 virtualbox->GetExtraData(bstrHostDNSOrderIgnoreKey.raw(),206 pVirtualBox->GetExtraData(bstrHostDNSOrderIgnoreKey.raw(), 206 207 bstrHostDNSOrderIgnore.asOutParam()); 207 208 uint32_t fDNSOrderIgnore = 0; … … 226 227 const com::Bstr bstrHostDNSSuffixesIgnoreKey("VBoxInternal2/HostDNSSuffixesIgnore"); 227 228 com::Bstr bstrHostDNSSuffixesIgnore; 228 virtualbox->GetExtraData(bstrHostDNSSuffixesIgnoreKey.raw(),229 pVirtualBox->GetExtraData(bstrHostDNSSuffixesIgnoreKey.raw(), 229 230 bstrHostDNSSuffixesIgnore.asOutParam()); 230 231 uint32_t fDNSSuffixesIgnore = 0; … … 246 247 } 247 248 248 void HostDnsMonitor::monitorThreadInitializationDone() 249 { 250 RTSemEventSignal(m->hDnsInitEvent); 251 } 252 253 254 DECLCALLBACK(int) HostDnsMonitor::threadMonitoringRoutine(RTTHREAD, void *pvUser) 255 { 256 HostDnsMonitor *pThis = static_cast<HostDnsMonitor *>(pvUser); 249 void HostDnsServiceBase::monitorThreadInitializationDone(void) 250 { 251 RTSemEventSignal(m->hMonitorThreadEvent); 252 } 253 254 DECLCALLBACK(int) HostDnsServiceBase::threadMonitoringRoutine(RTTHREAD, void *pvUser) 255 { 256 HostDnsServiceBase *pThis = static_cast<HostDnsServiceBase *>(pvUser); 257 257 return pThis->monitorWorker(); 258 258 } … … 271 271 void HostDnsMonitorProxy::init(VirtualBox* aParent) 272 272 { 273 HostDnsMonitor *monitor = HostDnsMonitor::createHostDnsMonitor(); 274 m = new HostDnsMonitorProxy::Data(monitor, aParent); 275 m->monitor->init(this); 276 } 277 278 279 void HostDnsMonitorProxy::uninit() 273 HostDnsServiceBase *pMonitor = HostDnsServiceBase::createHostDnsMonitor(); 274 m = new HostDnsMonitorProxy::Data(pMonitor, aParent); 275 m->pMonitorImpl->init(this); 276 } 277 278 void HostDnsMonitorProxy::uninit(void) 280 279 { 281 280 if (m) 282 281 { 283 m-> monitor->shutdown();282 m->pMonitorImpl->shutdown(); 284 283 delete m; 285 284 m = NULL; … … 291 290 bool fNotify = updateInfo(info); 292 291 if (fNotify) 293 m-> virtualbox->i_onHostNameResolutionConfigurationChange();292 m->pVirtualBox->i_onHostNameResolutionConfigurationChange(); 294 293 } 295 294 … … 362 361 return true; 363 362 } 364 365 363 366 364 static void dumpHostDnsInformation(const HostDnsInformation& info) -
trunk/src/VBox/Main/src-server/HostDnsService.h
r77506 r77984 52 52 * it lifecycle starts and ends together with VBoxSVC. 53 53 */ 54 class HostDnsMonitor 55 { 56 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsMonitor); 57 58 public: 59 static HostDnsMonitor *createHostDnsMonitor(); 54 class HostDnsServiceBase 55 { 56 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsServiceBase); 57 58 public: 59 60 static HostDnsServiceBase *createHostDnsMonitor(void); 60 61 void shutdown(); 61 62 62 63 /* @note: method will wait till client call 63 64 HostDnsService::monitorThreadInitializationDone() */ 64 virtual HRESULT init(HostDnsMonitorProxy *proxy); 65 66 protected: 67 explicit HostDnsMonitor(bool fThreaded = false); 68 virtual ~HostDnsMonitor(); 65 virtual HRESULT init(HostDnsMonitorProxy *pProxy); 66 67 protected: 68 69 explicit HostDnsServiceBase(bool fThreaded = false); 70 virtual ~HostDnsServiceBase(); 69 71 70 72 void setInfo(const HostDnsInformation &); … … 75 77 virtual int monitorWorker() = 0; 76 78 77 private: 79 private: 80 78 81 static DECLCALLBACK(int) threadMonitoringRoutine(RTTHREAD, void *); 79 82 80 protected: 83 protected: 84 81 85 mutable RTCLockMtx m_LockMtx; 82 86 83 public: 87 public: /** @todo r=andy Why is this public? */ 88 84 89 struct Data; 85 90 Data *m; … … 91 96 class HostDnsMonitorProxy 92 97 { 93 public: 98 public: 99 94 100 HostDnsMonitorProxy(); 95 ~HostDnsMonitorProxy(); 101 virtual ~HostDnsMonitorProxy(); 102 103 public: 104 96 105 void init(VirtualBox *virtualbox); 97 106 void uninit(); … … 102 111 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings); 103 112 104 private: 113 private: 114 105 115 void pollGlobalExtraData(); 106 116 bool updateInfo(const HostDnsInformation &info); 107 117 108 private: 118 private: 119 109 120 mutable RTCLockMtx m_LockMtx; 110 121 111 private:112 122 struct Data; 113 123 Data *m; … … 115 125 116 126 # if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING) 117 class HostDnsServiceDarwin : public HostDns Monitor118 { 119 127 class HostDnsServiceDarwin : public HostDnsServiceBase 128 { 129 public: 120 130 HostDnsServiceDarwin(); 121 ~HostDnsServiceDarwin(); 122 virtual HRESULT init(HostDnsMonitorProxy *proxy); 123 124 protected: 131 virtual ~HostDnsServiceDarwin(); 132 133 public: 134 135 virtual HRESULT init(HostDnsMonitorProxy *pProxy); 136 137 protected: 138 139 virtual void monitorThreadShutdown(); 140 virtual int monitorWorker(); 141 142 private: 143 144 HRESULT updateInfo(); 145 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info); 146 struct Data; 147 Data *m; 148 }; 149 # endif 150 # if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING) 151 class HostDnsServiceWin : public HostDnsServiceBase 152 { 153 public: 154 HostDnsServiceWin(); 155 virtual ~HostDnsServiceWin(); 156 157 public: 158 159 virtual HRESULT init(HostDnsMonitorProxy *pProxy); 160 161 protected: 162 125 163 virtual void monitorThreadShutdown(); 126 164 virtual int monitorWorker(); 127 165 128 private: 129 HRESULT updateInfo(); 130 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info); 131 struct Data; 132 Data *m; 133 }; 134 # endif 135 # if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING) 136 class HostDnsServiceWin : public HostDnsMonitor 137 { 138 public: 139 HostDnsServiceWin(); 140 ~HostDnsServiceWin(); 141 virtual HRESULT init(HostDnsMonitorProxy *proxy); 142 143 protected: 144 virtual void monitorThreadShutdown(); 145 virtual int monitorWorker(); 146 147 private: 166 private: 167 148 168 HRESULT updateInfo(); 149 169 … … 155 175 # if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \ 156 176 || defined(DOXYGEN_RUNNING) 157 class HostDnsServiceResolvConf: public HostDnsMonitor 158 { 159 public: 160 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {} 177 class HostDnsServiceResolvConf: public HostDnsServiceBase 178 { 179 public: 180 181 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {} 161 182 virtual ~HostDnsServiceResolvConf(); 162 virtual HRESULT init(HostDnsMonitorProxy *proxy, const char *aResolvConfFileName); 183 184 public: 185 186 virtual HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName); 163 187 const std::string& resolvConf() const; 164 188 165 protected: 189 protected: 190 166 191 HRESULT readResolvConf(); 167 192 /* While not all hosts supports Hosts DNS change notifiaction … … 171 196 virtual int monitorWorker() {return VERR_IGNORED;} 172 197 173 protected: 198 protected: 199 174 200 struct Data; 175 201 Data *m; … … 181 207 class HostDnsServiceSolaris : public HostDnsServiceResolvConf 182 208 { 183 public: 209 public: 210 184 211 HostDnsServiceSolaris(){} 185 ~HostDnsServiceSolaris(){} 186 virtual HRESULT init(HostDnsMonitorProxy *proxy) { 187 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf"); 212 virtual ~HostDnsServiceSolaris(){} 213 214 public: 215 216 virtual HRESULT init(HostDnsMonitorProxy *pProxy) { 217 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf"); 188 218 } 189 219 }; … … 193 223 class HostDnsServiceLinux : public HostDnsServiceResolvConf 194 224 { 195 public: 196 HostDnsServiceLinux():HostDnsServiceResolvConf(true){} 197 virtual ~HostDnsServiceLinux(); 198 virtual HRESULT init(HostDnsMonitorProxy *proxy) { 199 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf"); 200 } 201 202 protected: 225 public: 226 227 HostDnsServiceLinux() : HostDnsServiceResolvConf(true) {} 228 virtual ~HostDnsServiceLinux(); 229 230 public: 231 232 virtual HRESULT init(HostDnsMonitorProxy *pProxy) { 233 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf"); 234 } 235 236 protected: 237 203 238 virtual void monitorThreadShutdown(); 204 239 virtual int monitorWorker(); … … 209 244 class HostDnsServiceFreebsd: public HostDnsServiceResolvConf 210 245 { 211 public: 246 public: 247 212 248 HostDnsServiceFreebsd(){} 213 ~HostDnsServiceFreebsd(){} 214 virtual HRESULT init(HostDnsMonitorProxy *proxy) { 215 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf"); 249 virtual ~HostDnsServiceFreebsd() {} 250 251 public: 252 253 virtual HRESULT init(HostDnsMonitorProxy *pProxy) { 254 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf"); 216 255 } 217 256 }; … … 221 260 class HostDnsServiceOs2 : public HostDnsServiceResolvConf 222 261 { 223 public: 224 HostDnsServiceOs2(){} 225 ~HostDnsServiceOs2(){} 262 public: 263 264 HostDnsServiceOs2() {} 265 virtual ~HostDnsServiceOs2() {} 266 267 public: 268 226 269 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */ 227 virtual HRESULT init(HostDnsMonitorProxy *p roxy) {228 return HostDnsServiceResolvConf::init(p roxy, "\\MPTN\\ETC\\RESOLV2");270 virtual HRESULT init(HostDnsMonitorProxy *pProxy) { 271 return HostDnsServiceResolvConf::init(pProxy, "\\MPTN\\ETC\\RESOLV2"); 229 272 } 230 273 }; -
trunk/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp
r76553 r77984 55 55 }; 56 56 57 const std::string& HostDnsServiceResolvConf::resolvConf( ) const57 const std::string& HostDnsServiceResolvConf::resolvConf(void) const 58 58 { 59 59 return m->resolvConfFilename; … … 70 70 } 71 71 72 HRESULT HostDnsServiceResolvConf::init(HostDnsMonitorProxy *p roxy, const char *aResolvConfFileName)72 HRESULT HostDnsServiceResolvConf::init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName) 73 73 { 74 74 m = new Data(aResolvConfFileName); 75 75 76 HostDns Monitor::init(proxy);76 HostDnsServiceBase::init(pProxy); 77 77 78 78 readResolvConf(); … … 81 81 } 82 82 83 84 HRESULT HostDnsServiceResolvConf::readResolvConf() 83 HRESULT HostDnsServiceResolvConf::readResolvConf(void) 85 84 { 86 85 struct rcp_state st; -
trunk/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp
r77872 r77984 51 51 52 52 53 HostDnsServiceDarwin::HostDnsServiceDarwin():HostDnsMonitor(true),m(NULL) 53 HostDnsServiceDarwin::HostDnsServiceDarwin() 54 : HostDnsServiceBase(true) 55 , m(NULL) 54 56 { 55 57 m = new HostDnsServiceDarwin::Data(); … … 86 88 87 89 88 HRESULT HostDnsServiceDarwin::init(HostDnsMonitorProxy *p roxy)90 HRESULT HostDnsServiceDarwin::init(HostDnsMonitorProxy *pProxy) 89 91 { 90 92 SCDynamicStoreContext ctx; … … 94 96 95 97 m->m_store = SCDynamicStoreCreate(NULL, CFSTR("org.virtualbox.VBoxSVC"), 96 (SCDynamicStoreCallBack)HostDnsServiceDarwin::hostDnsServiceStoreCallback,97 &ctx);98 (SCDynamicStoreCallBack)HostDnsServiceDarwin::hostDnsServiceStoreCallback, 99 &ctx); 98 100 AssertReturn(m->m_store, E_FAIL); 99 101 … … 111 113 AssertReturn(m->m_Stopper, E_FAIL); 112 114 113 HRESULT hrc = HostDns Monitor::init(proxy);115 HRESULT hrc = HostDnsServiceBase::init(pProxy); 114 116 AssertComRCReturn(hrc, hrc); 115 117 … … 118 120 119 121 120 void HostDnsServiceDarwin::monitorThreadShutdown( )122 void HostDnsServiceDarwin::monitorThreadShutdown(void) 121 123 { 122 124 RTCLock grab(m_LockMtx); … … 132 134 133 135 134 int HostDnsServiceDarwin::monitorWorker( )136 int HostDnsServiceDarwin::monitorWorker(void) 135 137 { 136 138 m->m_RunLoopRef = CFRunLoopGetCurrent(); … … 168 170 } 169 171 170 171 HRESULT HostDnsServiceDarwin::updateInfo() 172 HRESULT HostDnsServiceDarwin::updateInfo(void) 172 173 { 173 174 CFPropertyListRef propertyRef = SCDynamicStoreCopyValue(m->m_store, … … 254 255 } 255 256 256 void HostDnsServiceDarwin::Data::performShutdownCallback(void * info)257 { 258 HostDnsServiceDarwin::Data *pThis = static_cast<HostDnsServiceDarwin::Data *>( info);257 void HostDnsServiceDarwin::Data::performShutdownCallback(void *pInfo) 258 { 259 HostDnsServiceDarwin::Data *pThis = static_cast<HostDnsServiceDarwin::Data *>(pInfo); 259 260 AssertPtrReturnVoid(pThis); 260 261 pThis->m_fStop = true; -
trunk/src/VBox/Main/src-server/linux/HostDnsServiceLinux.cpp
r76553 r77984 94 94 95 95 96 int HostDnsServiceLinux::monitorWorker( )96 int HostDnsServiceLinux::monitorWorker(void) 97 97 { 98 98 … … 151 151 RT_ZERO(combo); 152 152 ssize_t r = read(polls[0].fd, static_cast<void *>(&combo), sizeof(combo)); 153 NOREF(r);153 RT_NOREF(r); 154 154 155 155 if (combo.e.wd == wd[0]) -
trunk/src/VBox/Main/src-server/win/HostDnsServiceWin.cpp
r76553 r77984 87 87 88 88 89 HRESULT HostDnsServiceWin::init(HostDnsMonitorProxy *p roxy)89 HRESULT HostDnsServiceWin::init(HostDnsMonitorProxy *pProxy) 90 90 { 91 91 if (m == NULL) … … 129 129 } 130 130 131 HRESULT hrc = HostDns Monitor::init(proxy);131 HRESULT hrc = HostDnsServiceBase::init(pProxy); 132 132 if (FAILED(hrc)) 133 133 return hrc; … … 248 248 249 249 250 HRESULT HostDnsServiceWin::updateInfo( )250 HRESULT HostDnsServiceWin::updateInfo(void) 251 251 { 252 252 HostDnsInformation info; … … 471 471 info.searchList.clear(); 472 472 473 HostDns Monitor::setInfo(info);473 HostDnsServiceBase::setInfo(info); 474 474 475 475 return S_OK;
Note:
See TracChangeset
for help on using the changeset viewer.