Fix a minor bug in `ipfconfig` and clean up some logic.
authorDan Cross <crossd@gmail.com>
Fri, 7 Oct 2016 20:13:20 +0000 (16:13 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 11 Oct 2016 18:28:04 +0000 (14:28 -0400)
If the lease time is 1, then we wouldn't wait; that's a bug.
Clean up an obnoxious conditional.

Change-Id: I25ad3c5ac3510d56a0dc3d37b464ca002236875b
Signed-off-by: Dan Cross <crossd@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tools/apps/ipconfig/main.c

index db353bd..9aa0712 100644 (file)
@@ -952,20 +952,17 @@ static void *dhcpwatchthr(void *arg)
        uint32_t t;
        int needconfig = (arg == NULL);
 
-       // procsetname("dhcpwatch");
        /* keep trying to renew the lease */
        for (;;) {
-               if (conf.lease == 0)
+               secs = conf.lease / 2;
+               if (secs == 0)
                        secs = 5;
-               else
-                       secs = conf.lease >> 1;
 
                /* avoid overflows */
                for (s = secs; s > 0; s -= t) {
-                       if (s > Maxsleep)
+                       t = s;
+                       if (t > Maxsleep)
                                t = Maxsleep;
-                       else
-                               t = s;
                        usleep(t * 1000 * 1000);
                }
 
@@ -1279,9 +1276,8 @@ void dhcprecv(void)
                /* get plan9-specific options */
                n = optgetvec(bp->optdata, OBvendorinfo, vopts, sizeof(vopts) - 1);
                if (n > 0 && parseoptions(vopts, n) == 0) {
-                       if (validip(conf.fs) && Oflag)
-                               n = 1;
-                       else {
+                       n = 1;
+                       if (!validip(conf.fs) || !Oflag) {
                                n = optgetp9addrs(vopts, OP9fs, conf.fs, 2);
                                if (n == 0)
                                        n = optgetaddrs(vopts, OP9fsv4, conf.fs, 2);
@@ -1289,9 +1285,8 @@ void dhcprecv(void)
                        for (i = 0; i < n; i++)
                                DEBUG("fs=%R ", conf.fs + i * IPaddrlen);
 
-                       if (validip(conf.auth) && Oflag)
-                               n = 1;
-                       else {
+                       n = 1;
+                       if (!validip(conf.auth) || !Oflag) {
                                n = optgetp9addrs(vopts, OP9auth, conf.auth, 2);
                                if (n == 0)
                                        n = optgetaddrs(vopts, OP9authv4, conf.auth, 2);