INITTODR(9)

πŸ’– INITTODR(9) β€” the "what time even is it" page, from the Kernel Developer's Manual ✨

okay bestie, so this one's called inittodr and it's literally about setting the system clock at boot. like, the kernel wakes up and has NO idea what time it is, which is so relatable honestly. and this function is the one that fixes that. πŸ•°οΈβœ¨


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <sys/types.h>
#include <sys/systm.h>

void
inittodr(time_t base);

🌸 DESCRIPTION 🌸

so inittodr() is the function that figures out the time and sets the system clock. periodt. πŸ’…

it tries to pick the correct time using a whole little toolkit of heuristics, and those heuristics go look at two things: the system's battery-backed clock and the time it got from the root file system, which shows up as the base argument. and ngl, how that base value actually gets obtained depends on what type of root file system you're dealing with β€” so it varies, no cap. 🫢

the heuristics it uses are:

  • if the battery-backed clock has a valid time, that time gets used. easy. iconic. ✨
  • if the battery-backed clock does not have a valid time, then the time provided in base is what gets used instead. πŸ’«

and once a system time has been determined, it gets stored in the time variable. and that's the whole vibe. πŸŽ€


πŸ”₯ DIAGNOSTICS πŸ”₯

inittodr() will print diagnostic messages if it's having trouble figuring out the system time β€” like, it's struggling and it wants you to know. 😭

conditions that can cause diagnostic messages to be printed include:

  • the battery-backed clock's time appears nonsensical πŸ’€

πŸŽ€ SEE ALSO πŸŽ€


πŸ’€ BUGS πŸ’€

okay so here's where we get honest, bestie:

  • on many systems, inittodr() has to convert from a time expressed in terms of year, month, day, hours, minutes, and seconds over to time, which is expressed in seconds. and the tea is that many of the implementations could share code, but they do not. πŸ™ˆ
  • each system's heuristics for picking the correct time are slightly different. every system is doing its own little thing. πŸ¦‹
  • the FreeBSD implementation should do a better job of validating the time provided in base when the battery-backed clock is unusable. currently it unconditionally sets the system clock to this value. no checks, no second thoughts, just sending it. 😭

fr fr, if your battery-backed clock is cooked, this page is your whole personality at boot. iykyk. 🫢

and that's a wrap on this one, my love πŸ’– this Debian page is dated March 22, 1997 β€” yes, a whole vintage icon, still serving after all these years πŸ‘‘βœ¨ slay, honestly. 🌈

πŸ“¦ where this page comes from