.br
.BR "hwclock \-w" " or " "hwclock \-\-systohc"
.br
-.BR "hwclock \-s" " or " "hwclock \-\-hctosys"
+.BR "hwclock \-s" " or " "hwclock \-\-hctosys"
.br
.BR "hwclock \-a" " or " "hwclock \-\-adjust"
.br
Hardware Clock to the System Time, and set the System Time from the
Hardware Clock.
.PP
-You can also run
-.B hwclock
+You can also run
+.B hwclock
periodically to insert or remove time from the Hardware Clock to
compensate for systematic drift (where the clock consistently gains or
loses time at a certain rate if left to run).
.SH OPTIONS
-You need exactly one of the following options to tell
-.B hwclock
+You need exactly one of the following options to tell
+.B hwclock
what function to perform:
.PP
.TP
.TP
.B \-\-set
-Set the Hardware Clock to the time given by the
+Set the Hardware Clock to the time given by the
.B \-\-date
option.
.TP
.B \-\-hctosys
-Set the System Time from the Hardware Clock.
+Set the System Time from the Hardware Clock.
Also set the kernel's timezone value to the local timezone
as indicated by the TZ environment variable and/or
.IR /usr/share/zoneinfo ,
-as
+as
.BR tzset (3)
would interpret them.
The obsolete tz_dsttime field of the kernel's timezone value is set
option for details.
.TP
.B \-\-version
-Print the version of
-.B hwclock
+Print the version of
+.B hwclock
on Standard Output.
.TP
.B \-\-date=date_string
.sp
.I hwclock --set --date="9/22/96 16:45:05"
.sp
-The argument is in local time, even if you keep your Hardware Clock in
-Coordinated Universal time. See the
+The argument is in local time, even if you keep your Hardware Clock in
+Coordinated Universal time. See the
.B \-\-utc
option.
.B hwclock
was used to set the clock (i.e. hwclock was successfully run with the
.B \-\-set
-,
+,
.B \-\-systohc
,
or
.TP
.B \-\-directisa
is meaningful only on an ISA machine or an Alpha (which implements enough
-of ISA to be, roughly speaking, an ISA machine for
+of ISA to be, roughly speaking, an ISA machine for
.BR hwclock 's
purposes). For other machines, it has no effect. This option tells
.B hwclock
to use explicit I/O instructions to access the Hardware Clock.
-Without this option,
+Without this option,
.B hwclock
will try to use the /dev/rtc device (which it assumes to be driven by the
rtc device driver). If it is unable to open the device (for read), it will
.TP
.B \-\-badyear
Indicates that the Hardware Clock is incapable of storing years outside
-the range 1994-1999. There is a problem in some BIOSes (almost all
+the range 1994-1999. There is a problem in some BIOSes (almost all
Award BIOSes made between 4/26/94 and 5/31/95) wherein they are unable
to deal with years after 1999. If one attempts to set the year-of-century
value to something less than 94 (or 95 in some cases), the value that
the true time in the normal way.
To compensate for this (without your getting a BIOS update, which would
-definitely be preferable), always use
+definitely be preferable), always use
.B \-\-badyear
-if you have one of these machines. When
+if you have one of these machines. When
.B hwclock
knows it's working with a brain-damaged clock, it ignores the year part of
-the Hardware Clock value and instead tries to guess the year based on the
+the Hardware Clock value and instead tries to guess the year based on the
last calibrated date in the adjtime file, by assuming that that date is
-within the past year. For this to work, you had better do a
+within the past year. For this to work, you had better do a
.I hwclock \-\-set
or
.I hwclock \-\-systohc
at least once a year!
-Though
+Though
.B hwclock
ignores the year value when it reads the Hardware Clock, it sets the
year value when it sets the clock. It sets it to 1995, 1996, 1997, or
end up losing a day.
.B hwclock
-warns you that you probably need
+warns you that you probably need
.B \-\-badyear
-whenever it finds your Hardware Clock set to 1994 or 1995.
+whenever it finds your Hardware Clock set to 1994 or 1995.
.TP
.B \-\-srm
.B \-\-funky\-toy
These two options specify what kind of Alpha machine you have. They
are invalid if you don't have an Alpha and are usually unnecessary
-if you do, because
-.B hwclock
-should be able to determine by itself what it's
+if you do, because
+.B hwclock
+should be able to determine by itself what it's
running on, at least when
.I /proc
is mounted.
(If you find you need one of these options to make
-.B hwclock
+.B hwclock
work, contact the maintainer to see if the program can be improved
to detect your system automatically. Output of `hwclock --debug'
and `cat /proc/cpuinfo' may be of interest.)
-.B \-\-jensen
+.B \-\-jensen
means you are running on a Jensen model.
-.B \-\-funky\-toy
+.B \-\-funky\-toy
means that on your machine, one has to use the UF bit instead
of the UIP bit in the Hardware Clock to detect a time transition. "Toy"
-in the option name refers to the Time Of Year facility of the machine.
+in the option name refers to the Time Of Year facility of the machine.
.TP
Do everything except actually updating the Hardware Clock or anything
else. This is useful, especially in conjunction with
.B \-\-debug,
-in learning about
+in learning about
.B hwclock.
.TP
.B \-\-debug
-Display a lot of information about what
-.B hwclock
+Display a lot of information about what
+.B hwclock
is doing internally. Some of its function is complex and this output
can help you understand how the program works.
.PP
There are two main clocks in a Linux system:
.PP
-.B The Hardware Clock:
+.B The Hardware Clock:
This is a clock that runs independently of any control program running
in the CPU and even when the machine is powered off.
.PP
This clock is commonly called the hardware clock, the real time clock,
the RTC, the BIOS clock, and the CMOS clock. Hardware Clock, in its
-capitalized form, was coined for use by
-.B hwclock
+capitalized form, was coined for use by
+.B hwclock
because all of the other names are inappropriate to the point of being
misleading.
.PP
backup battery as the hardware clock to initialize a more functional
integrated real-time clock which is used for most other purposes.
.PP
-.B The System Time:
+.B The System Time:
This is the time kept by a clock inside the Linux kernel and driven by
a timer interrupt. (On an ISA machine, the timer interrupt is part of
the ISA standard). It has meaning only while Linux is running on the
for which ISA was designed, the Hardware Clock is the only real time clock.
.PP
It is important that the System Time not have any discontinuities such as
-would happen if you used the
+would happen if you used the
.BR date (1L)
program to set it while the system is running. You can, however, do whatever
you want to the Hardware Clock while the system is running, and the next
time Linux starts up, it will do so with the adjusted time from the Hardware
-Clock. You can also use the program
+Clock. You can also use the program
.BR adjtimex (8)
to smoothly adjust the System Time while the system runs.
.PP
.B hwclock
sets the kernel timezone to the value indicated by TZ and/or
.I /usr/share/zoneinfo
-when you set the System Time using the
+when you set the System Time using the
.B \-\-hctosys
option.
.PP
.SH How hwclock Accesses the Hardware Clock
.PP
-.B hwclock
+.B hwclock
Uses many different ways to get and set Hardware Clock values.
The most normal way is to do I/O to the device special file /dev/rtc,
which is presumed to be driven by the rtc device driver. However,
instead.
.PP
On older systems, the method of accessing the Hardware Clock depends on
-the system hardware.
+the system hardware.
.PP
-On an ISA system,
-.B hwclock
+On an ISA system,
+.B hwclock
can directly access the "CMOS memory" registers that
constitute the clock, by doing I/O to Ports 0x70 and 0x71. It does
this with actual I/O instructions and consequently can only do it if
running with superuser effective userid. (In the case of a Jensen
Alpha, there is no way for
-.B hwclock
+.B hwclock
to execute those I/O instructions, and so it uses instead the
/dev/port device special file, which provides almost as low-level an
interface to the I/O subsystem).
can access the clock via the console driver, via the device special
file /dev/tty1.
.PP
-.B hwclock
+.B hwclock
tries to use /dev/rtc. If it is compiled for a kernel that doesn't have
that function or it is unable to open /dev/rtc
(or the alternative special file you've defined on the command line)
-.B hwclock
+.B hwclock
will fall back to another method, if available. On an ISA or Alpha
machine, you can force
.B hwclock
The Hardware Clock is usually not very accurate. However, much of its
inaccuracy is completely predictable - it gains or loses the same amount
of time every day. This is called systematic drift.
-.BR hwclock 's
+.BR hwclock 's
"adjust" function lets you make systematic corrections to correct the
systematic drift.
.PP
-It works like this:
-.B hwclock
+It works like this:
+.B hwclock
keeps a file,
.I /etc/adjtime,
that keeps some historical information. This is called the adjtime file.
.PP
-Suppose you start with no adjtime file. You issue a
+Suppose you start with no adjtime file. You issue a
.I hwclock \-\-set
-command to set the Hardware Clock to the true current time.
-.B Hwclock
-creates the adjtime file and records in it the current time as the
+command to set the Hardware Clock to the true current time.
+.B Hwclock
+creates the adjtime file and records in it the current time as the
last time the clock was calibrated.
5 days later, the clock has gained 10 seconds, so you issue another
.I hwclock \-\-set
-command to set it back 10 seconds.
-.B Hwclock
+command to set it back 10 seconds.
+.B Hwclock
updates the adjtime file to show the current time as the last time the
clock was calibrated, and records 2 seconds per day as the systematic
drift rate. 24 hours go by, and then you issue a
.I hwclock \-\-adjust
-command.
-.B Hwclock
+command.
+.B Hwclock
consults the adjtime file and sees that the clock gains 2 seconds per
day when left alone and that it has been left alone for exactly one
day. So it subtracts 2 seconds from the Hardware Clock. It then
records the current time as the last time the clock was adjusted.
Another 24 hours goes by and you issue another
.I hwclock \-\-adjust.
-.B Hwclock
+.B Hwclock
does the same thing: subtracts 2 seconds and updates the adjtime file
with the current time as the last time the clock was adjusted.
.PP
-Every time you calibrate (set) the clock (using
+Every time you calibrate (set) the clock (using
.I \-\-set
or
.I \-\-systohc
),
-.B hwclock
+.B hwclock
recalculates the systematic drift rate based on how long it has been
since the last calibration, how long it has been since the last
adjustment, what drift rate was assumed in any intervening
adjustments, and the amount by which the clock is presently off.
.PP
-A small amount of error creeps in any time
-.B hwclock
+A small amount of error creeps in any time
+.B hwclock
sets the clock, so it refrains from making an adjustment that would be
less than 1 second. Later on, when you request an adjustment again,
the accumulated drift will be more than a second and
-.B hwclock
+.B hwclock
will do the adjustment then.
.PP
-It is good to do a
+It is good to do a
.I hwclock \-\-adjust
-just before the
+just before the
.I hwclock \-\-hctosys
at system startup time, and maybe periodically while the system is
running via cron.
Line 2: 1 number: Resulting number of seconds since 1969 UTC of most
recent calibration. Zero if there has been no calibration yet or it
is known that any previous calibration is moot (for example, because
-the Hardware Clock has been found, since that calibration, not to
+the Hardware Clock has been found, since that calibration, not to
contain a valid time). This is a decimal integer.
.PP
-Line 3: "UTC" or "LOCAL". Tells whether the Hardware Clock is set to
+Line 3: "UTC" or "LOCAL". Tells whether the Hardware Clock is set to
Coordinated Universal Time or local time. You can always override this
-value with options on the
+value with options on the
.B hwclock
command line.
.PP
-You can use an adjtime file that was previously used with the
+You can use an adjtime file that was previously used with the
.BR clock (8)
-program with
+program with
.B hwclock.
.SH "Automatic Hardware Clock Synchronization By the Kernel"
-You should be aware of another way that the Hardware Clock is kept
+You should be aware of another way that the Hardware Clock is kept
synchronized in some systems. The Linux kernel has a mode wherein it
-copies the System Time to the Hardware Clock every 11 minutes.
+copies the System Time to the Hardware Clock every 11 minutes.
This is a good mode to use when you are using something sophisticated
like ntp to keep your System Time synchronized. (ntp is a way to keep
your System Time synchronized either to a time server somewhere on the
that sets the System Time the old fashioned way.
To see if it is on or
-off, use the command
+off, use the command
.I adjtimex \-\-print
and look at the value of "status". If the "64" bit of this number
(expressed in binary) equal to 0, 11 minute mode is on. Otherwise, it
is off.
-If your system runs with 11 minute mode on, don't use
+If your system runs with 11 minute mode on, don't use
.I hwclock \-\-adjust
or
.IR "hwclock \-\-hctosys" .
You'll just make a mess. It is acceptable to use a
-.I hwclock \-\-hctosys
+.I hwclock \-\-hctosys
at startup time to get a reasonable System Time until your system is
able to set the System Time from the external source and start 11
minute mode.
.SH ISA Hardware Clock Century value
There is some sort of standard that defines CMOS memory Byte 50 on an ISA
-machine as an indicator of what century it is.
+machine as an indicator of what century it is.
.B hwclock
does not use or set that byte because there are some machines that
don't define the byte that way, and it really isn't necessary anyway,
since the year-of-century does a good job of implying which century it
is.
-If you have a bona fide use for a CMOS century byte, contact the
+If you have a bona fide use for a CMOS century byte, contact the
.B hwclock
maintainer; an option may be appropriate.
Written by Bryan Henderson, September 1996 (bryanh@giraffe-data.com),
based on work done on the
.I clock
-program by Charles Hedrick, Rob Hooft, and Harald Koenig.
+program by Charles Hedrick, Rob Hooft, and Harald Koenig.
See the source code for complete history and credits.
*
* Reshuffled things, added sparc code, and re-added alpha stuff
* by David Mosberger <davidm@azstarnet.com>
- * and Jay Estabrook <jestabro@amt.tay1.dec.com>
+ * and Jay Estabrook <jestabro@amt.tay1.dec.com>
* and Martin Ostermann <ost@coments.rwth-aachen.de>, aeb@cwi.nl, 990212.
*
* Fix for Award 2094 bug, Dave Coffin (dcoffin@shore.net) 11/12/98
adjtime file, so see documentation of that file for details.
Exception is <dirty>, which is an indication that what's in this
structure is not what's in the disk file (because it has been
- updated since read from the disk file).
+ updated since read from the disk file).
*/
bool dirty;
/* line 1 */
- double drift_factor;
+ double drift_factor;
time_t last_adj_time;
double not_adjusted;
write_date_to_file (tm);
}
-static double
+static double
time_diff(struct timeval subtrahend, struct timeval subtractor) {
/*---------------------------------------------------------------------------
The difference in seconds between two times in "timeval" format.
Return them as the adjtime structure <*adjtime_p>.
If there is no /etc/adjtime file, return defaults.
If values are missing from the file, return defaults for them.
-
+
return value 0 if all OK, !=0 otherwise.
-----------------------------------------------------------------------------*/
char line2[81]; /* String: second line of adjtime file */
char line3[81]; /* String: third line of adjtime file */
long timeval;
-
+
line1[0] = '\0'; /* In case fgets fails */
fgets(line1, sizeof(line1), adjfile);
line2[0] = '\0'; /* In case fgets fails */
fgets(line2, sizeof(line2), adjfile);
line3[0] = '\0'; /* In case fgets fails */
fgets(line3, sizeof(line3), adjfile);
-
+
fclose(adjfile);
-
+
/* Set defaults in case values are missing from file */
adjtime_p->drift_factor = 0;
adjtime_p->last_adj_time = 0;
adjtime_p->not_adjusted = 0;
adjtime_p->last_calib_time = 0;
timeval = 0;
-
- sscanf(line1, "%lf %ld %lf",
+
+ sscanf(line1, "%lf %ld %lf",
&adjtime_p->drift_factor,
- &timeval,
+ &timeval,
&adjtime_p->not_adjusted);
adjtime_p->last_adj_time = timeval;
adjtime_p->dirty = FALSE;
if (debug) {
- printf(_("Last drift adjustment done at %ld seconds after 1969\n"),
+ printf(_("Last drift adjustment done at %ld seconds after 1969\n"),
(long) adjtime_p->last_adj_time);
printf(_("Last calibration done at %ld seconds after 1969\n"),
(long) adjtime_p->last_calib_time);
once per second, right on the falling edge of the update flag.
We wait (up to one second) either blocked waiting for an rtc device
- or in a CPU spin loop. The former is probably not very accurate.
+ or in a CPU spin loop. The former is probably not very accurate.
Return 0 if it worked, nonzero if it didn't.
-----------------------------------------------------------------------------*/
static void
-mktime_tz(struct tm tm, const bool universal,
+mktime_tz(struct tm tm, const bool universal,
bool *valid_p, time_t *systime_p) {
/*-----------------------------------------------------------------------------
Convert a time in broken down format (hours, minutes, etc.) into standard
time_t mktime_result; /* The value returned by our mktime() call */
char *zone; /* Local time zone name */
- /* We use the C library function mktime(), but since it only works on
- local time zone input, we may have to fake it out by temporarily
+ /* We use the C library function mktime(), but since it only works on
+ local time zone input, we may have to fake it out by temporarily
changing the local time zone to UTC.
*/
zone = getenv("TZ"); /* remember original time zone */
} else {
*valid_p = TRUE;
*systime_p = mktime_result;
- if (debug)
+ if (debug)
printf(_("Hw clock time : %4d/%.2d/%.2d %.2d:%.2d:%.2d = "
"%ld seconds since 1969\n"),
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
static void
-set_hardware_clock(const time_t newtime,
- const bool universal,
+set_hardware_clock(const time_t newtime,
+ const bool universal,
const bool testing) {
/*----------------------------------------------------------------------------
Set the Hardware Clock to the time <newtime>, in local time zone or UTC,
according to <universal>.
----------------------------------------------------------------------------*/
int err;
- struct tm new_broken_time;
+ struct tm new_broken_time;
/* Time to which we will set Hardware Clock, in broken down format, in
the time zone of caller's choice
*/
else
new_broken_time = *localtime(&newtime);
- if (debug)
+ if (debug)
printf(_("Setting Hardware Clock to %.2d:%.2d:%.2d "
- "= %ld seconds since 1969\n"),
- new_broken_time.tm_hour, new_broken_time.tm_min,
+ "= %ld seconds since 1969\n"),
+ new_broken_time.tm_hour, new_broken_time.tm_min,
new_broken_time.tm_sec, (long) newtime);
if (testing)
static void
-set_hardware_clock_exact(const time_t sethwtime,
+set_hardware_clock_exact(const time_t sethwtime,
const struct timeval refsystime,
- const bool universal,
+ const bool universal,
const bool testing) {
/*----------------------------------------------------------------------------
Set the Hardware Clock to the time "sethwtime", in local time zone or UTC,
to 14:03:07, thus getting a precise and retroactive setting of the clock.
(Don't be confused by the fact that the system clock and the Hardware
- Clock differ by two hours in the above example. That's just to remind
+ Clock differ by two hours in the above example. That's just to remind
you that there are two independent time scales here).
This function ought to be able to accept set times as fractional times.
time_resync:
gettimeofday(&beginsystime, NULL);
newhwtime = sethwtime + (int) time_diff(beginsystime, refsystime) + 1;
- if (debug)
+ if (debug)
printf(_("Time elapsed since reference time has been %.6f seconds.\n"
"Delaying further to reach the next full second.\n"),
time_diff(beginsystime, refsystime));
-
+
/*
* Now delay some more until Hardware Clock time newhwtime arrives. The -500
* ms is because the Hardware Clock always sets to your set time plus 500 ms
if (tdiff < 0)
goto time_resync; /* probably time was reset */
} while (time_diff(nowsystime, refsystime) - 0.5 < newhwtime - sethwtime);
-
+
set_hardware_clock(newhwtime, universal, testing);
}
static void
-display_time(const bool hclock_valid, const time_t systime,
+display_time(const bool hclock_valid, const time_t systime,
const double sync_duration) {
/*----------------------------------------------------------------------------
Put the time "systime" on standard output in display format.
Interpret the value of the --date option, which is something like
"13:05:01". In fact, it can be any of the myriad ASCII strings that specify
a time which the "date" program can understand. The date option value in
- question is our "dateopt" argument.
+ question is our "dateopt" argument.
The specified time is in the local time zone.
FILE *date_child_fp;
char date_resp[100];
const char magic[]="seconds-into-epoch=";
- char date_command[100];
+ char date_command[100];
int retcode; /* our eventual return code */
int rc; /* local return code */
return 12;
}
- sprintf(date_command, "date --date=\"%s\" +seconds-into-epoch=%%s",
+ sprintf(date_command, "date --date=\"%s\" +seconds-into-epoch=%%s",
date_opt);
if (debug)
printf(_("Issuing date command: %s\n"), date_command);
fprintf(stderr, _("The date command issued by %s returned "
"unexpected results.\n"
"The command was:\n %s\n"
- "The response was:\n %s\n"),
+ "The response was:\n %s\n"),
MYNAME, date_command, date_resp);
retcode = 8;
} else {
} else {
retcode = 0;
*time_p = seconds_since_epoch;
- if (debug)
+ if (debug)
printf(_("date string %s equates to "
"%ld seconds since 1969.\n"),
date_opt, (long) *time_p);
return retcode;
}
-
-static int
-set_system_clock(const bool hclock_valid, const time_t newtime,
+
+static int
+set_system_clock(const bool hclock_valid, const time_t newtime,
const bool testing) {
/*----------------------------------------------------------------------------
Set the System Clock to time 'newtime'.
- Also set the kernel time zone value to the value indicated by the
+ Also set the kernel time zone value to the value indicated by the
TZ environment variable and/or /usr/lib/zoneinfo/, interpreted as
tzset() would interpret them.
saying there is no valid time in the Hardware Clock to which to set
the system time.
- If 'testing' is true, don't actually update anything -- just say we
+ If 'testing' is true, don't actually update anything -- just say we
would have.
-----------------------------------------------------------------------------*/
int retcode;
struct tm *broken;
int minuteswest;
int rc;
-
+
tv.tv_sec = newtime;
tv.tv_usec = 0;
-
+
broken = localtime(&newtime);
#ifdef HAVE_TM_GMTOFF
minuteswest = -broken->tm_gmtoff/60; /* GNU extension */
if (broken->tm_isdst)
minuteswest -= 60;
#endif
-
+
if (debug) {
printf(_("Calling settimeofday:\n"));
printf(_("\ttv.tv_sec = %ld, tv.tv_usec = %ld\n"),
static void
adjust_drift_factor(struct adjtime *adjtime_p,
- const time_t nowtime,
+ const time_t nowtime,
const bool hclock_valid,
const time_t hclocktime,
const double sync_delay) {
(int) (nowtime - adjtime_p->last_calib_time),
adjtime_p->drift_factor,
factor_adjust);
-
+
adjtime_p->drift_factor += factor_adjust;
}
adjtime_p->last_calib_time = nowtime;
-
+
adjtime_p->last_adj_time = nowtime;
-
+
adjtime_p->not_adjusted = 0;
-
+
adjtime_p->dirty = TRUE;
}
static void
calculate_adjustment(const double factor,
- const time_t last_time,
+ const time_t last_time,
const double not_adjusted,
const time_t systime,
- int *adjustment_p,
+ int *adjustment_p,
double *retro_p,
const int debug ) {
/*----------------------------------------------------------------------------
The way we have to set the clock, we need the adjustment in two parts:
1) an integer number of seconds (return as *adjustment_p)
-
+
2) a positive fraction of a second (less than 1) (return as *retro_p)
The sum of these two values is the adjustment needed. Positive means to
exact_adjustment = ((double) (systime - last_time)) * factor / (24 * 60 * 60)
+ not_adjusted;
*adjustment_p = FLOOR(exact_adjustment);
-
+
*retro_p = exact_adjustment - (double) *adjustment_p;
if (debug) {
printf (_("Time since last adjustment is %d seconds\n"),
if (testing) {
printf(_("Not updating adjtime file because of testing mode.\n"));
- printf(_("Would have written the following to %s:\n%s"),
+ printf(_("Would have written the following to %s:\n%s"),
ADJPATH, newfile);
} else {
FILE *adjfile;
static void
do_adjustment(struct adjtime *adjtime_p,
- const bool hclock_valid, const time_t hclocktime,
+ const bool hclock_valid, const time_t hclocktime,
const struct timeval read_time,
const bool universal, const bool testing) {
/*---------------------------------------------------------------------------
- Do the adjustment requested, by 1) setting the Hardware Clock (if
+ Do the adjustment requested, by 1) setting the Hardware Clock (if
necessary), and 2) updating the last-adjusted time in the adjtime
structure.
<hclock_valid> means the Hardware Clock contains a valid time, and that
time is <hclocktime>.
- <read_time> is the current system time (to be precise, it is the system
+ <read_time> is the current system time (to be precise, it is the system
time at the time <hclocktime> was read, which due to computational delay
could be a short time ago).
} else {
int adjustment;
/* Number of seconds we must insert in the Hardware Clock */
- double retro;
+ double retro;
/* Fraction of second we have to remove from clock after inserting
<adjustment> whole seconds.
*/
&adjustment, &retro,
debug );
if (adjustment > 0 || adjustment < -1) {
- set_hardware_clock_exact(hclocktime + adjustment,
+ set_hardware_clock_exact(hclocktime + adjustment,
time_inc(read_time, -retro),
universal, testing);
adjtime_p->last_adj_time = hclocktime + adjustment;
adjtime_p->not_adjusted = 0;
adjtime_p->dirty = TRUE;
- } else
- if (debug)
+ } else
+ if (debug)
printf(_("Needed adjustment is less than one second, "
"so not setting clock.\n"));
}
static int
manipulate_clock(const bool show, const bool adjust, const bool noadjfile,
const bool set, const time_t set_time,
- const bool hctosys, const bool systohc,
- const struct timeval startup_time,
+ const bool hctosys, const bool systohc,
+ const struct timeval startup_time,
const bool utc, const bool local_opt,
const bool testing) {
/*---------------------------------------------------------------------------
return rc;
} else {
/* A little trick to avoid reading the file if we don't have to */
- adjtime.dirty = FALSE;
+ adjtime.dirty = FALSE;
rc = 0;
}
return rc;
{
- struct timeval read_time;
+ struct timeval read_time;
/* The time at which we read the Hardware Clock */
bool hclock_valid;
synchronized to its next clock tick when we started up.
Defined only if hclock_valid is true.
*/
-
+
gettimeofday(&read_time, NULL);
- read_hardware_clock(universal, &hclock_valid, &hclocktime);
-
+ read_hardware_clock(universal, &hclock_valid, &hclocktime);
+
if (show) {
- display_time(hclock_valid, hclocktime,
+ display_time(hclock_valid, hclocktime,
time_diff(read_time, startup_time));
} else if (set) {
- set_hardware_clock_exact(set_time, startup_time,
+ set_hardware_clock_exact(set_time, startup_time,
universal, testing);
adjust_drift_factor(&adjtime, set_time, hclock_valid, hclocktime,
time_diff(read_time, startup_time));
} else if (adjust) {
- do_adjustment(&adjtime, hclock_valid, hclocktime,
+ do_adjustment(&adjtime, hclock_valid, hclocktime,
read_time, universal, testing);
} else if (systohc) {
struct timeval nowtime, reftime;
/* We can only set_hardware_clock_exact to a whole seconds
time, so we set it with reference to the most recent
- whole seconds time.
+ whole seconds time.
*/
gettimeofday(&nowtime, NULL);
reftime.tv_sec = nowtime.tv_sec;
reftime.tv_usec = 0;
-
- set_hardware_clock_exact((time_t) reftime.tv_sec, reftime,
+
+ set_hardware_clock_exact((time_t) reftime.tv_sec, reftime,
universal, testing);
- adjust_drift_factor(&adjtime, (time_t) reftime.tv_sec, hclock_valid,
+ adjust_drift_factor(&adjtime, (time_t) reftime.tv_sec, hclock_valid,
hclocktime, (double) read_time.tv_usec / 1E6);
} else if (hctosys) {
rc = set_system_clock(hclock_valid, hclocktime, testing);
static void
-manipulate_epoch(const bool getepoch, const bool setepoch,
+manipulate_epoch(const bool getepoch, const bool setepoch,
const int epoch_opt, const bool testing) {
/*----------------------------------------------------------------------------
Get or set the Hardware Clock epoch value in the kernel, as appropriate.
-----------------------------------------------------------------------------*/
/*
- Maintenance note: This should work on non-Alpha machines, but the
+ Maintenance note: This should work on non-Alpha machines, but the
evidence today (98.03.04) indicates that the kernel only keeps the
epoch value on Alphas. If that is ever fixed, this function should be
changed.
if (get_epoch_rtc(&epoch, 0))
fprintf(stderr, _("Unable to get the epoch value from the kernel.\n"));
- else
+ else
printf(_("Kernel is assuming an epoch value of %lu\n"), epoch);
} else if (setepoch) {
if (epoch_opt == -1)
/*
usage - Output (error and) usage information
- This function is called both directly from main to show usage
- information and as fatal function from shhopt if some argument is
- not understood. In case of normal usage info FMT should be NULL.
- In that case the info is printed to stdout. If FMT is given
- usage will act like fprintf( stderr, fmt, ... ), show a usage
+ This function is called both directly from main to show usage
+ information and as fatal function from shhopt if some argument is
+ not understood. In case of normal usage info FMT should be NULL.
+ In that case the info is printed to stdout. If FMT is given
+ usage will act like fprintf( stderr, fmt, ... ), show a usage
information and terminate the program afterwards.
*/
-static void
+static void
usage( const char *fmt, ... ) {
FILE *usageto;
va_list ap;
vfprintf(stderr, fmt, ap);
va_end(ap);
}
-
+
hwclock_exit(fmt ? EX_USAGE : 0);
}
* 0: OK (or not)
* 1: failure
*/
-int
+int
main(int argc, char **argv) {
struct timeval startup_time;
}
}
- if (!(show | set | systohc | hctosys | adjust | getepoch | setepoch))
+ if (!(show | set | systohc | hctosys | adjust | getepoch | setepoch))
show = 1; /* default to show */
-
+
if (getuid() == 0)
permitted = TRUE;
else {
/* program is designed to run setuid (in some situations) */
if (set || hctosys || systohc || adjust) {
- fprintf(stderr,
+ fprintf(stderr,
_("Sorry, only the superuser can change "
"the Hardware Clock.\n"));
permitted = FALSE;
"the System Clock.\n"));
permitted = FALSE;
} else if (setepoch) {
- fprintf(stderr,
+ fprintf(stderr,
_("Sorry, only the superuser can change the "
"Hardware Clock epoch in the kernel.\n"));
permitted = FALSE;
outsyserr(char *msg, ...) {
va_list args;
int errsv = errno;
-
+
fprintf(stderr, "%s: ", progname);
va_start(args, msg);
vfprintf(stderr, msg, args);
History of this program:
- 98.08.12 BJH Version 2.4
+ 98.08.12 BJH Version 2.4
Don't use century byte from Hardware Clock. Add comments telling why.
Make --hctosys set the kernel timezone from TZ environment variable
and/or /usr/lib/zoneinfo. From Klaus Ripke (klaus@ripke.com).
- 98.03.05 BJH. Version 2.2.
+ 98.03.05 BJH. Version 2.2.
- Add --getepoch and --setepoch.
+ Add --getepoch and --setepoch.
Fix some word length things so it works on Alpha.
97.06.01: BJH. Version 2.1. Read and write the century byte (Byte
50) of the ISA Hardware Clock when using direct ISA I/O. Problem
discovered by job (jei@iclnl.icl.nl).
-
+
Use the rtc clock access method in preference to the KDGHWCLK method.
Problem discovered by Andreas Schwab <schwab@LS5.informatik.uni-dortmund.de>.
in this program will be compiled as external references. Since you
probably won't be linking with any functions by these names, you will
have unresolved external references when you link.
-
+
The program is designed to run setuid superuser, since we need to be
- able to do direct I/O. (More to the point: we need permission to
- execute the iopl() system call). (However, if you use one of the
+ able to do direct I/O. (More to the point: we need permission to
+ execute the iopl() system call). (However, if you use one of the
methods other than direct ISA I/O to access the clock, no setuid is
required).
-
+
Here's some info on how we must deal with the time that elapses while
this program runs: There are two major delays as we run:
So we check the system time as soon as we start up, then run "date"
and do file I/O if necessary, then wait to synchronize with a
Hardware Clock edge, then check the system time again to see how
- much time we spent. We immediately read the clock then and (if
+ much time we spent. We immediately read the clock then and (if
appropriate) report that time, and additionally, the delay we measured.
If we're setting the clock to a time given by the user, we wait some
complications that might cause, we set the clock as soon as possible
after an oscillator tick.
-
+
About synchronizing to the Hardware Clock when reading the time: The
precision of the Hardware Clock counters themselves is one second.
You can't read the counters and find out that is 12:01:02.5. But if
fail if we miss the goal by more than .1 second, as could happen if
we get pre-empted (by the kernel dispatcher).
-****************************************************************************/
+****************************************************************************/