Changeset 79621 in vbox
- Timestamp:
- Jul 9, 2019 1:14:53 AM (5 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 6 edited
-
Main/include/DHCPServerImpl.h (modified) (1 diff)
-
Main/src-server/DHCPServerImpl.cpp (modified) (8 diffs)
-
NetworkServices/Dhcpd/Config.cpp (modified) (2 diffs)
-
NetworkServices/Dhcpd/Config.h (modified) (2 diffs)
-
NetworkServices/Dhcpd/DHCPD.cpp (modified) (4 diffs)
-
NetworkServices/Dhcpd/DHCPD.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/DHCPServerImpl.h
r79610 r79621 139 139 /** @name Helpers 140 140 * @{ */ 141 HRESULT i_calcLease Filename(const com::Utf8Str &aNetwork) RT_NOEXCEPT;141 HRESULT i_calcLeasesFilename(const com::Utf8Str &aNetwork) RT_NOEXCEPT; 142 142 /** @} */ 143 143 -
trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp
r79610 r79621 66 66 67 67 char tempConfigFileName[RTPATH_MAX]; 68 com::Utf8Str strLease Filename;68 com::Utf8Str strLeasesFilename; 69 69 com::Utf8Str networkName; 70 70 com::Utf8Str trunkName; … … 696 696 m->trunkName = aTrunkName; 697 697 m->trunkType = aTrunkType; 698 HRESULT hrc = i_calcLease Filename(aNetworkName);698 HRESULT hrc = i_calcLeasesFilename(aNetworkName); 699 699 if (FAILED(hrc)) 700 700 return hrc; … … 732 732 pElmRoot->setAttribute("lowerIP", m->lowerIP); 733 733 pElmRoot->setAttribute("upperIP", m->upperIP); 734 pElmRoot->setAttribute("lease Filename", m->strLeaseFilename);734 pElmRoot->setAttribute("leasesFilename", m->strLeasesFilename); 735 735 736 736 /* Process global options */ … … 866 866 */ 867 867 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 868 if (m->strLease Filename.isEmpty())869 { 870 HRESULT hrc = i_calcLease Filename(m->networkName.isEmpty() ? mName : m->networkName);868 if (m->strLeasesFilename.isEmpty()) 869 { 870 HRESULT hrc = i_calcLeasesFilename(m->networkName.isEmpty() ? mName : m->networkName); 871 871 if (FAILED(hrc)) 872 872 return hrc; … … 886 886 { 887 887 xml::XmlFileParser parser; 888 parser.read(m->strLease Filename.c_str(), doc);888 parser.read(m->strLeasesFilename.c_str(), doc); 889 889 } 890 890 catch (const xml::EIPRTFailure &e) … … 912 912 } 913 913 return setErrorBoth(VBOX_E_FILE_ERROR, vrc, "Reading '%s' failed: %Rrc - %s", 914 m->strLease Filename.c_str(), vrc, e.what());914 m->strLeasesFilename.c_str(), vrc, e.what()); 915 915 } 916 916 catch (const RTCError &e) 917 917 { 918 918 if (e.what()) 919 return setError(VBOX_E_FILE_ERROR, "Reading '%s' failed: %s", m->strLease Filename.c_str(), e.what());920 return setError(VBOX_E_FILE_ERROR, "Reading '%s' failed: RTCError", m->strLease Filename.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()); 921 921 } 922 922 catch (std::bad_alloc &) … … 927 927 { 928 928 AssertFailed(); 929 return setError(VBOX_E_FILE_ERROR, tr("Reading '%s' failed: Unexpected exception"), m->strLease Filename.c_str());929 return setError(VBOX_E_FILE_ERROR, tr("Reading '%s' failed: Unexpected exception"), m->strLeasesFilename.c_str()); 930 930 } 931 931 … … 988 988 989 989 /** 990 * Calculates and updates the value of strLease Filename given @a aNetwork.990 * Calculates and updates the value of strLeasesFilename given @a aNetwork. 991 991 */ 992 HRESULT DHCPServer::i_calcLease Filename(const com::Utf8Str &aNetwork)992 HRESULT DHCPServer::i_calcLeasesFilename(const com::Utf8Str &aNetwork) 993 993 { 994 994 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 995 995 996 996 /* The lease file must be the same as we used the last time, so careful when changing this code. */ 997 int vrc = m->strLease Filename.assignNoThrow(mVirtualBox->i_homeDir());997 int vrc = m->strLeasesFilename.assignNoThrow(mVirtualBox->i_homeDir()); 998 998 if (RT_SUCCESS(vrc)) 999 vrc = RTPathAppendCxx(m->strLease Filename, aNetwork);999 vrc = RTPathAppendCxx(m->strLeasesFilename, aNetwork); 1000 1000 if (RT_SUCCESS(vrc)) 1001 vrc = m->strLease Filename.appendNoThrow("-Dhcpd.leases");1001 vrc = m->strLeasesFilename.appendNoThrow("-Dhcpd.leases"); 1002 1002 if (RT_SUCCESS(vrc)) 1003 1003 { 1004 RTPathPurgeFilename(RTPathFilename(m->strLease Filename.mutableRaw()), RTPATH_STR_F_STYLE_HOST);1005 m->strLease Filename.jolt();1004 RTPathPurgeFilename(RTPathFilename(m->strLeasesFilename.mutableRaw()), RTPATH_STR_F_STYLE_HOST); 1005 m->strLeasesFilename.jolt(); 1006 1006 return S_OK; 1007 1007 } -
trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp
r79613 r79621 29 29 #include <iprt/string.h> 30 30 #include <iprt/uuid.h> 31 #include <iprt/cpp/path.h> 31 32 32 33 #include <VBox/com/com.h> /* For log initialization. */ … … 735 736 m_strTrunk = ""; 736 737 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 } 738 749 739 750 i_getIPv4AddrAttribute(pElmServer, "IPAddress", &m_IPv4Address); -
trunk/src/VBox/NetworkServices/Dhcpd/Config.h
r79613 r79621 46 46 RTCString m_strNetwork; /**< The name of the internal network the DHCP server is connected to. */ 47 47 RTCString m_strBaseName; /**< m_strNetwork sanitized to be usable in a path component. */ 48 RTCString m_strLease Filename; /**< The lease filename if one given. Dhcpd will pick a default if empty. */48 RTCString m_strLeasesFilename;/**< The lease DB filename. */ 49 49 50 50 RTCString m_strTrunk; /**< The trunk name of the internal network. */ … … 93 93 const RTCString &getNetwork() const RT_NOEXCEPT { return m_strNetwork; } 94 94 const RTCString &getBaseName() const RT_NOEXCEPT { return m_strBaseName; } 95 const RTCString &getLease Filename() const RT_NOEXCEPT { return m_strLeaseFilename; }95 const RTCString &getLeasesFilename() const RT_NOEXCEPT { return m_strLeasesFilename; } 96 96 97 97 const RTCString &getTrunk() const RT_NOEXCEPT { return m_strTrunk; } -
trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.cpp
r79613 r79621 25 25 26 26 #include <iprt/message.h> 27 #include <iprt/cpp/path.h>28 27 29 28 … … 44 43 Assert(pConfig); 45 44 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); 59 49 if (RT_SUCCESS(rc)) 60 50 { 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()); 79 60 } 80 61 return rc; … … 83 64 84 65 /** 85 * Load leases from m_strLeasesFilename.66 * Load leases from pConfig->getLeasesFilename(). 86 67 */ 87 68 int DHCPD::i_loadLeases() RT_NOEXCEPT 88 69 { 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. 95 76 * 96 77 * This is called after m_db is updated during a client request, so the on disk … … 104 85 { 105 86 m_db.expire(); 106 m_db.writeLeases(m_ strLeasesFilename);87 m_db.writeLeases(m_pConfig->getLeasesFilename()); 107 88 } 108 89 -
trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.h
r79568 r79621 40 40 /** The DHCP configuration. */ 41 41 const Config *m_pConfig; 42 /** The lease database filename. */43 RTCString m_strLeasesFilename;44 42 /** The lease database. */ 45 43 Db m_db;
Note:
See TracChangeset
for help on using the changeset viewer.

