Package: rdate Version: 1:1.1.3-2 Severity: wishlist Tags: patch Hi,
I have problems with rdate with hundreds of network clients that use PPP over 9600bps CSD connections. The link "delay" is often less than 2 seconds, but if a file transfer is in progress, it can take 30 seconds for rdate fetching the date. That will make the clock worst than it was. I implemented an option to rdate (-t) that does not set the clock when it took more than an specified time to fetch the time from network. Please add it to the sources, it may be useful for others. Usage example: rdate -t 3500 192.168.10.20 if it took more than 3.5 seconds for fetching the time, it will not set it (instead, it will exit with an error). Thanks, Pedro -- System Information: Debian Release: 5.0 APT prefers stable APT policy: (990, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 2.6.26-1-amd64 (SMP w/2 CPU cores) Locale: LANG=pt_BR.UTF-8, LC_CTYPE=pt_BR.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash Versions of packages rdate depends on: ii libc6 2.7-18 GNU C Library: Shared libraries rdate recommends no packages. rdate suggests no packages. -- no debconf information
diff -ur rdate-1.1.3-old/docs/rdate.8 rdate-1.1.3-new/docs/rdate.8 --- rdate-1.1.3-old/docs/rdate.8 2009-04-10 15:49:34.000000000 -0300 +++ rdate-1.1.3-new/docs/rdate.8 2009-04-10 15:52:42.000000000 -0300 @@ -40,6 +40,7 @@ .Nm rdate .Op Fl 46acnpsuv .Op Fl o Ar port +.Op Fl t Ar msec .Ar host .Sh DESCRIPTION .Nm @@ -88,6 +89,10 @@ Do not print the time. .It Fl u Use UDP instead of TCP as transport. +.It Fl t Ar msec +Does not set time if it took more than +.Ar msec +mili-seconds to fetch time from network. .It Fl v Verbose output. Always show the adjustment. diff -ur rdate-1.1.3-old/src/rdate.c rdate-1.1.3-new/src/rdate.c --- rdate-1.1.3-old/src/rdate.c 2009-04-10 15:49:34.000000000 -0300 +++ rdate-1.1.3-new/src/rdate.c 2009-04-10 15:55:12.000000000 -0300 @@ -38,6 +38,7 @@ * Time is returned as the number of seconds since * midnight January 1st 1900. */ +/* option -t implemented by Pedro Zorzenon Neto - 2009-04-10 */ #ifndef lint #if 0 from: static char rcsid[] = "$NetBSD: rdate.c,v 1.3 1996/02/22 06:59:18 thorpej Exp $"; @@ -77,7 +78,7 @@ void usage(void) { - (void) fprintf(stderr, "Usage: %s [-46acnpsv] [-o port] host\n", __progname); + (void) fprintf(stderr, "Usage: %s [-46acnpsv] [-o port] [ -t msec ] host\n", __progname); (void) fprintf(stderr, " -4: use IPv4 only\n"); (void) fprintf(stderr, " -6: use IPv6 only\n"); (void) fprintf(stderr, " -a: use adjtime instead of instant change\n"); @@ -87,6 +88,7 @@ (void) fprintf(stderr, " -p: just print, don't set\n"); (void) fprintf(stderr, " -s: just set, don't print\n"); (void) fprintf(stderr, " -u: use UDP instead of TCP as transport\n"); + (void) fprintf(stderr, " -t msec: does not set clock if network delay greater than msec\n"); (void) fprintf(stderr, " -v: verbose output\n"); } @@ -102,8 +104,12 @@ int port = 0; struct timeval new, adjust; + int maxdelay = 0; + int netdelay = 0; + struct timeval netdelay1, netdelay2; + struct timezone tz; - while ((c = getopt(argc, argv, "46psancvuo:")) != -1) + while ((c = getopt(argc, argv, "46psancvuo:t:")) != -1) switch (c) { case '4': family = PF_INET; @@ -145,6 +151,10 @@ port = atoi(optarg); break; + case 't': + maxdelay = atoi(optarg); + break; + default: usage(); return 1; @@ -156,11 +166,25 @@ } hname = argv[optind]; + if (maxdelay) { + gettimeofday(&netdelay1, &tz); + } if (ntp) ntp_client(hname, family, &new, &adjust, corrleaps, port, verbose); else rfc868time_client(hname, family, &new, &adjust, corrleaps, useudp, port); + if (maxdelay) { + gettimeofday(&netdelay2, &tz); + netdelay = (netdelay2.tv_sec - netdelay1.tv_sec) * 1000; + netdelay += (netdelay2.tv_usec - netdelay1.tv_usec) / 1000; + if (netdelay > maxdelay) { + fprintf(stderr, "%s: Network delay exceeded (%i msec)\n", + __progname, netdelay); + exit(2); + } + } + if (!pr) { if (!slidetime) { logwtmp("|", "date", ""); @@ -195,6 +219,13 @@ "%s: adjust local clock by %ld seconds\n", __progname, adjust.tv_sec); } + + if (maxdelay) { + (void) fprintf(stdout, + "%s: network delay %i msecs\n", + __progname, netdelay); + } + } return 0;