ADJTIME(2)

πŸ’– ADJTIME(2) πŸ’–

okay bestie, so this is a system call from the System Calls Manual β€” and it lives in the Standard C Library (libc, -lc), which is giving "the blueprint, the moment, the canon." it's called adjtime and it's here to correct the time to allow synchronization of the system clock. literally the clock's little glow-up era ✨


🌸 SYNOPSIS 🌸

#include <sys/time.h>

int
adjtime(const struct timeval *delta, struct timeval *olddelta);

✨ DESCRIPTION ✨

so the adjtime() system call makes small adjustments to the system time β€” like the time you get back from gettimeofday(2) β€” and it either advances or retards it by however much you put in the timeval delta. πŸ•°οΈ

  • if delta is negative, the clock gets slowed down β€” it's incremented more slowly than normal until the correction is done.
  • if delta is positive, a larger increment than normal is used instead.

the skew used to perform the correction is generally a fraction of one percent. so yeah, the time is always a monotonically increasing function β€” it never, ever goes backwards, no cap, that's the whole vibe. πŸ“ˆ

⚠️ important bestie: a time correction from an earlier call to adjtime() might not be finished when you call adjtime() again. if olddelta is not a null pointer, then on return the structure it points to will hold the number of microseconds still to be corrected from the earlier call. so you can peek at the leftover to-do list. πŸ’…

this call is what time servers use to synchronize the clocks of computers in a local area network. such time servers would slow down the clocks of some machines and speed up the clocks of others, bringing them all to the average network time. group chat but for clocks, honestly. 🫢

πŸ”’ and yes, the adjtime() system call is restricted to the super-user. root only. periodt.

πŸ’« RETURN VALUES πŸ’«

  • adjtime() returns the value 0 if it ate. πŸŽ€
  • otherwise it returns the value -1 and the global variable errno is set to indicate the error. πŸ’€

πŸŽ€ ERRORS πŸŽ€

the adjtime() system call will fail if:

  • [EFAULT] β€” an argument points outside the process's allocated address space. 😭
  • [EPERM] β€” the process's effective user ID is not that of the super-user. bestie you are simply not on the list. πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹

and also, from R. Gusella and S. Zatti: TSP: The Time Synchronization Protocol for UNIX 4.3BSD. πŸ“šβœ¨


πŸ‘‘ HISTORY πŸ‘‘

the adjtime() system call appeared in 4.3BSD. it's been iconic since day one, fr fr. ⭐


mwah πŸ’– that's the whole page! this one's a Debian classic, dated June 4, 1993, and it's the ADJTIME(2) page from the System Calls Manual. slay, stay synchronized, and remember: always check your olddelta. πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from