VirtualBox

Changeset 49235 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Oct 22, 2013 6:56:03 PM (11 years ago)
Author:
vboxsync
Message:

Main/HostDnsService: splits HostDnsService on "singleton" HostDnsMonitor
which monitors host changes and share DnsInformation to per HostImpl/VirtualBoxImpl objects
HostDnsMonitorProxy.

TODO: Win/Darwin parts might burn (not tested)
TODO: find good place to call HostDnsMonitor::shutdown() to stop
monitoring thread. (ref counting could be used on
HostDnsMonitor::addMonitorProxy and HostDnsMonitor::releaseMonitorProxy,
but it better to pausing monitoring on no --auto-shutdown launches of VBoxSVC).

Location:
trunk/src/VBox/Main/src-server
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/HostDnsService.cpp

    r49228 r49235  
    2626#include <iprt/semaphore.h>
    2727#include <iprt/critsect.h>
     28
     29#include <algorithm>
     30#include <string>
     31#include <vector>
    2832#include "HostDnsService.h"
     33
     34
     35static HostDnsMonitor *g_monitor;
     36
    2937
    3038/* Lockee */
     
    4957
    5058
    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
     60inline 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
    9067    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
     76struct HostDnsMonitor::Data
     77{
     78    std::vector<HostDnsMonitorProxy> proxies;
     79    HostDnsInformation info;
     80};
     81
     82
     83struct 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
     97HostDnsMonitor::HostDnsMonitor():m(NULL){}
     98
     99
     100HostDnsMonitor::~HostDnsMonitor(){if (m) delete m;}
     101
     102
     103const 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
     128void HostDnsMonitor::addMonitorProxy(const HostDnsMonitorProxy& proxy) const
     129{
     130    ALock l(this);
     131    m->proxies.push_back(proxy);
     132
     133    proxy.notify();
     134}
     135
     136
     137void 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
     150void HostDnsMonitor::shutdown()
     151{
     152    if (g_monitor)
     153    {
     154        delete g_monitor;
     155        g_monitor = NULL;
     156    }
     157}
     158
     159
     160const HostDnsInformation& HostDnsMonitor::getInfo() const
     161{
     162    ALock l(this);
     163    return m->info;
     164}
     165
     166
     167void 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
     176void HostDnsMonitor::setInfo(const HostDnsInformation& info)
     177{
     178    ALock l(this);
     179    m->info = info;
     180}
     181
     182
     183HRESULT HostDnsMonitor::init()
     184{
     185    m = new HostDnsMonitor::Data();
     186    return S_OK;
     187}
     188
     189/* HostDnsMonitorProxy */
     190HostDnsMonitorProxy::HostDnsMonitorProxy():m(NULL){}
     191
     192HostDnsMonitorProxy::~HostDnsMonitorProxy()
     193{
     194    if (m && m->monitor)
     195    {
     196        m->monitor->releaseMonitorProxy(*this);
     197        delete m;
     198    }
     199}
     200
     201
     202void 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
     210void HostDnsMonitorProxy::notify() const
     211{
     212    m->fModified = true;
     213    const_cast<VirtualBox *>(m->virtualbox)->onHostNameResolutionConfigurationChange();
     214}
     215
     216
     217STDMETHODIMP 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
     231STDMETHODIMP 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
     245STDMETHODIMP 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
     259bool 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
     269void 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  
    5454
    5555
    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);
     56struct HostDnsInformation
     57{
     58    std::vector<std::string> servers;
     59    std::string domain;
     60    std::vector<std::string> searchList;
     61};
     62
     63
     64class 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 */
     71class 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 */
     101class HostDnsMonitorProxy: public Lockee
     102{
     103    public:
     104    HostDnsMonitorProxy();
     105    ~HostDnsMonitorProxy();
     106    void init(const HostDnsMonitor* mon, const VirtualBox* aParent);
     107    void notify() const;
     108   
    64109    STDMETHOD(COMGETTER(NameServers))(ComSafeArrayOut(BSTR, aNameServers));
    65110    STDMETHOD(COMGETTER(DomainName))(BSTR *aDomainName);
    66111    STDMETHOD(COMGETTER(SearchStrings))(ComSafeArrayOut(BSTR, aSearchStrings));
    67112
     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
     124class 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
     137class 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)
     150class 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
    68158    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};
    131165#  if defined(RT_OS_SOLARIS)
    132166/**
     
    135169class HostDnsServiceSolaris: public HostDnsServiceResolvConf
    136170{
    137 public:
     171    public:
    138172    HostDnsServiceSolaris(){}
    139     virtual ~HostDnsServiceSolaris(){}
    140 };
     173    ~HostDnsServiceSolaris(){}
     174    HRESULT init(){ return init("/etc/resolv.conf");}
     175};
     176
    141177#  elif defined(RT_OS_LINUX)
    142178class HostDnsServiceLinux: public HostDnsServiceResolvConf
     
    144180    public:
    145181    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);
    149185
    150186    static int hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser);
     
    155191{
    156192    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
    164199#  endif
    165 #endif
     200# endif
    166201
    167202#endif /* !___H_DNSHOSTSERVICE */
  • trunk/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp

    r48955 r49235  
    33#include <VBox/com/ptr.h>
    44
    5 #include "HostDnsService.h"
    65
    76#ifdef RT_OS_OS2
     
    1918#include <iprt/err.h>
    2019#include <iprt/file.h>
     20#include <iprt/critsect.h>
    2121
    2222#include <VBox/log.h>
     23
     24#include <string>
     25#include <vector>
     26
     27#include "HostDnsService.h"
     28
     29
     30struct HostDnsServiceResolvConf::Data
     31{
     32    Data(const char *fileName):resolvConfFilename(fileName){};
     33
     34    std::string resolvConfFilename;
     35};
     36
     37
     38const std::string& HostDnsServiceResolvConf::resolvConf()
     39{
     40    return m->resolvConfFilename;
     41}
    2342
    2443
     
    5170
    5271
    53 HostDnsServiceResolvConf::HostDnsServiceResolvConf(const char* aResolvConfFilename)
     72HostDnsServiceResolvConf::~HostDnsServiceResolvConf()
    5473{
    55     m_ResolvConfFilename = com::Utf8Str(aResolvConfFilename);
     74    if (m) delete m;
    5675}
    5776
    5877
    59 HostDnsServiceResolvConf::~HostDnsServiceResolvConf()
     78HRESULT HostDnsServiceResolvConf::init(const char *aResolvConfFileName)
    6079{
    61     m_ResolvConfFilename.setNull();
    62     RTFileClose(m_ResolvConfFile);
    63 }
     80    HostDnsMonitor::init();
    6481
    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();
    8184
    8285    return S_OK;
     
    8487
    8588
    86 HRESULT HostDnsServiceResolvConf::update()
     89HRESULT HostDnsServiceResolvConf::readResolvConf()
    8790{
    8891    char buff[256];
     
    9194    bool fWarnTooManyDnsServers = false;
    9295    struct in_addr tmp_addr;
    93     int rc;
    9496    size_t bytes;
     97    HostDnsInformation info;
     98    RTFILE resolvConfFile;
    9599
    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))
    97105            && rc != VERR_EOF)
    98106    {
     
    110118                continue;
    111119
    112             m_llNameServers.push_back(com::Utf8Str(buff2));
     120            info.servers.push_back(std::string(buff2));
    113121
    114122            cNameserversFound++;
     
    122130
    123131            if (tok != NULL)
    124                 m_DomainName = com::Utf8Str(tok);
     132                info.domain = std::string(tok);
    125133        }
    126134    }
    127135
     136    RTFileClose(resolvConfFile);
     137
     138    setInfo(info);
     139
    128140    return S_OK;
    129 
    130141}
  • trunk/src/VBox/Main/src-server/HostImpl.cpp

    r49132 r49235  
    2323
    2424#include "HostImpl.h"
    25 #include "HostDnsService.h"
    2625
    2726#ifdef VBOX_WITH_USB
     
    172171
    173172#include <algorithm>
     173#include <string>
     174#include <vector>
     175
     176#include "HostDnsService.h"
    174177
    175178////////////////////////////////////////////////////////////////////////////////
     
    225228    HostPowerService        *pHostPowerService;
    226229    /** Host's DNS informaton fetching */
    227     HostDnsService          *pHostDnsService;
     230    HostDnsMonitorProxy         hostDnsMonitorProxy;
    228231};
    229232
     
    292295    updateNetIfList();
    293296
    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);
    313298
    314299#if defined (RT_OS_WINDOWS)
     
    513498#endif
    514499
    515     m->pHostDnsService->stop();
    516 
    517     delete m->pHostDnsService;
    518500    delete m;
    519501    m = NULL;
     
    851833    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    852834
    853     return m->pHostDnsService->COMGETTER(NameServers)(ComSafeArrayOutArg(aNameServers));
     835    return m->hostDnsMonitorProxy.COMGETTER(NameServers)(ComSafeArrayOutArg(aNameServers));
    854836}
    855837
     
    866848    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    867849
    868     return m->pHostDnsService->COMGETTER(DomainName)(aDomainName);
     850    return m->hostDnsMonitorProxy.COMGETTER(DomainName)(aDomainName);
    869851}
    870852
     
    882864    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    883865
    884     return m->pHostDnsService->COMGETTER(SearchStrings)(ComSafeArrayOutArg(aSearchStrings));
     866    return m->hostDnsMonitorProxy.COMGETTER(SearchStrings)(ComSafeArrayOutArg(aSearchStrings));
    885867}
    886868
  • trunk/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp

    r48955 r49235  
    7070}
    7171
     72
    7273HostDnsServiceDarwin::HostDnsServiceDarwin(){}
     74
     75
    7376HostDnsServiceDarwin::~HostDnsServiceDarwin()
    7477{
     78    if (g_RunLoopRef)
     79        CFRunLoopStop(g_RunLoopRef);
     80
    7581    CFRelease(g_DnsWatcher);
     82
    7683    CFRelease(g_store);
    7784}
     85
    7886
    7987void HostDnsServiceDarwin::hostDnsServiceStoreCallback(void *arg0, void *arg1, void *info)
     
    8593
    8694    RTCritSectEnter(&pThis->m_hCritSect);
    87     pThis->update();
     95    pThis->updateInfo();
     96    pThis->notifyAll();
    8897    RTCritSectLeave(&pThis->m_hCritSect);
    8998}
     99
    90100
    91101HRESULT HostDnsServiceDarwin::init(const VirtualBox *aParent)
     
    111121    AssertRCReturn(rc, E_FAIL);
    112122
    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");
    122125    AssertRCReturn(rc, E_FAIL);
    123126
    124127    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
     132HRESULT HostDnsServiceDarwin::updateInfo()
     133{
    144134    CFPropertyListRef propertyRef = SCDynamicStoreCopyValue(g_store,
    145135                                                            kStateNetworkGlobalDNSKey);
     
    165155        return S_OK;
    166156
     157    HostDnsInformation info;
    167158    CFStringRef domainNameRef = (CFStringRef)CFDictionaryGetValue(
    168159      static_cast<CFDictionaryRef>(propertyRef), CFSTR("DomainName"));
     
    172163                                                    CFStringGetSystemEncoding());
    173164        if (pszDomainName)
    174             m_DomainName = com::Utf8Str(pszDomainName);
     165            info.domain = pszDomainName;
    175166    }
    176167
     
    191182            if (!pszServerAddress)
    192183                continue;
    193 
    194             m_llNameServers.push_back(com::Utf8Str(pszServerAddress));
     184           
     185            info.servers.push_back(std::string(pszServerAddress));
    195186        }
    196187    }
     
    213204                continue;
    214205
    215             m_llSearchStrings.push_back(com::Utf8Str(pszSearchString));
     206            info.searchList.push_back(std::string(pszSearchString));
    216207        }
    217208    }
    218209
    219210    CFRelease(propertyRef);
    220     this->HostDnsService::update();
     211
     212    setInfo(info);
    221213
    222214    return S_OK;
  • trunk/src/VBox/Main/src-server/linux/HostDnsServiceLinux.cpp

    r49201 r49235  
    2626#include <iprt/thread.h>
    2727
    28 #include "../HostDnsService.h"
    29 
    3028#include <errno.h>
    3129#include <poll.h>
     
    4038
    4139#include <string>
     40#include <vector>
     41#include "../HostDnsService.h"
     42
    4243
    4344static RTTHREAD g_DnsMonitoringThread;
     
    102103
    103104
     105HostDnsServiceLinux::~HostDnsServiceLinux()
     106{
     107    send(g_DnsMonitorStop[0], "", 1, 0);
     108}
     109
     110
    104111int HostDnsServiceLinux::hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser)
    105112{
     
    140147        if (polls[0].revents & POLLIN)
    141148        {
    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
    145153            polls[0].revents = 0;
    146154
     
    153161
    154162
    155 HRESULT HostDnsServiceLinux::init(const VirtualBox *aParent)
     163HRESULT HostDnsServiceLinux::init(const char *aResolvConfFileName)
    156164{
    157     HRESULT hrc = HostDnsServiceResolvConf::init(aParent);
     165    HRESULT hrc = HostDnsServiceResolvConf::init(aResolvConfFileName);
    158166    AssertComRCReturnRC(hrc);
    159167
     
    169177    return S_OK;
    170178}
    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  
    3030
    3131
    32 HRESULT HostDnsServiceWin::init(const VirtualBox *aParent)
     32HRESULT HostDnsServiceWin::init()
    3333{
    34     HRESULT hrc;
    35     hrc = HostDnsService::init(aParent);
     34    HRESULT hrc = HostDnsMonitor::init(aParent);
    3635    AssertComRCReturn(hrc, hrc);
    3736
     
    4039
    4140    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 {
    5341}
    5442
     
    6149    BYTE abNameServers[256];
    6250    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);
    7151
    7252    regIndex = 0;
     
    11595    /* OK, now parse and update DNS structures. */
    11696    /* domain name */
    117     m_DomainName = com::Utf8Str((char *)abDomain);
     97    HostDnsInformation info;
     98    info.domain = static_cast<char*>(abDomain);
     99
    118100    /* server list */
    119     strList2List(m_llNameServers, (char *)abNameServers);
     101    strList2List(info.servers, static_cast<char *>(abNameServers));
    120102    /* search list */
    121     strList2List(m_llSearchStrings, (char *)abNameServers);
     103    strList2List(info.searchList, static_cast<char *>(abSearchList));
     104
     105    setInfo(info);
    122106
    123107    return S_OK;
     
    126110
    127111
    128 void HostDnsServiceWin::strList2List(Utf8StrList& lst, char *strLst)
     112void HostDnsServiceWin::strList2List(std::vector<std::string>& lst, char *strLst)
    129113{
    130114    char *next, *current;
     
    146130          strcpy(address, current);
    147131
    148         lst.push_back(com::Utf8Str(address));
     132        lst.push_back(std::string(address));
    149133
    150134        current = next + 1;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette