Skip to content

Commit

Permalink
Original copy of htpdate 1.0.5 from http://www.vervest.org/fiki/bin/v…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong Shen committed Apr 25, 2013
0 parents commit 1209e7d
Show file tree
Hide file tree
Showing 19 changed files with 1,550 additions and 0 deletions.
257 changes: 257 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
Changes in 1.0.5
----------------

- Change of e-mail/website
- Fix for debian build


1.0.4
-----
- Fixed a memory leak (reported and fixed by Andreas Bohne-Lang)


1.0.3
-----

- Fixed logic error... 1.0.2 is broken :(


1.0.2
-----

- Fixed a buffer overflow when time offset gets to large
https://dev.openwrt.org/cgi-bin/trac.fcgi/ticket/3940


1.0.1
-----

- Added "burst mode" (-b) to enhance accuracy.
- Extended debug output
- Removed potential buffer overflows vulnerabilities.
- Replaced usleep by nanosleep (which is more portable).
- Included debian package.


1.0.0
-----

- Cleanup/simplified the code.
- Again a more robust implementation of the "-p" (precision) switch.


0.9.3
-----

- Bug fixes: poll loop could be become close to zero in case of a "connection
failed". Sleeptime wasn't correct in case all hosts fail.
- Use more "sane" minsleep and maxsleep values.


0.9.2
-----

- The use of the ntp_adjtime system call is now optional. The clock
frequency will be adjusted when using the "-x" switch and the systematic
drift will be compensated. Works only in daemon mode.


0.9.1
-----

- Htpdate can drop root privileges and run as a restricted user.
- Drift calculation starts now after first time correction.


0.9.0
-----

- Mostly code cleanup
- Changed "char" variables into "int", which should be more efficient
- Changed the qsort routine, into an insertion sort. Quicksort is
kind of overkill for such small lists.
- Debug mode is allowed in daemon mode.


0.8.8
-----

- Speeded up the poll cycle loop, once a time offset has been detected.
- Added systematic drift to the syslog logging (daemon only).
The "adjtimex_parameters.sh" script may help to reduce the drift of your
system clock.
- Changed "precision" from micro into milliseconds.
- Changed manpage directory from /usr/man into /usr/share/man.
- HTTP/1.1 has become the default


0.8.7
-----

- Bug fix: with precision set, the time could only be adjusted
negative (slow down).
- Fixed undesired effects in (rare) cases when using only a few servers.
- Exit code changed to 1 if no server was found (requested by Supernaut).


0.8.6
-----

- Reintroduction of the "-p" switch. The "precision" determines more accurate
when a time adjustment is needed. The implementation of precision is much
beter than the one in the past.


0.8.5
-----

- Changed the variable type of "param" from char into int (thanks to
Arnaud Mazin). GCC 3.4.x is less forgiving than older versions.
- Made compare function for qsort more robust (avoiding overflow).


0.8.4
-----

- Finaly added IPv6 support!
- If you would lose internet connectivity, htpdate would flood the system
(CPU and log). A patch submitted by Peter Surda, has been included.
- Removed -0 switch (HTTP/1.0), since this is the default anyway.


0.8.3
-----

- Fixed that "when" wasn't properly initialized in every poll cycle. This
bug fix reduces jitter when system time is close to the correct time.
- Added missing "-t" switch to the manpage.
- Added warning message if more than 16 servers are specified.
- Htpdate double forks now, like a proper daemon :)
- vim setting are added to the source (set ts=4)


0.8.2
-----

- Fixed a major bug in offset calculation (caused by changing the rtt type
from double to unsigned long)


0.8.1 (broken)
--------------

- Correction install paths in Makefile, added uninstall option
- Added "-t" switch, which disables time sanity checking (requested for
devices, like supported by openwrt, which boot/startup at "epoch" time)


0.8.0
-----

- Lots of code clean up, eg.:
- compiles with the -ansi switch (for better portability, but only
tested on Linux and FreeBSD)
- Compiles with Tiny C Compiler (tcc) and Intel C compiler (icc)
- Restored compatibility with FreeBSD (timezone calculation).
- A second poll is made if a time offset has been detected.
- Removed the switches "-t" and "-x". In daemon mode htpdate will only adjust
time. With the "-s" switch htpdate will set the time once at startup and
after that only smooth adjusts are made.
- Added "-l" switch, which enables logging to syslog in non-daemon mode.
Convinient if htpdate is used from cron.
- Added "-0" to make an HTTP/1.0 request and "-1" for HTTP/1.1


0.7.2
-----

- Minor bug fix. When running in daemon mode TCP connections weren't cleaned up
properly (sockets remained in CLOSE_WAIT status).


0.7.1
-----

- Bug fix. Poll cycle could become very very short (seconds...) in some
cases.


0.7.0
-----

- The polling mechanisme has been improved once more :)
As of this version polls are also spread within the polling cycle.
This way a time offset will be detected earlier, without increasing the
polling frequency.
- Sleeptime isn't writen to syslog anymore, only time adjustments
- Previous versions of htpdate tried to close a already closed HTTP/1.0
session.
- The rpm version doesn't override the init-script anymore


0.6.2
-----

