My first fix to avoid overwriting resolv.conf was better. Reverted to this code
and clarified the TODO comments. resolv.conf is written again once per _ParseOptions(), with the DHCP_ACK messages providing the final data. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35954 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -336,8 +336,7 @@ DHCPClient::DHCPClient(BMessenger target, const char* device)
|
|||||||
: AutoconfigClient("dhcp", target, device),
|
: AutoconfigClient("dhcp", target, device),
|
||||||
fConfiguration(kMsgConfigureInterface),
|
fConfiguration(kMsgConfigureInterface),
|
||||||
fRunner(NULL),
|
fRunner(NULL),
|
||||||
fLeaseTime(0),
|
fLeaseTime(0)
|
||||||
fRewriteResolvConf(true)
|
|
||||||
{
|
{
|
||||||
fStartTime = system_time();
|
fStartTime = system_time();
|
||||||
fTransactionID = (uint32)fStartTime;
|
fTransactionID = (uint32)fStartTime;
|
||||||
@@ -463,7 +462,6 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
// no need to check the status; in case of an error we'll just send
|
// no need to check the status; in case of an error we'll just send
|
||||||
// the message again
|
// the message again
|
||||||
|
|
||||||
fRewriteResolvConf = true;
|
|
||||||
// receive loop until we've got an offer and acknowledged it
|
// receive loop until we've got an offer and acknowledged it
|
||||||
|
|
||||||
while (state != ACKNOWLEDGED) {
|
while (state != ACKNOWLEDGED) {
|
||||||
@@ -620,6 +618,10 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address)
|
|||||||
// maintained and it should be distinguished between user entered
|
// maintained and it should be distinguished between user entered
|
||||||
// and auto-generated parts of the file, with this method only re-writing
|
// and auto-generated parts of the file, with this method only re-writing
|
||||||
// the auto-generated parts of course.
|
// the auto-generated parts of course.
|
||||||
|
// TODO: We write resolv.conf once per _ParseOptions invokation, there
|
||||||
|
// is the first DHCP_OFFER message and the final DHCP_ACK message
|
||||||
|
// from the same server, which should contain all the final data.
|
||||||
|
bool resolvConfCreated = false;
|
||||||
while (message.NextOption(cookie, option, data, size)) {
|
while (message.NextOption(cookie, option, data, size)) {
|
||||||
// iterate through all options
|
// iterate through all options
|
||||||
switch (option) {
|
switch (option) {
|
||||||
@@ -640,13 +642,13 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* openMode = fRewriteResolvConf ? "w" : "a";
|
const char* openMode = resolvConfCreated ? "a" : "w";
|
||||||
FILE* file = fopen(path.Path(), openMode);
|
FILE* file = fopen(path.Path(), openMode);
|
||||||
for (uint32 i = 0; i < size / 4; i++) {
|
for (uint32 i = 0; i < size / 4; i++) {
|
||||||
syslog(LOG_INFO, "DNS: %s\n",
|
syslog(LOG_INFO, "DNS: %s\n",
|
||||||
_ToString(&data[i * 4]).String());
|
_ToString(&data[i * 4]).String());
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
fRewriteResolvConf = false;
|
resolvConfCreated = true;
|
||||||
fprintf(file, "nameserver %s\n",
|
fprintf(file, "nameserver %s\n",
|
||||||
_ToString(&data[i * 4]).String());
|
_ToString(&data[i * 4]).String());
|
||||||
}
|
}
|
||||||
@@ -690,10 +692,10 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* openMode = fRewriteResolvConf ? "w" : "a";
|
const char* openMode = resolvConfCreated ? "a" : "w";
|
||||||
FILE* file = fopen(path.Path(), openMode);
|
FILE* file = fopen(path.Path(), openMode);
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
fRewriteResolvConf = false;
|
resolvConfCreated = true;
|
||||||
fprintf(file, "domain %.*s\n", (int)size,
|
fprintf(file, "domain %.*s\n", (int)size,
|
||||||
(const char*)data);
|
(const char*)data);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ private:
|
|||||||
bigtime_t fRebindingTime;
|
bigtime_t fRebindingTime;
|
||||||
bigtime_t fLeaseTime;
|
bigtime_t fLeaseTime;
|
||||||
status_t fStatus;
|
status_t fStatus;
|
||||||
bool fRewriteResolvConf;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DHCP_CLIENT_H
|
#endif // DHCP_CLIENT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user