INITTODR(9) | Kernel Developer's Manual | INITTODR(9)

# NAME

`inittodr` — initialize system time

# SYNOPSIS

void
`inittodr`(time_t base);

# DESCRIPTION

The `inittodr`() function determines the time and sets the system clock. It tries to pick the correct time using a set of heuristics that examine the system's battery-backed clock and the time reported by the file system, as given in base. Those heuristics include:

- If the battery-backed clock has a valid time, and is not significantly behind the time provided by base, it is used.
- If the battery-backed clock does not have a valid time, or is significantly behind the time provided in base, and the time provided in base is within reason, base is used as the current time.
- If the battery-backed clock appears invalid, and base appears non-sensical or was not provided (was given as zero), an arbitrary base (typically some time within the same year that the kernel was last updated) will be used.

Once a system time has been determined, it is stored in the time variable.

# DIAGNOSTICS

The `inittodr`() function prints diagnostic messages if it has trouble figuring out the system time. Conditions that can cause diagnostic messages to be printed include:

- There is no battery-backed clock present on the system.
- The battery-backed clock's time appears nonsensical.
- The base time appears nonsensical.
- The base time and the battery-backed clock's time differ by a large amount.

# SEE ALSO

clock_ymdhms_to_secs(9), resettodr(9), time_second(9)

# BUGS

Some systems use heuristics for picking the correct time that are slightly different.

September 6, 2006 | NetBSD 11.0