Compare commits

..

7 Commits
1.20 ... 1.21

Author SHA1 Message Date
Richard Curnow
3a8f93792b Fix potential buffer overflow problem (Martin Simmons) 2006-01-19 21:37:14 +00:00
Richard Curnow
692d2799e4 More build_kit fixes 2006-01-19 21:37:14 +00:00
Richard Curnow
c928cd857b First stab at moving build_kit to release versioning based on tla 2006-01-19 21:37:14 +00:00
Richard Curnow
77da5b6144 RTC usage bails out cleanly if accessing it goes wrong (e.g. HPET without generic RTC emulation) 2006-01-19 21:37:13 +00:00
Richard Curnow
13ace061fa Further fixes to avoid use of linux kernel header files 2006-01-19 21:37:13 +00:00
Richard Curnow
29953d6ddb Remove dependence on <linux/spinlock.h>
Use local definitions for the ioctl codes needed to access the RTC.

Note : not tested.  Some architectures not handled yet.
2006-01-19 21:37:13 +00:00
Richard P. Curnow
6ff561dd23 Pick up tla version.txt 2006-01-19 21:37:13 +00:00
13 changed files with 216 additions and 52 deletions

View File

@@ -86,7 +86,7 @@ clean :
-rm -f *.o *.s chronyc chronyd core *~ -rm -f *.o *.s chronyc chronyd core *~
version.h : version.txt version.h : version.txt
sed -e 's/[$$]Name: \(.*\) [$$]/\1/;' < version.txt > version.h ./mkversion
# For install, don't use the install command, because its switches # For install, don't use the install command, because its switches

8
NEWS
View File

@@ -1,3 +1,11 @@
New in version 1.21
===================
* Don't include Linux kernel header files any longer : allows chrony to compile
on recent distros.
* Stop trying to use RTC if continuous streams of error messages would occur
(Linux with HPET).
New in version 1.20 New in version 1.20
=================== ===================

View File

