diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-09-18 20:01:39 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-09-18 20:01:39 +0000 |
commit | 8b59e5dd896409954c209fbbd456a90d15694f8e (patch) | |
tree | 60f9f45c4be65b515dfa9f392ba832f476752688 /usr.sbin/ntpd/ntp.c | |
parent | 6b75e289325ab12e31ac956a08d9d3a80ff41ef5 (diff) |
add a new -s option, that tells ntpd to set the time using settimeofday()
once at startup. ntpd delays daemonizing until it has done the intial
time setting (or ran into the timeout) in this mode to make sure stuff started
later in rc is not subject to time jumps.
this eleminates the need to run rdate -n beforehands.
with some input from & ok ryan and bob, march music from mickey
Diffstat (limited to 'usr.sbin/ntpd/ntp.c')
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index 568178b2b87..1f955e2b527 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.32 2004/09/18 07:33:14 henning Exp $ */ +/* $OpenBSD: ntp.c,v 1.33 2004/09/18 20:01:38 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -19,6 +19,8 @@ #include <sys/param.h> #include <errno.h> +#include <fcntl.h> +#include <paths.h> #include <poll.h> #include <pwd.h> #include <signal.h> @@ -56,7 +58,7 @@ ntp_sighdlr(int sig) pid_t ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) { - int nfds, i, j, idx_peers, timeout; + int nfds, i, j, idx_peers, timeout, nullfd; u_int pfd_elms = 0, idx2peer_elms = 0; u_int listener_cnt, new_cnt; pid_t pid; @@ -84,11 +86,21 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) if ((pw = getpwnam(NTPD_USER)) == NULL) fatal(NULL); + if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) + fatal(NULL); + if (chroot(pw->pw_dir) == -1) fatal("chroot"); if (chdir("/") == -1) fatal("chdir(\"/\")"); + if (!nconf->debug) { + dup2(nullfd, STDIN_FILENO); + dup2(nullfd, STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + } + close(nullfd); + setproctitle("ntp engine"); conf = nconf; @@ -228,8 +240,8 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) for (; nfds > 0 && j < i; j++) if (pfd[j].revents & POLLIN) { nfds--; - if (client_dispatch(idx2peer[j - idx_peers]) == - -1) + if (client_dispatch(idx2peer[j - idx_peers], + conf->settime) == -1) ntp_quit = 1; } } @@ -362,6 +374,13 @@ ntp_adjtime(void) } void +ntp_settime(double offset) +{ + imsg_compose(ibuf_main, IMSG_SETTIME, 0, 0, &offset, sizeof(offset)); + conf->settime = 0; +} + +void ntp_host_dns(char *name, u_int32_t peerid) { u_int16_t dlen; |