正體中文 | 简体中文 | English

:::

vsntp

Description

vsntp is an SNTP client daemon for machines without a sane system time. The word vsntp stands for SNTP for Virtual PC. It was originally designed for my GNU/Linux server running on Connectix Virtual PC. It runs according to RFC 1769 SNTP, connecting the NTP server on UDP port 123.

Without Virtual PC Additions, the system time on Virtual PC is completely insane. It’s RTC (Real Time Clock, or CMOS time, or hardware clock) is software emulated, which does not seems to be running. The GNU/Linux kernel hardly maintains a system time itself. With smooth run it goes 4 seconds ahead per minute, which is nearly 1.5 hours per day. That is insane. You can even tell it with your eyes.

David L. Mills’ ntp does not work here. It uses a method that learns the clock frequency drift first, and adjust the kerenl clock with adjtimex() so that time adjustment goes smoothly, from the point of view of system and applications. This assumes an existing fix-speed system clock. But this is not the case of Virtual PC. The system clock on Virtual PC is software emulated. It can be faster or slower now and then, depending on the load of the hosting machine. There is no fixed clock speed. The frequency drift does not exist, then. It dooms to fail to measure it.

There is an sntp client that comes with David L. Mills’ ntp package. It is suggested to be run from crontab. But crontab runs by minutes, and Virtual PC goes 4 seconds ahead per minute. Rolling back 4 seconds every minute is insane for most applications. It also increases system load heavily to run one instance per minute.

vsntp is a workaround on this. It runs as a daemon to eliminates the additional system load on every synchronization. It uses settimeofday() to synchronize the time. It synchronizes the time with an arbitrary interval, so that time can be accurate within a second.

There are some defects. Synchronizing the time too often introduces heavy network load. It introduces heavy load on the target NTP server, too. You should have a working NTP server nearby that is owned by you. Also, since settimeofday() is called so often, high-accurate time operations like timer, etc., may not run correctly.

vsntp uses sleep() as the synchronization scheduler. Reports show that on some systems sleep() may not function normally. If you find vsntp stops synchronization after running for some time, that the sleep() is not functioning normally on your system, you may want to switch to the alarm() scheduler with the -a switch.

If you ever encounter any problem, you may check your syslog. vsntp logs detailed debugging information to syslog in log level LOG_DEBUG with facility LOG_DAEMON. You may turn it on in your /etc/syslog.conf with the following line:

daemon.debug  /var/log/debug

and check the /var/log/debug file for the debugging message. Remember to remove this afterwards, for the amount of the debugging messages may be huge and may use up your harddisk in a very short time. To the least it may slow down your system for frequent harddisk I/O.

vsntp was originally written for GNU/Linux. It uses POSIX compatible system calls. It should work on any POSIX compatible system. But I have yet only tested it on Cygwin. Cygwin is known to work. I don’t have others to test and run on. Please let me know (and submit the patch if needed) if you can port it to other systems.

Please tell me if you have successfully running vsntp on other virtual machines, like VMWare.

Generally, please tell me if you are using vsntp. I would like to know that I am really doing some good for the world, *^_^* but not having fun myself. :p

This is my first daemon, my first socket program and my first public-released C program. Any comment or suggestion is welcome. ^_*'

Running and Stopping

You need to be root to run vsntp. vsntp uses settimeofday() to set the system time. settimeofday() requires root privilege.

To start vsntp, just specify your NTP server:

# vsntp my.ntp.server.com

vsntp writes its PID in /var/run/vsntp.pid. To stop vsntp, kill it by its PID:

# kill `cat /var/run/vsntp.pid`

The PID file location can be changed with the -p switch.

Options

vsntp [-i n] [-p file] [-s|-a] server
vsntp [-h|-v]
server
The NTP server to synchronize with.
-i,--interval n
Set the synchronization interval to n seconds. Default is 900 seconds (15 minutes).
-p,--pidfile file
The PID file location. Default to /var/run/vsntp.pid.
-s, --sleep
Use sleep() to schedule synchronization. This is currently the default.
-a, --alarm
Use alarm() to schedule synchronization.
-h, --help
Display the help message and exit.
-v, --version
Output version information and exit.
By imacat, first version 2004-01-14, last updated 2009-04-19