- Bug fix, time wasn't correct if 'timeavg' was negative...


0.6.1
-----

- Code clean up, use global variable 'timezone'


0.6
---

- New poll schedule mechanisme has been introduced!
This results in a better spreading of the polls in time to
gain some extra accuracy.
- Removed the -p (precision) flag, because it has become obsolete with
the new poll scheduling mechanisme.
- Extended 'debug mode' output with round trip time (rtt) information.
- Sleeptime parameters are no longer in seconds, but in 2^n seconds.


0.5
---

- Added relevant header files, so gcc -Wall compiles without warnings.
- Added -p switch, to set the precision of htpdate. The polling rate
is affected by this switch (high precision -> more frequent polling).


0.4
---

- Spread the individual time polls better, to gain accuracy with
a small number of web servers as source
- Added debug mode, so you can value the quality of the timestamps
from web servers
- Minor correction on HEAD request (removed max-age=0)
- pid file is created
- Added htpdate init script


0.3
---

- Run htpdate as a daemon
- automatic set/adjust time, based upon offset
- automatic poll interval
- Added manpage
- Added RPM
- Minor bug fixes


0.2
---

- Htpdate can set or adjust time smoothly now, without calling external
programs


0.1
---

- Initial release. Htpdate extracts the raw timestamp from a webserver.
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
prefix = $(DESTDIR)/usr
bindir = ${prefix}/bin
mandir = ${prefix}/share/man

CC = gcc
CFLAGS += -Wall -O2
#CFLAGS += -Wall -pedantic -ansi -O2

INSTALL = /usr/bin/install -c
STRIP = /usr/bin/strip -s

all: htpdate

htpdate: htpdate.c
$(CC) $(CFLAGS) $(LDFLAGS) -o htpdate htpdate.c

install: all
$(STRIP) htpdate
mkdir -p $(bindir)
$(INSTALL) -m 755 htpdate $(bindir)/htpdate
mkdir -p $(mandir)/man8
$(INSTALL) -m 644 htpdate.8.gz $(mandir)/man8/htpdate.8.gz

clean:
rm -rf htpdate

uninstall:
rm -rf $(bindir)/htpdate
rm -rf $(mandir)/man8/htpdate.8.gz
68 changes: 68 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Htpdate
-------

The HTTP Time Protocol (HTP) is used to synchronize a computer's time
with web servers as reference time source. Htpdate will synchronize your
computer's time by extracting timestamps from HTTP headers found
in web server responses. Htpdate can be used as a daemon, to keep your
computer synchronized.
The accuracy of htpdate is at least -+0.5 seconds (better with multiple
servers). If this is not good enough for you, try the ntpd package.

Install the htpdate package if you need tools for keeping your system's
time synchronized via the HTP protocol. Htpdate works also through
proxy servers.


Installation from source
------------------------

Tested on Linux and FreeBSD only, but should work for most Unix flavors.

$ tar zxvf htpdate-x.y.z.tar.gz
or
$ tar jxvf htpdate-x.y.z.tar.bz2
$ cd htpdate-X.Y.Z
$ make
$ make install

An example init script (scripts/htpdate.init) for use in /etc/init.d/
is included, but not installed automatically. This scripts with run
htpdate as a daemon.

Another option is to use htpdate in a cronjob and start it periodically
from cron. For a daily time sync it would look something like this:
5 3 * * * /usr/bin/htpdate -s www.linux.org www.freebsd.org


Installation from RPM
---------------------

The easiest way to install (Redhat, SuSE, Mandriva etc..)

$ rpm -Uvh htpdate-x.y.z.i386.rpm

By default the htpdate daemon is activated (with chkconfig).
If you only want to run htpdate from cron, disable the htpdate service
with 'chkconfig --del htpdate'.


Usage
-----

Usage: htpdate [-046abdhlqstxD] [-i pid file] [-m minpoll] [-M maxpoll]
[-p precision] [-P <proxyserver>[:port]] [-u user[:group]]
<host[:port]> ...

E.g. htpdate -q www.linux.org www.freebsd.org


In general, if more web servers are specified, the accuracy will increase.

See manpage for more details.


To do
-----

- I'm open for suggestions :)
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
htpdate (1.0.4) stable; urgency=low

* Fixed a memory leak

-- Eddy Vervest <[email protected]> Mon, 13 Oct 2008 20:20:45 +0200
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
13 changes: 13 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Source: htpdate
Section: net
Priority: extra
Maintainer: Eddy Vervest <[email protected]>
Build-Depends: debhelper (>= 5)
Standards-Version: 3.7.2

Package: htpdate
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: HTTP based time synchronization tool
The HTTP Time Protocol (HTP) is used to synchronize a computer's time with web servers as reference time source. Htpdate will synchronize your computer's time by extracting timestamps from HTTP headers found in web servers responses. Htpdate can be used as a daemon, to keep your computer synchronized. Accuracy of htpdate is usually better than 0.5 seconds (even better with multiple servers). If this is not good enough for you, try the ntpd package.
Install the htp package if you need tools for keeping your system's time synchronized via the HTP protocol. Htpdate works also through proxy servers.
Loading

0 comments on commit 1209e7d

Please sign in to comment.