Teach rdate to timeout in 10 seconds to avoid blocking forever
with odd or broken networking setups
This commit is contained in:
parent
f57a614db9
commit
e15138a870
@ -32,11 +32,17 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
|
|
||||||
static const int RFC_868_BIAS = 2208988800UL;
|
static const int RFC_868_BIAS = 2208988800UL;
|
||||||
|
|
||||||
|
static void socket_timeout()
|
||||||
|
{
|
||||||
|
bb_error_msg_and_die("timeout connecting to time server\n");
|
||||||
|
}
|
||||||
|
|
||||||
static time_t askremotedate(const char *host)
|
static time_t askremotedate(const char *host)
|
||||||
{
|
{
|
||||||
unsigned long int nett, localt;
|
unsigned long int nett, localt;
|
||||||
@ -46,6 +52,10 @@ static time_t askremotedate(const char *host)
|
|||||||
if (getservbyname("time", "tcp") != NULL)
|
if (getservbyname("time", "tcp") != NULL)
|
||||||
port="time";
|
port="time";
|
||||||
|
|
||||||
|
/* Add a timeout for dead or non accessable servers */
|
||||||
|
alarm(10);
|
||||||
|
signal(SIGALRM, socket_timeout);
|
||||||
|
|
||||||
fd = xconnect(host, port);
|
fd = xconnect(host, port);
|
||||||
|
|
||||||
if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */
|
if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */
|
||||||
|
Loading…
Reference in New Issue
Block a user