]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/adjtime.3
389af6f02b4f9c46ca93a998e16f04cd74e34ea4
[thirdparty/man-pages.git] / man3 / adjtime.3
1 '\" t
2 .\" Copyright (c) 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH adjtime 3 (date) "Linux man-pages (unreleased)"
7 .SH NAME
8 adjtime \- correct the time to synchronize the system clock
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/time.h>
15 .PP
16 .BI "int adjtime(const struct timeval *" delta ", struct timeval *" olddelta );
17 .fi
18 .PP
19 .RS -4
20 Feature Test Macro Requirements for glibc (see
21 .BR feature_test_macros (7)):
22 .RE
23 .PP
24 .BR adjtime ():
25 .nf
26 Since glibc 2.19:
27 _DEFAULT_SOURCE
28 glibc 2.19 and earlier:
29 _BSD_SOURCE
30 .fi
31 .SH DESCRIPTION
32 The
33 .BR adjtime ()
34 function gradually adjusts the system clock (as returned by
35 .BR gettimeofday (2)).
36 The amount of time by which the clock is to be adjusted is specified
37 in the structure pointed to by
38 .IR delta .
39 This structure has the following form:
40 .PP
41 .in +4n
42 .EX
43 struct timeval {
44 time_t tv_sec; /* seconds */
45 suseconds_t tv_usec; /* microseconds */
46 };
47 .EE
48 .in
49 .PP
50 If the adjustment in
51 .I delta
52 is positive, then the system clock is speeded up by some
53 small percentage (i.e., by adding a small
54 amount of time to the clock value in each second) until the adjustment
55 has been completed.
56 If the adjustment in
57 .I delta
58 is negative, then the clock is slowed down in a similar fashion.
59 .PP
60 If a clock adjustment from an earlier
61 .BR adjtime ()
62 call is already in progress
63 at the time of a later
64 .BR adjtime ()
65 call, and
66 .I delta
67 is not NULL for the later call, then the earlier adjustment is stopped,
68 but any already completed part of that adjustment is not undone.
69 .PP
70 If
71 .I olddelta
72 is not NULL, then the buffer that it points to is used to return
73 the amount of time remaining from any previous adjustment that
74 has not yet been completed.
75 .SH RETURN VALUE
76 On success,
77 .BR adjtime ()
78 returns 0.
79 On failure, \-1 is returned, and
80 .I errno
81 is set to indicate the error.
82 .SH ERRORS
83 .TP
84 .B EINVAL
85 The adjustment in
86 .I delta
87 is outside the permitted range.
88 .TP
89 .B EPERM
90 The caller does not have sufficient privilege to adjust the time.
91 Under Linux, the
92 .B CAP_SYS_TIME
93 capability is required.
94 .SH ATTRIBUTES
95 For an explanation of the terms used in this section, see
96 .BR attributes (7).
97 .ad l
98 .nh
99 .TS
100 allbox;
101 lbx lb lb
102 l l l.
103 Interface Attribute Value
104 T{
105 .BR adjtime ()
106 T} Thread safety MT-Safe
107 .TE
108 .hy
109 .ad
110 .sp 1
111 .SH STANDARDS
112 None.
113 .SH HISTORY
114 4.3BSD, System V.
115 .SH NOTES
116 The adjustment that
117 .BR adjtime ()
118 makes to the clock is carried out in such a manner that the clock
119 is always monotonically increasing.
120 Using
121 .BR adjtime ()
122 to adjust the time prevents the problems that can be caused for certain
123 applications (e.g.,
124 .BR make (1))
125 by abrupt positive or negative jumps in the system time.
126 .PP
127 .BR adjtime ()
128 is intended to be used to make small adjustments to the system time.
129 Most systems impose a limit on the adjustment that can be specified in
130 .IR delta .
131 In the glibc implementation,
132 .I delta
133 must be less than or equal to (INT_MAX / 1000000 \- 2)
134 and greater than or equal to (INT_MIN / 1000000 + 2)
135 (respectively 2145 and \-2145 seconds on i386).
136 .SH BUGS
137 A longstanding bug
138 .\" http://sourceware.org/bugzilla/show_bug?id=2449
139 .\" http://bugzilla.kernel.org/show_bug.cgi?id=6761
140 meant that if
141 .I delta
142 was specified as NULL,
143 no valid information about the outstanding clock adjustment was returned in
144 .IR olddelta .
145 (In this circumstance,
146 .BR adjtime ()
147 should return the outstanding clock adjustment, without changing it.)
148 This bug is fixed
149 .\" Thanks to the new adjtimex() ADJ_OFFSET_SS_READ flag
150 on systems with glibc 2.8 or later and
151 Linux kernel 2.6.26 or later.
152 .SH SEE ALSO
153 .BR adjtimex (2),
154 .BR gettimeofday (2),
155 .BR time (7)