[haiku-commits] r35954 - haiku/trunk/src/servers/net

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 26 Mar 2010 11:43:51 +0100 (CET)

Author: stippi
Date: 2010-03-26 11:43:51 +0100 (Fri, 26 Mar 2010)
New Revision: 35954
Changeset: http://dev.haiku-os.org/changeset/35954/haiku

Modified:
   haiku/trunk/src/servers/net/DHCPClient.cpp
   haiku/trunk/src/servers/net/DHCPClient.h
Log:
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.


Modified: haiku/trunk/src/servers/net/DHCPClient.cpp
===================================================================
--- haiku/trunk/src/servers/net/DHCPClient.cpp  2010-03-26 00:15:59 UTC (rev 
35953)
+++ haiku/trunk/src/servers/net/DHCPClient.cpp  2010-03-26 10:43:51 UTC (rev 
35954)
@@ -336,8 +336,7 @@
        : AutoconfigClient("dhcp", target, device),
        fConfiguration(kMsgConfigureInterface),
        fRunner(NULL),
-       fLeaseTime(0),
-       fRewriteResolvConf(true)
+       fLeaseTime(0)
 {
        fStartTime = system_time();
        fTransactionID = (uint32)fStartTime;
@@ -463,7 +462,6 @@
                // no need to check the status; in case of an error we'll just 
send
                // the message again
 
-       fRewriteResolvConf = true;
        // receive loop until we've got an offer and acknowledged it
 
        while (state != ACKNOWLEDGED) {
@@ -620,6 +618,10 @@
        // maintained and it should be distinguished between user entered
        // and auto-generated parts of the file, with this method only 
re-writing
        // 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)) {
                // iterate through all options
                switch (option) {
@@ -640,13 +642,13 @@
                                        break;
                                }
 
-                               const char* openMode = fRewriteResolvConf ? "w" 
: "a";
+                               const char* openMode = resolvConfCreated ? "a" 
: "w";
                                FILE* file = fopen(path.Path(), openMode);
                                for (uint32 i = 0; i < size / 4; i++) {
                                        syslog(LOG_INFO, "DNS: %s\n",
                                                _ToString(&data[i * 
4]).String());
                                        if (file != NULL) {
-                                               fRewriteResolvConf = false;
+                                               resolvConfCreated = true;
                                                fprintf(file, "nameserver %s\n",
                                                        _ToString(&data[i * 
4]).String());
                                        }
@@ -690,10 +692,10 @@
                                        break;
                                }
 
-                               const char* openMode = fRewriteResolvConf ? "w" 
: "a";
+                               const char* openMode = resolvConfCreated ? "a" 
: "w";
                                FILE* file = fopen(path.Path(), openMode);
                                if (file != NULL) {
-                                       fRewriteResolvConf = false;
+                                       resolvConfCreated = true;
                                        fprintf(file, "domain %.*s\n", 
(int)size,
                                                (const char*)data);
                                        fclose(file);

Modified: haiku/trunk/src/servers/net/DHCPClient.h
===================================================================
--- haiku/trunk/src/servers/net/DHCPClient.h    2010-03-26 00:15:59 UTC (rev 
35953)
+++ haiku/trunk/src/servers/net/DHCPClient.h    2010-03-26 10:43:51 UTC (rev 
35954)
@@ -65,7 +65,6 @@
                        bigtime_t                       fRebindingTime;
                        bigtime_t                       fLeaseTime;
                        status_t                        fStatus;
-                       bool                            fRewriteResolvConf;
 };
 
 #endif // DHCP_CLIENT_H


Other related posts:

  • » [haiku-commits] r35954 - haiku/trunk/src/servers/net - superstippi