1.\" $NetBSD: inittodr.9,v 1.2 1996/03/27 21:16:06 jtc Exp $ 2.\" 3.\" Copyright (c) 1994 Christopher G. Demetriou 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by Christopher G. Demetriou 17.\" for the NetBSD Project. 18.\" 3. The name of the author may not be used to endorse or promote products 19.\" derived from this software without specific prior written permission 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd March 22, 1997 33.Dt INITTODR 9 34.Os FreeBSD 35.Sh NAME 36.Nm inittodr 37.Nd initialize system time 38.Sh SYNOPSIS 39.Ft void 40.Fn inittodr "time_t base" 41.Sh DESCRIPTION 42The 43.Fn inittodr 44function determines the time and sets the system clock. 45It tries to pick the correct time using a set of heuristics that examine 46the system's battery backed clock and the time obtained from the root 47file system, as given in 48.Fa base . 49How the 50.Fa base 51value is obtained will vary depending on the 52root file system type. 53The heuristics used include: 54.Bl -bullet 55.It 56If the battery-backed clock has a valid time, it is used. 57.\" .It 58.\" If the battery-backed clock does not have a valid time, and 59.\" the time provided in 60.\" .Fa base 61.\" is within reason, 62.\" .Fa base 63.\" is used as the current time. 64.\" .It 65.\" If the battery-backed clock appears invalid, and 66.\" .Fa base 67.\" appears non-sensical or was not provided (was given as zero), 68.\" a arbitrary base (typically some time in the late 1970s) 69.\" will be used. 70.It 71If the battery-backed clock does not have a valid time, 72the time provided in 73.Fa base 74will be used. 75.El 76.Pp 77Once a system time has been determined, it is stored in the 78.Va time 79variable. 80.Sh DIAGNOSTICS 81The 82.Fn inittodr 83function prints diagnostic messages if it has trouble figuring 84out the system time. Conditions that can cause diagnostic 85messages to be printed include: 86.Bl -bullet 87.It 88The battery-backed clock's time appears nonsensical. 89.\" .It 90.\" The 91.\" .Fa base 92.\" time appears nonsensical. 93.\" .It 94.\" The 95.\" .Fa base 96.\" time and the battery-backed clock's time differ by a large amount. 97.El 98.Sh SEE ALSO 99.Xr resettodr 9 , 100.Xr time 9 101.Sh BUGS 102On many systems, 103.Fn inittodr 104has to convert from 105a time expressed in terms of year, month, day, hours, minutes, 106and seconds to 107.Va time , 108expressed in seconds. Many of the implementations could share code, 109but do not. 110.Pp 111Each system's heuristics for picking the correct time are slightly 112different. 113.Pp 114The 115.Tn FreeBSD 116implementation should do a better job of validating the time provided in 117.Fa base 118when the battery-backed clock is unusable. Currently it unconditionally 119sets the system clock to this value. 120