@@ -2,10 +2,25 @@
# $Header: /cvs/src/chrony/build_kit,v 1.13 2003/01/12 23:50:54 richard Exp $ # $Header: /cvs/src/chrony/build_kit,v 1.13 2003/01/12 23:50:54 richard Exp $
# Perl script for building a release # Perl script for building a release
# Have to run it in the current directory
if (($0 ne "build_kit") && ($0 ne "./build_kit")) {
die "Have to be in the checked-out directory to run build_kit";
}
$here=`pwd`;
chomp $here;
$version=$here;
$version =~ s,^.*/chrony-([^/]+)$,$1, || die "Didn't recognize directory name";
print "Building kit for version $version\n";
chmod 0755, "configure"; chmod 0755, "configure";
# Overwrite normal version.h file with version-specific one
open (OUT, ">version.txt");
print OUT $version."\n";
close OUT;
# Construct chrony.spec file # Construct chrony.spec file
$version = $ARGV[0] || die "No version on command line";
open (IN, "<chrony.spec.sample"); open (IN, "<chrony.spec.sample");
open (OUT, ">chrony.spec"); open (OUT, ">chrony.spec");
while (<IN>) { while (<IN>) {
@@ -15,10 +30,16 @@ while (<IN>) {
close (IN); close (IN);
close (OUT); close (OUT);
unlink "chrony.spec.sample";
# Requires the makeinfo from texinfo v4 # Requires the makeinfo from texinfo v4
system("makeinfo --no-headers --number-sections -o chrony.txt chrony.texi"); system("makeinfo --no-headers --number-sections -o chrony.txt chrony.texi");
system ("rm -rf ./{arch}");
system ("rm -rf ./.arch-ids");
unlink "chrony.spec.sample";
unlink("build_kit"); unlink("build_kit");
unlink("LICINS");
chdir ("..");
system ("tar cvf - chrony-$version | gzip -9 > chrony-$version.tar.gz");
system ("gpg -b -a -o chrony-$version-tar-gz-asc.txt chrony-$version.tar.gz");

View File

@@ -836,7 +836,11 @@ compiled into the kernel). An estimate is made of the RTC error at a
particular RTC second, and the rate at which the RTC gains or loses time particular RTC second, and the rate at which the RTC gains or loses time
relative to true time. relative to true time.
The RTC is fully supported in 2.2 and 2.4 kernels. The RTC is fully supported in 2.2, 2.4 and 2.6 kernels.
On 2.6 kernels, if your motherboard has a HPET, you need to enable the
@samp{HPET_EMULATE_RTC} option in your kernel configuration. Otherwise, chrony
will not be able to interact with the RTC device and will give up using it.
For kernels in the 2.0 series prior to 2.0.32, the kernel was set up to For kernels in the 2.0 series prior to 2.0.32, the kernel was set up to
trim the RTC every 11 minutes. This would be disasterous for trim the RTC every 11 minutes. This would be disasterous for

66
chrony_timex.h Normal file
View File

@@ -0,0 +1,66 @@
/* Taken from /usr/include/linux/timex.h. Avoids the need to
* include kernel header files. */
#ifndef CHRONY_TIMEX_H
#define CHRONY_TIMEX_H
#include <sys/time.h>
struct timex {
unsigned int modes; /* mode selector */
long offset; /* time offset (usec) */
long freq; /* frequency offset (scaled ppm) */
long maxerror; /* maximum error (usec) */
long esterror; /* estimated error (usec) */
int status; /* clock command/status */
long constant; /* pll time constant */
long precision; /* clock precision (usec) (read only) */
long tolerance; /* clock frequency tolerance (ppm)
* (read only)
*/
struct timeval time; /* (read only) */
long tick; /* (modified) usecs between clock ticks */
long ppsfreq; /* pps frequency (scaled ppm) (ro) */
long jitter; /* pps jitter (us) (ro) */
int shift; /* interval duration (s) (shift) (ro) */
long stabil; /* pps stability (scaled ppm) (ro) */
long jitcnt; /* jitter limit exceeded (ro) */
long calcnt; /* calibration intervals (ro) */
long errcnt; /* calibration errors (ro) */
long stbcnt; /* stability limit exceeded (ro) */
int :32; int :32; int :32; int :32;
int :32; int :32; int :32; int :32;
int :32; int :32; int :32; int :32;
};
#define ADJ_FREQUENCY 0x0002 /* frequency offset */
#define ADJ_STATUS 0x0010 /* clock status */
#define ADJ_TICK 0x4000 /* tick value */
#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
#define SHIFT_USEC 16 /* frequency offset scale (shift) */
#define STA_PLL 0x0001 /* enable PLL updates (rw) */
#define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */
#define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */
#define STA_FLL 0x0008 /* select frequency-lock mode (rw) */
#define STA_INS 0x0010 /* insert leap (rw) */
#define STA_DEL 0x0020 /* delete leap (rw) */
#define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */
#define STA_FREQHOLD 0x0080 /* hold frequency (rw) */
#define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */
#define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */
#define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */
#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
/* This doesn't seem to be in any include files !! */
extern int adjtimex(struct timex *);
#endif /* CHRONY_TIMEX_H */

14
configure vendored
View File

@@ -241,17 +241,11 @@ case $SYSTEM in
EXTRA_OBJECTS="sys_linux.o wrap_adjtimex.o rtc_linux.o" EXTRA_OBJECTS="sys_linux.o wrap_adjtimex.o rtc_linux.o"
SYSDEFS="-DLINUX" SYSDEFS="-DLINUX"
echo "Configuring for " $SYSTEM echo "Configuring for " $SYSTEM
if [ -r /usr/include/linux/spinlock.h ]; then if [ "${MACHINE}" = "alpha" ]; then
SYSDEFS="$SYSDEFS -DHAS_SPINLOCK_H" echo "Enabling -mieee"
echo "The system has <spinlock.h>, using that" # FIXME: Should really test for GCC
else SYSDEFS="$SYSDEFS -mieee -DALPHA"
echo "The system does not have <spinlock.h>, using private definition for spinlock_t"
fi fi
if [ "${MACHINE}" = "alpha" ]; then
echo "Enabling -mieee"
# FIXME: Should really test for GCC
SYSDEFS="$SYSDEFS -mieee -DALPHA"
fi
;; ;;
BSD/386-i[3456]86 ) BSD/386-i[3456]86 )

View File

