[PATCH] udhcpc: give up on repeated errors
Peter Korsgaard
jacmet at uclibc.org
Tue May 20 11:51:46 UTC 2008
From: Peter Korsgaard <jacmet at sunsite.dk>
udhcpc never time out if errors occur (E.G. if the network
interface didn't detect a link), as the file descriptor keeps
on being readable with the error condition (E.G. -ENETDOWN).
Add a max_errors and give up if it is exceeded.
Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
---
networking/udhcp/dhcpc.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index fb328cb..8154db3 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -140,6 +140,8 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
int tryagain_timeout = 20;
int discover_timeout = 3;
int discover_retries = 3;
+ int errors = 0;
+ int max_errors = 5;
uint32_t xid = 0;
uint32_t lease_seconds = 0; /* can be given as 32-bit quantity */
int packet_num;
@@ -477,6 +479,13 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (len == -1) { /* error is severe, reopen socket */
DEBUG("error on read, %s, reopening socket", strerror(errno));
change_listen_mode(listen_mode); /* just close and reopen */
+ if (++errors >= max_errors) {
+ bb_info_msg("Too many errors, failing");
+ retval = 2;
+ goto ret;
+ }
+ } else {
+ errors = 0;
}
if (len < 0) continue;
--
1.5.5.1
More information about the busybox
mailing list