aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_ntptime.c
diff options
context:
space:
mode:
authorMark Santcroos <marks@FreeBSD.org>2004-11-18 23:44:49 +0000
committerMark Santcroos <marks@FreeBSD.org>2004-11-18 23:44:49 +0000
commit932cfd418cf35b6650ce43fa72971b1b0296984b (patch)
tree726d77a8ca6547d9aa88d0c9e0a615ae4b38e174 /sys/kern/kern_ntptime.c
parent1317240bac0eb3027acb0122eca8308f6a95f45f (diff)
downloadsrc-932cfd418cf35b6650ce43fa72971b1b0296984b.tar.gz
src-932cfd418cf35b6650ce43fa72971b1b0296984b.zip
Add system call implementation of ntp_gettime(2).
Moved most of the work to ntp_gettime1(), which is now called by ntp_gettime() and ntp_sysctl(). Reviewed by: imp, phk, njl, peter Approved by: njl
Notes
Notes: svn path=/head/; revision=137873
Diffstat (limited to 'sys/kern/kern_ntptime.c')
-rw-r--r--sys/kern/kern_ntptime.c61
1 files changed, 43 insertions, 18 deletions
diff --git a/sys/kern/kern_ntptime.c b/sys/kern/kern_ntptime.c
index 964e5244adfa..0d8d54ab2e5d 100644
--- a/sys/kern/kern_ntptime.c
+++ b/sys/kern/kern_ntptime.c
@@ -194,27 +194,20 @@ static long pps_errcnt; /* calibration errors */
static void ntp_init(void);
static void hardupdate(long offset);
+static void ntp_gettime1(struct ntptimeval *ntvp);
-/*
- * ntp_gettime() - NTP user application interface
- *
- * See the timex.h header file for synopsis and API description. Note
- * that the TAI offset is returned in the ntvtimeval.tai structure
- * member.
- */
-static int
-ntp_sysctl(SYSCTL_HANDLER_ARGS)
+static void
+ntp_gettime1(struct ntptimeval *ntvp)
{
- struct ntptimeval ntv; /* temporary structure */
struct timespec atv; /* nanosecond time */
nanotime(&atv);
- ntv.time.tv_sec = atv.tv_sec;
- ntv.time.tv_nsec = atv.tv_nsec;
- ntv.maxerror = time_maxerror;
- ntv.esterror = time_esterror;
- ntv.tai = time_tai;
- ntv.time_state = time_state;
+ ntvp->time.tv_sec = atv.tv_sec;
+ ntvp->time.tv_nsec = atv.tv_nsec;
+ ntvp->maxerror = time_maxerror;
+ ntvp->esterror = time_esterror;
+ ntvp->tai = time_tai;
+ ntvp->time_state = time_state;
/*
* Status word error decode. If any of these conditions occur,
@@ -245,8 +238,40 @@ ntp_sysctl(SYSCTL_HANDLER_ARGS)
*/
(time_status & STA_PPSFREQ &&
time_status & (STA_PPSWANDER | STA_PPSERROR)))
- ntv.time_state = TIME_ERROR;
- return (sysctl_handle_opaque(oidp, &ntv, sizeof ntv, req));
+ ntvp->time_state = TIME_ERROR;
+}
+
+#ifndef _SYS_SYSPROTO_H_
+struct ntp_gettime_args {
+ struct ntptimeval *ntvp;
+};
+#endif
+/* ARGSUSED */
+int
+ntp_gettime(struct thread *td, struct ntp_gettime_args *uap)
+{
+ struct ntptimeval ntv;
+
+ ntp_gettime1(&ntv);
+
+ return (copyout(&ntv, uap->ntvp, sizeof(ntv)));
+}
+
+/*
+ * ntp_gettime() - NTP user application interface
+ *
+ * See the timex.h header file for synopsis and API description. Note
+ * that the TAI offset is returned in the ntvtimeval.tai structure
+ * member.
+ */
+static int
+ntp_sysctl(SYSCTL_HANDLER_ARGS)
+{
+ struct ntptimeval ntv; /* temporary structure */
+
+ ntp_gettime1(&ntv);
+
+ return (sysctl_handle_opaque(oidp, &ntv, sizeof(ntv), req));
}
SYSCTL_NODE(_kern, OID_AUTO, ntp_pll, CTLFLAG_RW, 0, "");