14035c910SMike Pritchard.\" $NetBSD: inittodr.9,v 1.2 1996/03/27 21:16:06 jtc Exp $ 24035c910SMike Pritchard.\" 34035c910SMike Pritchard.\" Copyright (c) 1994 Christopher G. Demetriou 44035c910SMike Pritchard.\" All rights reserved. 54035c910SMike Pritchard.\" 64035c910SMike Pritchard.\" Redistribution and use in source and binary forms, with or without 74035c910SMike Pritchard.\" modification, are permitted provided that the following conditions 84035c910SMike Pritchard.\" are met: 94035c910SMike Pritchard.\" 1. Redistributions of source code must retain the above copyright 104035c910SMike Pritchard.\" notice, this list of conditions and the following disclaimer. 114035c910SMike Pritchard.\" 2. Redistributions in binary form must reproduce the above copyright 124035c910SMike Pritchard.\" notice, this list of conditions and the following disclaimer in the 134035c910SMike Pritchard.\" documentation and/or other materials provided with the distribution. 144035c910SMike Pritchard.\" 3. All advertising materials mentioning features or use of this software 154035c910SMike Pritchard.\" must display the following acknowledgement: 164035c910SMike Pritchard.\" This product includes software developed by Christopher G. Demetriou 174035c910SMike Pritchard.\" for the NetBSD Project. 184035c910SMike Pritchard.\" 3. The name of the author may not be used to endorse or promote products 194035c910SMike Pritchard.\" derived from this software without specific prior written permission 204035c910SMike Pritchard.\" 214035c910SMike Pritchard.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 224035c910SMike Pritchard.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 234035c910SMike Pritchard.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 244035c910SMike Pritchard.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 254035c910SMike Pritchard.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 264035c910SMike Pritchard.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 274035c910SMike Pritchard.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 284035c910SMike Pritchard.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 294035c910SMike Pritchard.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 304035c910SMike Pritchard.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 314035c910SMike Pritchard.\" 324035c910SMike Pritchard.Dd March 22, 1997 334035c910SMike Pritchard.Dt INITTODR 9 343d45e180SRuslan Ermilov.Os 354035c910SMike Pritchard.Sh NAME 364035c910SMike Pritchard.Nm inittodr 374035c910SMike Pritchard.Nd initialize system time 384035c910SMike Pritchard.Sh SYNOPSIS 3932eef9aeSRuslan Ermilov.In sys/types.h 4032eef9aeSRuslan Ermilov.In sys/systm.h 414035c910SMike Pritchard.Ft void 424035c910SMike Pritchard.Fn inittodr "time_t base" 434035c910SMike Pritchard.Sh DESCRIPTION 444035c910SMike PritchardThe 454035c910SMike Pritchard.Fn inittodr 464035c910SMike Pritchardfunction determines the time and sets the system clock. 474035c910SMike PritchardIt tries to pick the correct time using a set of heuristics that examine 484035c910SMike Pritchardthe system's battery backed clock and the time obtained from the root 494035c910SMike Pritchardfile system, as given in 504035c910SMike Pritchard.Fa base . 514035c910SMike PritchardHow the 524035c910SMike Pritchard.Fa base 534035c910SMike Pritchardvalue is obtained will vary depending on the 544035c910SMike Pritchardroot file system type. 554035c910SMike PritchardThe heuristics used include: 564035c910SMike Pritchard.Bl -bullet 574035c910SMike Pritchard.It 584035c910SMike PritchardIf the battery-backed clock has a valid time, it is used. 594035c910SMike Pritchard.\" .It 604035c910SMike Pritchard.\" If the battery-backed clock does not have a valid time, and 614035c910SMike Pritchard.\" the time provided in 624035c910SMike Pritchard.\" .Fa base 634035c910SMike Pritchard.\" is within reason, 644035c910SMike Pritchard.\" .Fa base 654035c910SMike Pritchard.\" is used as the current time. 664035c910SMike Pritchard.\" .It 674035c910SMike Pritchard.\" If the battery-backed clock appears invalid, and 684035c910SMike Pritchard.\" .Fa base 694035c910SMike Pritchard.\" appears non-sensical or was not provided (was given as zero), 704035c910SMike Pritchard.\" a arbitrary base (typically some time in the late 1970s) 714035c910SMike Pritchard.\" will be used. 724035c910SMike Pritchard.It 734035c910SMike PritchardIf the battery-backed clock does not have a valid time, 744035c910SMike Pritchardthe time provided in 754035c910SMike Pritchard.Fa base 764035c910SMike Pritchardwill be used. 774035c910SMike Pritchard.El 784035c910SMike Pritchard.Pp 794035c910SMike PritchardOnce a system time has been determined, it is stored in the 804035c910SMike Pritchard.Va time 814035c910SMike Pritchardvariable. 824035c910SMike Pritchard.Sh DIAGNOSTICS 834035c910SMike PritchardThe 844035c910SMike Pritchard.Fn inittodr 854035c910SMike Pritchardfunction prints diagnostic messages if it has trouble figuring 86559eb8d2SHiten Pandyaout the system time. 87559eb8d2SHiten PandyaConditions that can cause diagnostic messages to be printed include: 884035c910SMike Pritchard.Bl -bullet 894035c910SMike Pritchard.It 904035c910SMike PritchardThe battery-backed clock's time appears nonsensical. 914035c910SMike Pritchard.\" .It 924035c910SMike Pritchard.\" The 934035c910SMike Pritchard.\" .Fa base 944035c910SMike Pritchard.\" time appears nonsensical. 954035c910SMike Pritchard.\" .It 964035c910SMike Pritchard.\" The 974035c910SMike Pritchard.\" .Fa base 984035c910SMike Pritchard.\" time and the battery-backed clock's time differ by a large amount. 994035c910SMike Pritchard.El 1004035c910SMike Pritchard.Sh SEE ALSO 1014035c910SMike Pritchard.Xr resettodr 9 , 1024035c910SMike Pritchard.Xr time 9 1034035c910SMike Pritchard.Sh BUGS 1044035c910SMike PritchardOn many systems, 1054035c910SMike Pritchard.Fn inittodr 1064035c910SMike Pritchardhas to convert from 1074035c910SMike Pritcharda time expressed in terms of year, month, day, hours, minutes, 1084035c910SMike Pritchardand seconds to 1094035c910SMike Pritchard.Va time , 110559eb8d2SHiten Pandyaexpressed in seconds. 111559eb8d2SHiten PandyaMany of the implementations could share code, but do not. 1124035c910SMike Pritchard.Pp 1134035c910SMike PritchardEach system's heuristics for picking the correct time are slightly 1144035c910SMike Pritcharddifferent. 1154035c910SMike Pritchard.Pp 1164035c910SMike PritchardThe 117b5c508fbSRuslan Ermilov.Fx 1184035c910SMike Pritchardimplementation should do a better job of validating the time provided in 1194035c910SMike Pritchard.Fa base 120559eb8d2SHiten Pandyawhen the battery-backed clock is unusable. 121559eb8d2SHiten PandyaCurrently it unconditionally sets the system clock to this value. 122