@@ -154,6 +154,9 @@ There have also been reports that just replacing the file
/usr/src/linux/spinlock.h by the equivalent file from a vanilla kernel source /usr/src/linux/spinlock.h by the equivalent file from a vanilla kernel source
tree is sufficient to fix the problem. tree is sufficient to fix the problem.
Note : from version 1.21 onwards, this problem no longer exists. The kernel
header files are no longer included.
S: Selection of NTP servers S: Selection of NTP servers
Q: I have several computers on a LAN. Should I make one the master, or make them all clients of an external server? Q: I have several computers on a LAN. Should I make one the master, or make them all clients of an external server?
I think the best configuration is to make one computer the master, with the I think the best configuration is to make one computer the master, with the

63
io_linux.h Normal file
View File

@@ -0,0 +1,63 @@
/* Taken from <asm-$foo/ioctl.h> in the Linux kernel sources.
* The ioctl.h file is pretty similar from one architecture to another.
* */
#ifndef IO_LINUX_H
#define IO_LINUX_H
/* Hmm. These constants vary a bit between systems. */
/* (__sh__ includes both sh and sh64) */
#if defined(__i386__) || defined(__sh__)
#define CHRONY_IOC_NRBITS 8
#define CHRONY_IOC_TYPEBITS 8
#define CHRONY_IOC_SIZEBITS 14
#define CHRONY_IOC_DIRBITS 2
#define CHRONY_IOC_NONE 0U
#define CHRONY_IOC_WRITE 1U
#define CHRONY_IOC_READ 2U
#elif defined(__alpha__) || defined(__sparc__)
#define CHRONY_IOC_NRBITS 8
#define CHRONY_IOC_TYPEBITS 8
#define CHRONY_IOC_SIZEBITS 13
#define CHRONY_IOC_DIRBITS 2
#define CHRONY_IOC_NONE 1U
#define CHRONY_IOC_READ 2U
#define CHRONY_IOC_WRITE 4U
#else
#error "I don't know the values of the _IOC_* constants for your architecture"
#endif
#define CHRONY_IOC_NRMASK ((1 << CHRONY_IOC_NRBITS)-1)
#define CHRONY_IOC_TYPEMASK ((1 << CHRONY_IOC_TYPEBITS)-1)
#define CHRONY_IOC_SIZEMASK ((1 << CHRONY_IOC_SIZEBITS)-1)
#define CHRONY_IOC_DIRMASK ((1 << CHRONY_IOC_DIRBITS)-1)
#define CHRONY_IOC_NRSHIFT 0
#define CHRONY_IOC_TYPESHIFT (CHRONY_IOC_NRSHIFT+CHRONY_IOC_NRBITS)
#define CHRONY_IOC_SIZESHIFT (CHRONY_IOC_TYPESHIFT+CHRONY_IOC_TYPEBITS)
#define CHRONY_IOC_DIRSHIFT (CHRONY_IOC_SIZESHIFT+CHRONY_IOC_SIZEBITS)
#define CHRONY_IOC(dir,type,nr,size) \
(((dir) << CHRONY_IOC_DIRSHIFT) | \
((type) << CHRONY_IOC_TYPESHIFT) | \
((nr) << CHRONY_IOC_NRSHIFT) | \
((size) << CHRONY_IOC_SIZESHIFT))
/* used to create numbers */
#define CHRONY_IO(type,nr) CHRONY_IOC(CHRONY_IOC_NONE,(type),(nr),0)
#define CHRONY_IOR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ,(type),(nr),sizeof(size))
#define CHRONY_IOW(type,nr,size) CHRONY_IOC(CHRONY_IOC_WRITE,(type),(nr),sizeof(size))
#define CHRONY_IOWR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ|CHRONY_IOC_WRITE,(type),(nr),sizeof(size))
#define RTC_UIE_ON CHRONY_IO('p', 0x03) /* Update int. enable on */
#define RTC_UIE_OFF CHRONY_IO('p', 0x04) /* ... off */
#define RTC_RD_TIME CHRONY_IOR('p', 0x09, struct rtc_time) /* Read RTC time */
#define RTC_SET_TIME CHRONY_IOW('p', 0x0a, struct rtc_time) /* Set RTC time */
/* From mc146818.h */
#define RTC_UIE 0x10 /* update-finished interrupt enable */
#endif

