Hi!
As NTP packets can be blocked by a wrong network configuration (or not
working well within qemu "user" network emulation), having to wait 30
seconds until rdate failure can sometime be a little frustrating.
These two patchs allow NTP synchronisation to be canceled in the
installer.
The first patch is against rdate, and adds, when -vv is specified on the
command-line, the output of single dot (".") for each NTP query sent.
The second patch modifies clock-setup to use these dots in order to
step the progress bar on each of these dots. In case of a cancelation,
rdate is killed on SIGPIPE due to the standard output closure.
It looked as the easiest way to make NTP synchronisation cancelable, but
I might be wrong. :) Comments happily welcome. :)
Cheers,
--
Jérémy Bobbio .''`.
lunar@debian.org : :Ⓐ : # apt-get install anarchism
`. `'`
`-
diff -u rdate-1.1.3/src/rdate.c rdate-1.1.3/src/rdate.c
--- rdate-1.1.3/src/rdate.c
+++ rdate-1.1.3/src/rdate.c
@@ -70,7 +70,7 @@
#endif
void rfc868time_client (const char *, int, struct timeval *, struct timeval *, int, int, int);
-void ntp_client (const char *, int, struct timeval *, struct timeval *, int, int);
+void ntp_client (const char *, int, struct timeval *, struct timeval *, int, int, int);
extern char *__progname;
@@ -157,7 +157,7 @@
hname = argv[optind];
if (ntp)
- ntp_client(hname, family, &new, &adjust, corrleaps, port);
+ ntp_client(hname, family, &new, &adjust, corrleaps, port, verbose);
else
rfc868time_client(hname, family, &new, &adjust, corrleaps, useudp, port);
diff -u rdate-1.1.3/src/ntp.c rdate-1.1.3/src/ntp.c
--- rdate-1.1.3/src/ntp.c
+++ rdate-1.1.3/src/ntp.c
@@ -110,8 +110,8 @@
u_int64_t xmitck;
};
-void ntp_client(const char *, int, struct timeval *, struct timeval *, int, int);
-int sync_ntp(int, const struct sockaddr *, double *, double *);
+void ntp_client(const char *, int, struct timeval *, struct timeval *, int, int, int);
+int sync_ntp(int, const struct sockaddr *, double *, double *, int);
int write_packet(int, struct ntp_data *);
int read_packet(int, struct ntp_data *, double *, double *);
void unpack_ntp(struct ntp_data *, u_char *);
@@ -126,7 +126,7 @@
void
ntp_client(const char *hostname, int family, struct timeval *new,
- struct timeval *adjust, int leapflag, int port)
+ struct timeval *adjust, int leapflag, int port, int verbose)
{
struct addrinfo hints, *res0, *res;
double offset, error;
@@ -155,7 +155,7 @@
((struct sockaddr_in*)res->ai_addr)->sin_port = htons(port);
}
- ret = sync_ntp(s, res->ai_addr, &offset, &error);
+ ret = sync_ntp(s, res->ai_addr, &offset, &error, verbose);
if (ret < 0) {
#ifdef DEBUG
fprintf(stderr, "try the next address\n");
@@ -181,7 +181,8 @@
}
int
-sync_ntp(int fd, const struct sockaddr *peer, double *offset, double *error)
+sync_ntp(int fd, const struct sockaddr *peer, double *offset, double *error,
+ int verbose)
{
int attempts = 0, accepts = 0, rejects = 0;
int delay = MAX_DELAY, ret;
@@ -200,6 +201,10 @@
}
while (accepts < MAX_QUERIES && attempts < 2 * MAX_QUERIES) {
+ if (verbose >= 2) {
+ fprintf(stderr, ".\n");
+ fflush(stderr);
+ }
memset(&data, 0, sizeof(data));
if (current_time(JAN_1970) > deadline) {
diff -u rdate-1.1.3/debian/changelog rdate-1.1.3/debian/changelog
--- rdate-1.1.3/debian/changelog
+++ rdate-1.1.3/debian/changelog
@@ -1,3 +1,11 @@
+rdate (1:1.1.3-2~~lunar1) UNRELEASED; urgency=low
+
+ * When "-vv" is specified, rdate now displays a dot each time it tries
+ to send a packet to the NTP server. This is needed to implement
+ cancelation of time synchronisation in the debian-installer.
+
+ -- Jérémy Bobbio <lunar@debian.org> Wed, 12 Mar 2008 08:04:06 +0100
+
rdate (1:1.1.3-1) unstable; urgency=low
* New upstream release
commit e7bc9afdc85c2080a2f5fd3ecccdedae01a47649
Author: Jérémy Bobbio <lunar@debian.org>
Date: Wed Mar 12 08:20:58 2008 +0100
Add the ability to cancel NTP synchronisation
diff --git a/packages/clock-setup/debian/changelog b/packages/clock-setup/debian/changelog
index 6d07620..ae78467 100644
--- a/packages/clock-setup/debian/changelog
+++ b/packages/clock-setup/debian/changelog
@@ -1,8 +1,13 @@
clock-setup (0.96) UNRELEASED; urgency=low
+ [ Frans Pop ]
* Remove Petter Reinholdtsen and Christian Perrier as Uploaders with many
thanks for their past contributions.
+ [ Jérémy Bobbio ]
+ * Add the ability to cancel NTP synchronisation.
+ This needs rdate-udeb (>> 1.1.3-1).
+
-- Frans Pop <fjp@debian.org> Tue, 08 Apr 2008 13:25:35 +0200
clock-setup (0.95) unstable; urgency=low
diff --git a/packages/clock-setup/debian/clock-setup.postinst b/packages/clock-setup/debian/clock-setup.postinst
index 2ead470..6e33a52 100755
--- a/packages/clock-setup/debian/clock-setup.postinst
+++ b/packages/clock-setup/debian/clock-setup.postinst
@@ -26,15 +26,27 @@ if [ "$RET" = true ]; then
db_get clock-setup/ntp-server
server="$RET"
- db_progress START 0 1 clock-setup/progress/title
+ db_capb progresscancel
+ db_progress START 0 30 clock-setup/progress/title
db_progress INFO clock-setup/progress/ntp
- if ! RDATE_OUT=`log-output -t clock-setup --pass-stdout rdate -o 123 -nv "$server"`; then
- log "rdate failed ($?)"
- fi
- log "$RDATE_OUT"
+ i=0
+ exec 4>&0
+ rdate -o 123 -nvv "$server" 2>&1 |
+ while read line; do
+ if [ "$line" = . ]; then
+ if ! db_progress STEP 1 <&4; then
+ log "rdate canceled."
+ break
+ fi
+ i=$(($i + 1))
+ else
+ log "$line"
+ fi
+ done
+ exec 0>&4
# This is commented out as it can cause a hang as described in
# #436497.
- #db_progress step 1
+ #db_progress step $((30 - $i))
db_progress stop
fi
diff --git a/packages/clock-setup/debian/control b/packages/clock-setup/debian/control
index 9256649..15b55d7 100644
--- a/packages/clock-setup/debian/control
+++ b/packages/clock-setup/debian/control
@@ -8,7 +8,7 @@ Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/clock-setup
Package: clock-setup
Architecture: alpha amd64 arm armel armeb hppa i386 ia64 m68k mips mipsel powerpc ppc64 sparc kfreebsd-i386 kfreebsd-amd64
-Depends: ${misc:Depends}, localechooser, tzsetup-udeb (>= 1:0.18), configured-network, rdate-udeb (>= 1:1.1.2-5), di-utils
+Depends: ${misc:Depends}, localechooser, tzsetup-udeb (>= 1:0.18), configured-network, rdate-udeb (>> 1.1.3-1), di-utils
XC-Package-Type: udeb
XB-Installer-Menu-Item: 2600
Description: set up clock
Attachment:
signature.asc
Description: Digital signature