Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/date roll back to 20101210 -- the current version just h...
details: https://anonhg.NetBSD.org/src/rev/22247049ad19
branches: trunk
changeset: 761468:22247049ad19
user: drochner <drochner%NetBSD.org@localhost>
date: Fri Jan 28 20:23:38 2011 +0000
description:
roll back to 20101210 -- the current version just hung if one tried
to set the date
diffstat:
bin/date/date.c | 45 ++++++++++++++-------------------------------
bin/date/netdate.c | 37 ++++++++++++++++++++-----------------
2 files changed, 34 insertions(+), 48 deletions(-)
diffs (267 lines):
diff -r bdb83a642e05 -r 22247049ad19 bin/date/date.c
--- a/bin/date/date.c Fri Jan 28 19:21:28 2011 +0000
+++ b/bin/date/date.c Fri Jan 28 20:23:38 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.57 2010/12/12 17:30:23 christos Exp $ */
+/* $NetBSD: date.c,v 1.58 2011/01/28 20:23:38 drochner Exp $ */
/*
* Copyright (c) 1985, 1987, 1988, 1993
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: date.c,v 1.57 2010/12/12 17:30:23 christos Exp $");
+__RCSID("$NetBSD: date.c,v 1.58 2011/01/28 20:23:38 drochner Exp $");
#endif
#endif /* not lint */
@@ -50,7 +50,6 @@
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
-#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
@@ -65,12 +64,13 @@
static time_t tval;
static int aflag, jflag, rflag, nflag;
+int retval;
static void badformat(void);
static void badtime(void);
static void badvalue(const char *);
static void setthetime(const char *);
-static void usage(void) __attribute__((__noreturn__));
+static void usage(void);
int
main(int argc, char *argv[])
@@ -79,8 +79,6 @@
size_t bufsiz;
const char *format;
int ch;
- long long val;
- struct tm *tm;
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
@@ -94,9 +92,8 @@
case 'd':
rflag = 1;
tval = parsedate(optarg, NULL, NULL);
- if (tval == -1)
-badarg: errx(EXIT_FAILURE,
- "Cannot parse `%s'", optarg);
+ if (tval == -1)
+ errx(1, "Cannot parse `%s'", optarg);
break;
case 'j': /* don't set time */
jflag = 1;
@@ -105,15 +102,8 @@
nflag = 1;
break;
case 'r': /* user specified seconds */
- errno = 0;
- val = strtoll(optarg, &buf, 0);
- if (optarg[0] == '\0' || *buf != '\0')
- goto badarg;
- if (errno == ERANGE && (val == LLONG_MAX ||
- val == LLONG_MIN))
- err(EXIT_FAILURE, "Bad number `%s'", optarg);
rflag = 1;
- tval = (time_t)val;
+ tval = strtoll(optarg, NULL, 0);
break;
case 'u': /* do everything in UTC */
(void)setenv("TZ", "UTC0", 1);
@@ -128,13 +118,13 @@
if (!rflag && time(&tval) == -1)
err(EXIT_FAILURE, "time");
+ format = "+%a %b %e %H:%M:%S %Z %Y";
/* allow the operands in any order */
if (*argv && **argv == '+') {
format = *argv;
++argv;
- } else
- format = "+%a %b %e %H:%M:%S %Z %Y";
+ }
if (*argv) {
setthetime(*argv);
@@ -146,19 +136,14 @@
if ((buf = malloc(bufsiz = 1024)) == NULL)
goto bad;
-
- if ((tm = localtime(&tval)) == NULL)
- err(EXIT_FAILURE, "localtime %lld failed", (long long)tval);
-
- while (strftime(buf, bufsiz, format, tm) == 0)
+ while (strftime(buf, bufsiz, format, localtime(&tval)) == 0)
if ((buf = realloc(buf, bufsiz <<= 1)) == NULL)
goto bad;
-
- (void)printf("%s\n", buf + 1);
+ (void)printf("%s\n", buf+1);
free(buf);
return 0;
bad:
- err(EXIT_FAILURE, "Cannot allocate format buffer");
+ err(1, "Cannot allocate format buffer");
}
static void
@@ -204,8 +189,7 @@
badformat();
}
- if ((lt = localtime(&tval)) == NULL)
- err(EXIT_FAILURE, "localtime %lld failed", (long long)tval);
+ lt = localtime(&tval);
lt->tm_isdst = -1; /* Divine correct DST */
@@ -333,8 +317,7 @@
usage(void)
{
(void)fprintf(stderr,
- "Usage: %s [-ajnu] [-d date] [-r seconds] [+format]",
- getprogname());
+ "usage: %s [-ajnu] [-d date] [-r seconds] [+format]", getprogname());
(void)fprintf(stderr, " [[[[[[CC]yy]mm]dd]HH]MM[.SS]]\n");
exit(EXIT_FAILURE);
/* NOTREACHED */
diff -r bdb83a642e05 -r 22247049ad19 bin/date/netdate.c
--- a/bin/date/netdate.c Fri Jan 28 19:21:28 2011 +0000
+++ b/bin/date/netdate.c Fri Jan 28 20:23:38 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netdate.c,v 1.28 2010/12/11 16:57:51 christos Exp $ */
+/* $NetBSD: netdate.c,v 1.29 2011/01/28 20:23:38 drochner Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)netdate.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: netdate.c,v 1.28 2010/12/11 16:57:51 christos Exp $");
+__RCSID("$NetBSD: netdate.c,v 1.29 2011/01/28 20:23:38 drochner Exp $");
#endif
#endif /* not lint */
@@ -59,6 +59,8 @@
#define WAITACK 2000 /* milliseconds */
#define WAITDATEACK 5000 /* milliseconds */
+extern int retval;
+
static const char *
tsp_type_to_string(const struct tsp *msg)
{
@@ -73,7 +75,7 @@
* new date to the local timedaemon. If the timedaemon is in the master state,
* it performs the correction on all slaves. If it is in the slave state, it
* notifies the master that a correction is needed.
- * Returns 0 on success. Returns > 0 on failure.
+ * Returns 0 on success. Returns > 0 on failure, setting retval to 2;
*/
int
netsettime(time_t tval)
@@ -87,7 +89,7 @@
if ((sp = getservbyname("timed", "udp")) == NULL) {
warnx("udp/timed: unknown service");
- return 2;
+ return (retval = 2);
}
(void)memset(&dest, 0, sizeof(dest));
@@ -98,18 +100,18 @@
dest.sin_port = sp->s_port;
dest.sin_addr.s_addr = htonl(INADDR_ANY);
s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s == -1) {
+ if (s < 0) {
if (errno != EAFNOSUPPORT)
warn("timed");
- return 2;
+ return (retval = 2);
}
#ifdef IP_PORTRANGE
{
static const int on = IP_PORTRANGE_LOW;
- if (setsockopt(s, IPPROTO_IP, IP_PORTRANGE, &on,
- sizeof(on)) == -1) {
+ if (setsockopt(s, IPPROTO_IP, IP_PORTRANGE,
+ &on, sizeof(on)) < 0) {
warn("setsockopt");
goto bad;
}
@@ -118,19 +120,20 @@
msg.tsp_type = TSP_SETDATE;
msg.tsp_vers = TSPVERSION;
- if (gethostname(hostname, sizeof(hostname)) == -1) {
+ if (gethostname(hostname, sizeof(hostname))) {
warn("gethostname");
goto bad;
}
- (void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
+ strncpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
+ msg.tsp_name[sizeof(msg.tsp_name) - 1] = '\0';
msg.tsp_seq = htons((uint16_t)0);
msg.tsp_time.tv_sec = htonl((uint32_t)tval); /* XXX: y2038 */
msg.tsp_time.tv_usec = htonl((uint32_t)0);
- if (connect(s, (const void *)&dest, sizeof(dest)) == -1) {
+ if (connect(s, (const struct sockaddr *)&dest, sizeof(dest)) < 0) {
warn("connect");
goto bad;
}
- if (send(s, &msg, sizeof(msg), 0) == -1) {
+ if (send(s, &msg, sizeof(msg), 0) < 0) {
if (errno != ECONNREFUSED)
warn("send");
goto bad;
@@ -148,7 +151,7 @@
int error;
length = sizeof(error);
- if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &length) == -1
+ if (!getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &length)
&& error) {
if (error != ECONNREFUSED)
warn("send (delayed error)");
@@ -159,8 +162,8 @@
if (found > 0 && ready.revents & POLLIN) {
ssize_t ret;
- if ((ret = recv(s, &msg, sizeof(msg), 0)) == -1) {
- if (ret < 0)
+ ret = recv(s, &msg, sizeof(msg), 0);
+ if (ret < 0) {
if (errno != ECONNREFUSED)
warn("recv");
goto bad;
@@ -179,7 +182,7 @@
goto loop;
case TSP_DATEACK:
(void)close(s);
- return 0;
+ return (0);
default:
warnx("wrong ack received from timed: %s",
tsp_type_to_string(&msg));
@@ -192,5 +195,5 @@
bad:
(void)close(s);
- return 2;
+ return (retval = 2);
}
Home |
Main Index |
Thread Index |
Old Index