15
mkversion Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
rm -f version.h
echo "#ifndef VERSION_H" > version.h
echo "#define VERSION_H 1" >> version.h
if [ -f version.txt ]; then
ver=`cat version.txt`
echo "#define PROGRAM_VERSION_STRING \"$ver\"" >> version.h
else
echo "#define PROGRAM_VERSION_STRING \"DEVELOPMENT\"" >> version.h
fi
echo "#endif /* VERSION_H */" >> version.h

View File

@@ -43,32 +43,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAS_SPINLOCK_H
#include <linux/spinlock.h>
#else
/* Include dummy definition of spinlock_t to cope with earlier kernels. */
typedef int spinlock_t;
#endif
/* This is a complete hack since the alpha sys/io.h needs these types
* but does not arrange them to be defined. This is almost certainly
* not how one should do these things. -- broonie
*/
#include <linux/types.h>
#ifdef __alpha__
typedef __u8 u8;
typedef __u16 u16;
typedef __u32 u32;
typedef __u64 u64;
#endif
#if defined(__i386__) /* || defined(__sparc__) */
#include <linux/mc146818rtc.h>
#else
#include <linux/rtc.h>
#define RTC_UIE 0x10 /* update-finished interrupt enable */
#endif
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@@ -84,10 +58,23 @@ typedef __u64 u64;
#include "regress.h" #include "regress.h"
#include "rtc.h" #include "rtc.h"
#include "rtc_linux.h" #include "rtc_linux.h"
#include "io_linux.h"
#include "conf.h" #include "conf.h"
#include "memory.h" #include "memory.h"
#include "mkdirpp.h" #include "mkdirpp.h"
struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
/* ================================================== */ /* ================================================== */
/* Forward prototypes */ /* Forward prototypes */
@@ -880,9 +867,19 @@ read_from_device(void *any)
status = read(fd, &data, sizeof(data)); status = read(fd, &data, sizeof(data));
if (status < 0) { if (status < 0) {
/* This looks like a bad error : the file descriptor was indicating it was
* ready to read but we couldn't read anything. Give up. */
LOG(LOGS_ERR, LOGF_RtcLinux, "Could not read flags %s : %s", CNF_GetRtcDevice(), strerror(errno)); LOG(LOGS_ERR, LOGF_RtcLinux, "Could not read flags %s : %s", CNF_GetRtcDevice(), strerror(errno));
error = 1; error = 1;
goto turn_off_interrupt; SCH_RemoveInputFileHandler(fd);
switch_interrupts(0); /* Likely to raise error too, but just to be sure... */
close(fd);
fd = -1;
if (logfile) {
fclose(logfile);
logfile = NULL;
}
return;
} }
if ((data & RTC_UIE) == RTC_UIE) { if ((data & RTC_UIE) == RTC_UIE) {

2
util.c
View File

@@ -232,7 +232,7 @@ UTI_TimevalToString(struct timeval *tv)
stm = *gmtime((time_t *) &(tv->tv_sec)); stm = *gmtime((time_t *) &(tv->tv_sec));
strftime(buffer, sizeof(buffer), "%a %x %X", &stm); strftime(buffer, sizeof(buffer), "%a %x %X", &stm);
result = NEXT_BUFFER; result = NEXT_BUFFER;
snprintf(result, sizeof(buffer), "%s.%06ld", buffer, (unsigned long)(tv->tv_usec)); snprintf(result, BUFFER_LENGTH, "%s.%06ld", buffer, (unsigned long)(tv->tv_usec));
return result; return result;
} }

View File

@@ -1,4 +1,4 @@
#ifndef VERSION_H #ifndef VERSION_H
#define VERSION_H #define VERSION_H
#define PROGRAM_VERSION_STRING "$Name: $" #define PROGRAM_VERSION_STRING "$Name: V1_12 $"
#endif /* VERSION_H */ #endif /* VERSION_H */

View File

@@ -36,16 +36,9 @@
#define _LOOSE_KERNEL_NAMES #define _LOOSE_KERNEL_NAMES
#include <linux/time.h> #include "chrony_timex.h"
#include <linux/timex.h>
#include <asm/param.h>
#include "wrap_adjtimex.h" #include "wrap_adjtimex.h"
/* This doesn't seem to be in any include files !! */
extern int adjtimex(struct timex *);
int int
TMX_SetTick(long tick) TMX_SetTick(long tick)
{ {