-i case goes to background pause and acts like -a case on receiving

SIGTERM. This helps to keep CMOS clock updated before reboot.
Idea from J.Wunsch.
This commit is contained in:
Andrey A. Chernov 1994-11-03 03:16:16 +00:00
parent 97555463a4
commit 9aa4fece6d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=4107
2 changed files with 40 additions and 4 deletions

View File

@ -53,18 +53,24 @@ initialization call from
.Pa /etc/rc
(before any daemons are started).
.Nm Adjkerntz
makes the first adjustment and the initial time zone offset is stored into
makes the adjustment of kernel clock (CMOS clock not touched)
and the initial time zone offset is stored into
.Pa adjkerntz
kernel variable
for following subsequent
.Nm adjkerntz
calls.
.Nm "'adjkerntz -a'"
calls. Then it goes to background pause which ends with SIGTERM.
After receiving SIGTERM it acts like
.Nm "'adjkerntz -a'"
to be shure to have proper CMOS clock before reboot.
.It Cm Fl a
This form is needed, when time zone changes occur.
.Nm Adjkerntz
uses the previously stored
time zone offset and the changed time zone rule to
produce the new time zone offset, fix the RTC clock and store the new
produce the new time zone offset, fix the CMOS clock
(kernel clock not touched)
and store the new
offset into
.Pa adjkerntz
kernel variable
@ -73,6 +79,7 @@ It is recommended to use this form in root's
.Xr crontab 5
every half of a hour from 0am to 4am
since this times matches most modern time zone changes.
.El
.Pp
.Nm Adjkerntz
clears the kernel timezone structure and makes kernel always run at UTC

View File

@ -41,6 +41,7 @@ char copyright[] =
*
*/
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
@ -54,6 +55,8 @@ char copyright[] =
#define REPORT_PERIOD (30*60)
void fake() {}
int main(argc, argv)
int argc;
char **argv;
@ -69,6 +72,7 @@ int main(argc, argv)
time_t initial_sec, final_sec;
int ch, init = -1;
int disrtcset, need_restore = 0;
sigset_t mask, emask;
while ((ch = getopt(argc, argv, "ai")) != EOF)
switch((char)ch) {
@ -95,10 +99,24 @@ int main(argc, argv)
if (access(_PATH_CLOCK, F_OK))
return 0;
sigemptyset(&mask);
sigemptyset(&emask);
sigaddset(&mask, SIGTERM);
openlog("adjkerntz", LOG_PID|LOG_PERROR, LOG_DAEMON);
(void) signal(SIGHUP, SIG_IGN);
if (init && daemon(0, 1)) {
syslog(LOG_ERR, "daemon: %m");
return 1;
}
again:
(void) sigprocmask(SIG_BLOCK, &mask, NULL);
(void) signal(SIGTERM, fake);
/****** Critical section, do all things as fast as possible ******/
/* get local CMOS clock and possible kernel offset */
@ -126,6 +144,8 @@ int main(argc, argv)
*/
syslog(LOG_WARNING,
"Nonexistent local time -- will retry after %d secs", REPORT_PERIOD);
(void) signal(SIGTERM, SIG_DFL);
(void) sigprocmask(SIG_UNBLOCK, &mask, NULL);
(void) sleep(REPORT_PERIOD);
goto again;
}
@ -165,6 +185,8 @@ int main(argc, argv)
*/
syslog(LOG_WARNING,
"Nonexistent (final) local time -- will retry after %d secs", REPORT_PERIOD);
(void) signal(SIGTERM, SIG_DFL);
(void) sigprocmask(SIG_UNBLOCK, &mask, NULL);
(void) sleep(REPORT_PERIOD);
goto again;
}
@ -241,5 +263,12 @@ int main(argc, argv)
/****** End of critical section ******/
if (init) {
init = 0;
/* wait for signals and acts like -a */
(void) sigsuspend(&emask);
goto again;
}
return 0;
}