projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Do not use the _syscall5 macro -- use syscall(2) instead
[oweals/busybox.git]
/
util-linux
/
rdate.c
diff --git
a/util-linux/rdate.c
b/util-linux/rdate.c
index df7d7bbc413445cbc76e8851bc3fe2e68969d432..c9a7ffeabe2970ae7ce5ca664c6043fa0fd8b3b2 100644
(file)
--- a/
util-linux/rdate.c
+++ b/
util-linux/rdate.c
@@
-32,24
+32,34
@@
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
+#include <signal.h>
+
#include "busybox.h"
static const int RFC_868_BIAS = 2208988800UL;
#include "busybox.h"
static const int RFC_868_BIAS = 2208988800UL;
+static void socket_timeout(int sig)
+{
+ bb_error_msg_and_die("timeout connecting to time server");
+}
+
static time_t askremotedate(const char *host)
{
unsigned long int nett, localt;
static time_t askremotedate(const char *host)
{
unsigned long int nett, localt;
-
const char *port="37"
;
+
struct sockaddr_in s_in
;
int fd;
int fd;
- if (getservbyname("time", "tcp") != NULL)
- port="time";
+ bb_lookup_host(&s_in, host, "time");
+
+ /* Add a timeout for dead or non accessable servers */
+ alarm(10);
+ signal(SIGALRM, socket_timeout);
- fd = xconnect(
host, port
);
+ fd = xconnect(
&s_in
);
- if (read(fd, (void *)&nett, 4) != 4) /* read time from server */
- error_msg_and_die("%s did not send the complete time", host);
+ if (
safe_
read(fd, (void *)&nett, 4) != 4) /* read time from server */
+
bb_
error_msg_and_die("%s did not send the complete time", host);
close(fd);
close(fd);
@@
-83,18
+93,18
@@
int rdate_main(int argc, char **argv)
setdate = 0;
break;
default:
setdate = 0;
break;
default:
- show_usage();
+
bb_
show_usage();
}
}
if (optind == argc)
}
}
if (optind == argc)
- show_usage();
+
bb_
show_usage();
remote_time = askremotedate(argv[optind]);
if (setdate) {
if (stime(&remote_time) < 0)
remote_time = askremotedate(argv[optind]);
if (setdate) {
if (stime(&remote_time) < 0)
- perror_msg_and_die("Could not set time of day");
+
bb_
perror_msg_and_die("Could not set time of day");
}
if (printdate)
}
if (printdate)