diff options
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 0e236261b..6aa6731fb 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -73,7 +73,9 @@ static const char udhcpc_longopts[] ALIGN1 = | |||
73 | "request-option\0" Required_argument "O" | 73 | "request-option\0" Required_argument "O" |
74 | "no-default-options\0" No_argument "o" | 74 | "no-default-options\0" No_argument "o" |
75 | "foreground\0" No_argument "f" | 75 | "foreground\0" No_argument "f" |
76 | USE_FOR_MMU( | ||
76 | "background\0" No_argument "b" | 77 | "background\0" No_argument "b" |
78 | ) | ||
77 | "broadcast\0" No_argument "B" | 79 | "broadcast\0" No_argument "B" |
78 | IF_FEATURE_UDHCPC_ARPING("arping\0" Optional_argument "a") | 80 | IF_FEATURE_UDHCPC_ARPING("arping\0" Optional_argument "a") |
79 | IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") | 81 | IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") |
@@ -1281,9 +1283,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1281 | unsigned already_waited_sec; | 1283 | unsigned already_waited_sec; |
1282 | unsigned opt; | 1284 | unsigned opt; |
1283 | IF_FEATURE_UDHCPC_ARPING(unsigned arpping_ms;) | 1285 | IF_FEATURE_UDHCPC_ARPING(unsigned arpping_ms;) |
1284 | int max_fd; | ||
1285 | int retval; | 1286 | int retval; |
1286 | fd_set rfds; | ||
1287 | 1287 | ||
1288 | setup_common_bufsiz(); | 1288 | setup_common_bufsiz(); |
1289 | 1289 | ||
@@ -1367,6 +1367,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1367 | /* now it looks similar to udhcpd's config file line: | 1367 | /* now it looks similar to udhcpd's config file line: |
1368 | * "optname optval", using the common routine: */ | 1368 | * "optname optval", using the common routine: */ |
1369 | udhcp_str2optset(optstr, &client_config.options); | 1369 | udhcp_str2optset(optstr, &client_config.options); |
1370 | if (colon) | ||
1371 | *colon = ':'; /* restore it for NOMMU reexec */ | ||
1370 | } | 1372 | } |
1371 | 1373 | ||
1372 | if (udhcp_read_interface(client_config.interface, | 1374 | if (udhcp_read_interface(client_config.interface, |
@@ -1432,7 +1434,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1432 | * "continue" statements in code below jump to the top of the loop. | 1434 | * "continue" statements in code below jump to the top of the loop. |
1433 | */ | 1435 | */ |
1434 | for (;;) { | 1436 | for (;;) { |
1435 | struct timeval tv; | 1437 | int tv; |
1438 | struct pollfd pfds[2]; | ||
1436 | struct dhcp_packet packet; | 1439 | struct dhcp_packet packet; |
1437 | /* silence "uninitialized!" warning */ | 1440 | /* silence "uninitialized!" warning */ |
1438 | unsigned timestamp_before_wait = timestamp_before_wait; | 1441 | unsigned timestamp_before_wait = timestamp_before_wait; |
@@ -1446,23 +1449,22 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1446 | * to change_listen_mode(). Thus we open listen socket | 1449 | * to change_listen_mode(). Thus we open listen socket |
1447 | * BEFORE we send renew request (see "case BOUND:"). */ | 1450 | * BEFORE we send renew request (see "case BOUND:"). */ |
1448 | 1451 | ||
1449 | max_fd = udhcp_sp_fd_set(&rfds, sockfd); | 1452 | udhcp_sp_fd_set(pfds, sockfd); |
1450 | 1453 | ||
1451 | tv.tv_sec = timeout - already_waited_sec; | 1454 | tv = timeout - already_waited_sec; |
1452 | tv.tv_usec = 0; | ||
1453 | retval = 0; | 1455 | retval = 0; |
1454 | /* If we already timed out, fall through with retval = 0, else... */ | 1456 | /* If we already timed out, fall through with retval = 0, else... */ |
1455 | if ((int)tv.tv_sec > 0) { | 1457 | if (tv > 0) { |
1456 | log1("waiting on select %u seconds", (int)tv.tv_sec); | 1458 | log1("waiting on select %u seconds", tv); |
1457 | timestamp_before_wait = (unsigned)monotonic_sec(); | 1459 | timestamp_before_wait = (unsigned)monotonic_sec(); |
1458 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); | 1460 | retval = poll(pfds, 2, tv < INT_MAX/1000 ? tv * 1000 : INT_MAX); |
1459 | if (retval < 0) { | 1461 | if (retval < 0) { |
1460 | /* EINTR? A signal was caught, don't panic */ | 1462 | /* EINTR? A signal was caught, don't panic */ |
1461 | if (errno == EINTR) { | 1463 | if (errno == EINTR) { |
1462 | already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait; | 1464 | already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait; |
1463 | continue; | 1465 | continue; |
1464 | } | 1466 | } |
1465 | /* Else: an error occured, panic! */ | 1467 | /* Else: an error occurred, panic! */ |
1466 | bb_perror_msg_and_die("select"); | 1468 | bb_perror_msg_and_die("select"); |
1467 | } | 1469 | } |
1468 | } | 1470 | } |
@@ -1591,8 +1593,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1591 | /* select() didn't timeout, something happened */ | 1593 | /* select() didn't timeout, something happened */ |
1592 | 1594 | ||
1593 | /* Is it a signal? */ | 1595 | /* Is it a signal? */ |
1594 | /* note: udhcp_sp_read checks FD_ISSET before reading */ | 1596 | /* note: udhcp_sp_read checks poll result before reading */ |
1595 | switch (udhcp_sp_read(&rfds)) { | 1597 | switch (udhcp_sp_read(pfds)) { |
1596 | case SIGUSR1: | 1598 | case SIGUSR1: |
1597 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1599 | client_config.first_secs = 0; /* make secs field count from 0 */ |
1598 | already_waited_sec = 0; | 1600 | already_waited_sec = 0; |
@@ -1627,7 +1629,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1627 | } | 1629 | } |
1628 | 1630 | ||
1629 | /* Is it a packet? */ | 1631 | /* Is it a packet? */ |
1630 | if (listen_mode == LISTEN_NONE || !FD_ISSET(sockfd, &rfds)) | 1632 | if (listen_mode == LISTEN_NONE || !pfds[1].revents) |
1631 | continue; /* no */ | 1633 | continue; /* no */ |
1632 | 1634 | ||
1633 | { | 1635 | { |
@@ -1742,8 +1744,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1742 | /* paranoia: must not be too small and not prone to overflows */ | 1744 | /* paranoia: must not be too small and not prone to overflows */ |
1743 | if (lease_seconds < 0x10) | 1745 | if (lease_seconds < 0x10) |
1744 | lease_seconds = 0x10; | 1746 | lease_seconds = 0x10; |
1745 | if (lease_seconds >= 0x10000000) | 1747 | if (lease_seconds > 0x7fffffff / 1000) |
1746 | lease_seconds = 0x0fffffff; | 1748 | lease_seconds = 0x7fffffff / 1000; |
1747 | } | 1749 | } |
1748 | #if ENABLE_FEATURE_UDHCPC_ARPING | 1750 | #if ENABLE_FEATURE_UDHCPC_ARPING |
1749 | if (opt & OPT_a) { | 1751 | if (opt & OPT_a) { |