VirtualBox

Changeset 79621 in vbox


Ignore:
Timestamp:
Jul 9, 2019 1:14:53 AM (5 years ago)
Author:
vboxsync
Message:

Dhcpd,Main/DHCPServerImpl: LeasesFilename should be plural everywhere. Moved default calc in dhcpd into the config class. bugref:9288

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/DHCPServerImpl.h

    r79610 r79621  
    139139    /** @name Helpers
    140140     * @{  */
    141     HRESULT i_calcLeaseFilename(const com::Utf8Str &aNetwork) RT_NOEXCEPT;
     141    HRESULT i_calcLeasesFilename(const com::Utf8Str &aNetwork) RT_NOEXCEPT;
    142142    /** @} */
    143143
  • trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp

    r79610 r79621  
    6666
    6767    char tempConfigFileName[RTPATH_MAX];
    68     com::Utf8Str strLeaseFilename;
     68    com::Utf8Str strLeasesFilename;
    6969    com::Utf8Str networkName;
    7070    com::Utf8Str trunkName;
     
    696696    m->trunkName   = aTrunkName;
    697697    m->trunkType   = aTrunkType;
    698     HRESULT hrc = i_calcLeaseFilename(aNetworkName);
     698    HRESULT hrc = i_calcLeasesFilename(aNetworkName);
    699699    if (FAILED(hrc))
    700700        return hrc;
     
    732732    pElmRoot->setAttribute("lowerIP", m->lowerIP);
    733733    pElmRoot->setAttribute("upperIP", m->upperIP);
    734     pElmRoot->setAttribute("leaseFilename", m->strLeaseFilename);
     734    pElmRoot->setAttribute("leasesFilename", m->strLeasesFilename);
    735735
    736736    /* Process global options */
     
    866866     */
    867867    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    868     if (m->strLeaseFilename.isEmpty())
    869     {
    870         HRESULT hrc = i_calcLeaseFilename(m->networkName.isEmpty() ? mName : m->networkName);
     868    if (m->strLeasesFilename.isEmpty())
     869    {
     870        HRESULT hrc = i_calcLeasesFilename(m->networkName.isEmpty() ? mName : m->networkName);
    871871        if (FAILED(hrc))
    872872            return hrc;
     
    886886        {
    887887            xml::XmlFileParser parser;
    888             parser.read(m->strLeaseFilename.c_str(), doc);
     888            parser.read(m->strLeasesFilename.c_str(), doc);
    889889        }
    890890        catch (const xml::EIPRTFailure &e)
     
    912912            }
    913913            return setErrorBoth(VBOX_E_FILE_ERROR, vrc, "Reading '%s' failed: %Rrc - %s",
    914                                 m->strLeaseFilename.c_str(), vrc, e.what());
     914                                m->strLeasesFilename.c_str(), vrc, e.what());
    915915        }
    916916        catch (const RTCError &e)
    917917        {
    918918            if (e.what())
    919                 return setError(VBOX_E_FILE_ERROR, "Reading '%s' failed: %s", m->strLeaseFilename.c_str(), e.what());
    920             return setError(VBOX_E_FILE_ERROR, "Reading '%s' failed: RTCError", m->strLeaseFilename.c_str());
     919                return setError(VBOX_E_FILE_ERROR, "Reading '%s' failed: %s", m->strLeasesFilename.c_str(), e.what());
     920            return setError(VBOX_E_FILE_ERROR, "Reading '%s' failed: RTCError", m->strLeasesFilename.c_str());
    921921        }
    922922        catch (std::bad_alloc &)
     
    927927        {
    928928            AssertFailed();
    929             return setError(VBOX_E_FILE_ERROR, tr("Reading '%s' failed: Unexpected exception"), m->strLeaseFilename.c_str());
     929            return setError(VBOX_E_FILE_ERROR, tr("Reading '%s' failed: Unexpected exception"), m->strLeasesFilename.c_str());
    930930        }
    931931
     
    988988
    989989/**
    990  * Calculates and updates the value of strLeaseFilename given @a aNetwork.
     990 * Calculates and updates the value of strLeasesFilename given @a aNetwork.
    991991 */
    992 HRESULT DHCPServer::i_calcLeaseFilename(const com::Utf8Str &aNetwork)
     992HRESULT DHCPServer::i_calcLeasesFilename(const com::Utf8Str &aNetwork)
    993993{
    994994    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    995995
    996996    /* The lease file must be the same as we used the last time, so careful when changing this code. */
    997     int vrc = m->strLeaseFilename.assignNoThrow(mVirtualBox->i_homeDir());
     997    int vrc = m->strLeasesFilename.assignNoThrow(mVirtualBox->i_homeDir());
    998998    if (RT_SUCCESS(vrc))
    999         vrc = RTPathAppendCxx(m->strLeaseFilename, aNetwork);
     999        vrc = RTPathAppendCxx(m->strLeasesFilename, aNetwork);
    10001000    if (RT_SUCCESS(vrc))
    1001         vrc = m->strLeaseFilename.appendNoThrow("-Dhcpd.leases");
     1001        vrc = m->strLeasesFilename.appendNoThrow("-Dhcpd.leases");
    10021002    if (RT_SUCCESS(vrc))
    10031003    {
    1004         RTPathPurgeFilename(RTPathFilename(m->strLeaseFilename.mutableRaw()), RTPATH_STR_F_STYLE_HOST);
    1005         m->strLeaseFilename.jolt();
     1004        RTPathPurgeFilename(RTPathFilename(m->strLeasesFilename.mutableRaw()), RTPATH_STR_F_STYLE_HOST);
     1005        m->strLeasesFilename.jolt();
    10061006        return S_OK;
    10071007    }
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp

    r79613 r79621  
    2929#include <iprt/string.h>
    3030#include <iprt/uuid.h>
     31#include <iprt/cpp/path.h>
    3132
    3233#include <VBox/com/com.h>       /* For log initialization. */
     
    735736        m_strTrunk = "";
    736737
    737     m_strLeaseFilename = pElmServer->findAttributeValue("leaseFilename"); /* optional */
     738    m_strLeasesFilename = pElmServer->findAttributeValue("leasesFilename"); /* optional */
     739    if (m_strLeasesFilename.isEmpty())
     740    {
     741        int rc = m_strLeasesFilename.assignNoThrow(getHome());
     742        if (RT_SUCCESS(rc))
     743            rc = RTPathAppendCxx(m_strLeasesFilename, getBaseName());
     744        if (RT_SUCCESS(rc))
     745            rc = m_strLeasesFilename.appendNoThrow("-Dhcpd.leases");
     746        if (RT_FAILURE(rc))
     747            throw ConfigFileError("Unexpected error constructing default m_strLeasesFilename value: %Rrc", rc);
     748    }
    738749
    739750    i_getIPv4AddrAttribute(pElmServer, "IPAddress", &m_IPv4Address);
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.h

    r79613 r79621  
    4646    RTCString       m_strNetwork;       /**< The name of the internal network the DHCP server is connected to. */
    4747    RTCString       m_strBaseName;      /**< m_strNetwork sanitized to be usable in a path component. */
    48     RTCString       m_strLeaseFilename; /**< The lease filename if one given.  Dhcpd will pick a default if empty. */
     48    RTCString       m_strLeasesFilename;/**< The lease DB filename. */
    4949
    5050    RTCString       m_strTrunk;         /**< The trunk name of the internal network. */
     
    9393    const RTCString    &getNetwork() const RT_NOEXCEPT          { return m_strNetwork; }
    9494    const RTCString    &getBaseName() const RT_NOEXCEPT         { return m_strBaseName; }
    95     const RTCString    &getLeaseFilename() const RT_NOEXCEPT    { return m_strLeaseFilename; }
     95    const RTCString    &getLeasesFilename() const RT_NOEXCEPT   { return m_strLeasesFilename; }
    9696
    9797    const RTCString    &getTrunk() const RT_NOEXCEPT            { return m_strTrunk; }
  • trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.cpp

    r79613 r79621  
    2525
    2626#include <iprt/message.h>
    27 #include <iprt/cpp/path.h>
    2827
    2928
     
    4443    Assert(pConfig);
    4544    AssertReturn(!m_pConfig, VERR_INVALID_STATE);
    46 
    47     /* leases filename */
    48     int rc;
    49     if (pConfig->getLeaseFilename().isEmpty())
    50         rc = m_strLeasesFilename.assignNoThrow(pConfig->getLeaseFilename());
    51     else
    52     {
    53         rc = m_strLeasesFilename.assignNoThrow(pConfig->getHome());
    54         if (RT_SUCCESS(rc))
    55             rc = RTPathAppendCxx(m_strLeasesFilename, pConfig->getBaseName());
    56         if (RT_SUCCESS(rc))
    57             rc = m_strLeasesFilename.appendNoThrow("-Dhcpd.leases");
    58     }
     45    m_pConfig = pConfig;
     46
     47    /* Load the lease database, ignoring most issues except being out of memory: */
     48    int rc = m_db.init(pConfig);
    5949    if (RT_SUCCESS(rc))
    6050    {
    61         /* Load the lease database, ignoring most issues except being out of memory: */
    62         rc = m_db.init(pConfig);
    63         if (RT_SUCCESS(rc))
    64         {
    65             rc = i_loadLeases();
    66             if (rc != VERR_NO_MEMORY)
    67             {
    68                 m_pConfig = pConfig;
    69                 rc = VINF_SUCCESS;
    70             }
    71             else
    72             {
    73                 LogRel(("Ran out of memory loading leases from '%s'.  Try rename or delete the file.\n",
    74                         m_strLeasesFilename.c_str()));
    75                 RTMsgError("Ran out of memory loading leases from '%s'.  Try rename or delete the file.\n",
    76                            m_strLeasesFilename.c_str());
    77             }
    78         }
     51        rc = i_loadLeases();
     52        if (rc != VERR_NO_MEMORY)
     53            return VINF_SUCCESS;
     54
     55        /** @todo macro for this: */
     56        LogRel((   "Ran out of memory loading leases from '%s'.  Try rename or delete the file.\n",
     57                   pConfig->getLeasesFilename().c_str()));
     58        RTMsgError("Ran out of memory loading leases from '%s'.  Try rename or delete the file.\n",
     59                   pConfig->getLeasesFilename().c_str());
    7960    }
    8061    return rc;
     
    8364
    8465/**
    85  * Load leases from m_strLeasesFilename.
     66 * Load leases from pConfig->getLeasesFilename().
    8667 */
    8768int DHCPD::i_loadLeases() RT_NOEXCEPT
    8869{
    89     return m_db.loadLeases(m_strLeasesFilename);
    90 }
    91 
    92 
    93 /**
    94  * Save the current leases to m_strLeasesFilename, doing expiry first.
     70    return m_db.loadLeases(m_pConfig->getLeasesFilename());
     71}
     72
     73
     74/**
     75 * Save the current leases to pConfig->getLeasesFilename(), doing expiry first.
    9576 *
    9677 * This is called after m_db is updated during a client request, so the on disk
     
    10485{
    10586    m_db.expire();
    106     m_db.writeLeases(m_strLeasesFilename);
     87    m_db.writeLeases(m_pConfig->getLeasesFilename());
    10788}
    10889
  • trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.h

    r79568 r79621  
    4040    /** The DHCP configuration. */
    4141    const Config   *m_pConfig;
    42     /** The lease database filename. */
    43     RTCString       m_strLeasesFilename;
    4442    /** The lease database. */
    4543    Db              m_db;
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