diff options
author | Darren Tucker <dtucker@cvs.openbsd.org> | 2005-03-13 10:06:28 +0000 |
---|---|---|
committer | Darren Tucker <dtucker@cvs.openbsd.org> | 2005-03-13 10:06:28 +0000 |
commit | 63a11a104455a315f1585089c9a4afe760b142c4 (patch) | |
tree | f59c87eb691196b48767786d5fdc8ed1c7cc2265 /usr.sbin | |
parent | edb2753a3529fd780991f576bb43e40999cf4bdd (diff) |
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@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ntpd/ntpd.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c index 02f63b067bb..2498d06279f 100644 --- a/usr.sbin/ntpd/ntpd.c +++ b/usr.sbin/ntpd/ntpd.c @@ -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)); |