]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix timeout for -p N. Fixes #5106
authorAlan T. DeKok <aland@freeradius.org>
Wed, 12 Jul 2023 14:11:52 +0000 (10:11 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 12 Jul 2023 14:11:52 +0000 (10:11 -0400)
src/main/radclient.c

index 49da461149995f7f8bbeadfcfffc5b491563fc9e..d6e1ebb79aad2d7c41987f45705b5dfd88a8014b 100644 (file)
@@ -1562,6 +1562,7 @@ int main(int argc, char **argv)
                int n = parallel;
                rc_request_t *next;
                char const *filename = NULL;
+               time_t wake = 0;
 
                done = true;
                sleep_time = -1;
@@ -1569,6 +1570,15 @@ int main(int argc, char **argv)
                /*
                 *      Walk over the packets, sending them.
                 */
+               for (this = request_head; this != NULL; this = this->next) {
+                       if (this->reply) continue;
+
+                       if (!this->timestamp) continue;
+
+                       if (!wake || (wake > (this->timestamp + ((int) timeout) * (retries - this->tries)))) {
+                               wake = this->timestamp + ((int) timeout) * (retries - this->tries);
+                       }
+               }
 
                for (this = request_head; this != NULL; this = next) {
                        next = this->next;
@@ -1613,6 +1623,10 @@ int main(int argc, char **argv)
                                        break;
                                }
 
+                               if (!wake || (wake > (this->timestamp + ((int) timeout) * (retries - this->tries)))) {
+                                       wake = this->timestamp + ((int) timeout) * (retries - this->tries);
+                               }
+
                                /*
                                 *      Wait a little before sending
                                 *      the next packet, if told to.
@@ -1664,7 +1678,18 @@ int main(int argc, char **argv)
                 *      Still have outstanding requests.
                 */
                if (fr_packet_list_num_elements(pl) > 0) {
+                       time_t now = time(NULL);
                        done = false;
+
+                       /*
+                        *      The last time we wake up for a packet.
+                        *
+                        *      If we're past that time, then give up.
+                        */
+                       if (wake < now) {
+                               break;
+                       }
+
                } else {
                        sleep_time = 0;
                }