VirtualBox

Ignore:
Timestamp:
Jul 9, 2019 1:14:53 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131923
Message:

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

Location:
trunk/src/VBox/NetworkServices/Dhcpd
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.

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