Browse Source

Fixes in ntpd_settime (ie ntpd -s):

- Handle errors from syscalls better
- Prevent curtime.tv_usec from being negative for negative offsets.
- Don't claim to have done settimeofday if it fails.
ok henning@
OPENBSD_3_7
dtucker 19 years ago
parent
commit
0a9920c236
1 changed files with 11 additions and 9 deletions
  1. +11
    -9
      src/usr.sbin/ntpd/ntpd.c

+ 11
- 9
src/usr.sbin/ntpd/ntpd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.c,v 1.31 2005/03/09 20:31:11 henning Exp $ */
/* $OpenBSD: ntpd.c,v 1.32 2005/03/13 10:06:27 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -332,17 +332,19 @@ ntpd_settime(double d)
if (d < SETTIME_MIN_OFFSET && d > -SETTIME_MIN_OFFSET)
return;
d_to_tv(d, &tv);
if (gettimeofday(&curtime, NULL) == -1)
if (gettimeofday(&curtime, NULL) == -1) {
log_warn("gettimeofday");
curtime.tv_sec += tv.tv_sec;
curtime.tv_usec += tv.tv_usec;
if (curtime.tv_usec > 1000000) {
curtime.tv_sec++;
curtime.tv_usec -= 1000000;
return;
}
if (settimeofday(&curtime, NULL) == -1)
d_to_tv(d, &tv);
curtime.tv_usec += tv.tv_usec + 1000000;
curtime.tv_sec += tv.tv_sec - 1 + (curtime.tv_usec / 1000000);
curtime.tv_usec %= 1000000;
if (settimeofday(&curtime, NULL) == -1) {
log_warn("settimeofday");
return;
}
tval = curtime.tv_sec;
strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y",
localtime(&tval));


Loading…
Cancel
Save