diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-09-15 19:14:12 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-09-15 19:14:12 +0000 |
commit | cd4ff5e43c31c11a0c2f117b61c9560e773ac5d1 (patch) | |
tree | 696e1f2bedaf5fce4b898ada02cb180ebe4bec26 /usr.sbin/ntpd | |
parent | d6d18fd87ddab6a16425ef8c785e5bb8ee153c72 (diff) |
malloc the imsg buffers instead of having them statically, suggested by
micsky some time ago, ok otto
Diffstat (limited to 'usr.sbin/ntpd')
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 27 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.c | 30 |
2 files changed, 32 insertions, 25 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index 038ee6fa3cd..27318e09828 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.29 2004/09/15 00:08:06 henning Exp $ */ +/* $OpenBSD: ntp.c,v 1.30 2004/09/15 19:14:11 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -33,7 +33,7 @@ #define PFD_MAX 1 volatile sig_atomic_t ntp_quit = 0; -struct imsgbuf ibuf_main; +struct imsgbuf *ibuf_main; struct ntpd_conf *conf; u_int peer_cnt; @@ -108,7 +108,9 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) signal(SIGHUP, SIG_IGN); close(pipe_prnt[0]); - imsg_init(&ibuf_main, pipe_prnt[1]); + if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL) + fatal(NULL); + imsg_init(ibuf_main, pipe_prnt[1]); TAILQ_FOREACH(p, &conf->ntp_peers, entry) client_peer_init(p); @@ -155,7 +157,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) bzero(pfd, sizeof(struct pollfd) * pfd_elms); bzero(idx2peer, sizeof(void *) * idx2peer_elms); nextaction = time(NULL) + 3600; - pfd[PFD_PIPE_MAIN].fd = ibuf_main.fd; + pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd; pfd[PFD_PIPE_MAIN].events = POLLIN; i = 1; @@ -195,7 +197,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) } } - if (ibuf_main.w.queued > 0) + if (ibuf_main->w.queued > 0) pfd[PFD_PIPE_MAIN].events |= POLLOUT; timeout = nextaction - time(NULL); @@ -209,7 +211,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) } if (nfds > 0 && (pfd[PFD_PIPE_MAIN].revents & POLLOUT)) - if (msgbuf_write(&ibuf_main.w) < 0) { + if (msgbuf_write(&ibuf_main->w) < 0) { log_warn("pipe write error (to parent)"); ntp_quit = 1; } @@ -236,8 +238,9 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) } } - msgbuf_write(&ibuf_main.w); - msgbuf_clear(&ibuf_main.w); + msgbuf_write(&ibuf_main->w); + msgbuf_clear(&ibuf_main->w); + free(ibuf_main); log_info("ntp engine exiting"); _exit(0); @@ -253,7 +256,7 @@ ntp_dispatch_imsg(void) u_char *p; struct ntp_addr *h; - if ((n = imsg_read(&ibuf_main)) == -1) + if ((n = imsg_read(ibuf_main)) == -1) return (-1); if (n == 0) { /* connection closed */ @@ -262,7 +265,7 @@ ntp_dispatch_imsg(void) } for (;;) { - if ((n = imsg_get(&ibuf_main, &imsg)) == -1) + if ((n = imsg_get(ibuf_main, &imsg)) == -1) return (-1); if (n == 0) @@ -351,7 +354,7 @@ ntp_adjtime(void) if (offset_cnt > 0) { offset_median /= offset_cnt; - imsg_compose(&ibuf_main, IMSG_ADJTIME, 0, + imsg_compose(ibuf_main, IMSG_ADJTIME, 0, &offset_median, sizeof(offset_median)); conf->status.reftime = gettime(); @@ -368,5 +371,5 @@ ntp_host_dns(char *name, u_int32_t peerid) u_int16_t dlen; dlen = strlen(name) + 1; - imsg_compose(&ibuf_main, IMSG_HOST_DNS, peerid, name, dlen); + imsg_compose(ibuf_main, IMSG_HOST_DNS, peerid, name, dlen); } diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c index bb8fbb8c8c3..deb51799c1d 100644 --- a/usr.sbin/ntpd/ntpd.c +++ b/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.15 2004/09/15 00:08:06 henning Exp $ */ +/* $OpenBSD: ntpd.c,v 1.16 2004/09/15 19:14:11 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -40,10 +40,10 @@ int check_child(pid_t, const char *); int dispatch_imsg(void); void ntpd_adjtime(double); -volatile sig_atomic_t quit = 0; -volatile sig_atomic_t reconfig = 0; -volatile sig_atomic_t sigchld = 0; -struct imsgbuf ibuf; +volatile sig_atomic_t quit = 0; +volatile sig_atomic_t reconfig = 0; +volatile sig_atomic_t sigchld = 0; +struct imsgbuf *ibuf; void sighdlr(int sig) @@ -139,12 +139,14 @@ main(int argc, char *argv[]) close(pipe_chld[1]); - imsg_init(&ibuf, pipe_chld[0]); + if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL) + fatal(NULL); + imsg_init(ibuf, pipe_chld[0]); while (quit == 0) { - pfd[PFD_PIPE].fd = ibuf.fd; + pfd[PFD_PIPE].fd = ibuf->fd; pfd[PFD_PIPE].events = POLLIN; - if (ibuf.w.queued) + if (ibuf->w.queued) pfd[PFD_PIPE].events |= POLLOUT; if ((nfds = poll(pfd, 1, INFTIM)) == -1) @@ -154,7 +156,7 @@ main(int argc, char *argv[]) } if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT)) - if (msgbuf_write(&ibuf.w) < 0) { + if (msgbuf_write(&ibuf->w) < 0) { log_warn("pipe write error (to child"); quit = 1; } @@ -184,6 +186,8 @@ main(int argc, char *argv[]) fatal("wait"); } while (pid != -1 || (pid == -1 && errno == EINTR)); + msgbuf_clear(&ibuf->w); + free(ibuf); log_info("Terminating"); return (0); } @@ -218,7 +222,7 @@ dispatch_imsg(void) struct ntp_addr *h, *hn; struct buf *buf; - if ((n = imsg_read(&ibuf)) == -1) + if ((n = imsg_read(ibuf)) == -1) return (-1); if (n == 0) { /* connection closed */ @@ -227,7 +231,7 @@ dispatch_imsg(void) } for (;;) { - if ((n = imsg_get(&ibuf, &imsg)) == -1) + if ((n = imsg_get(ibuf, &imsg)) == -1) return (-1); if (n == 0) @@ -245,7 +249,7 @@ dispatch_imsg(void) if (imsg.hdr.len != strlen(name) + 1 + IMSG_HEADER_SIZE) fatal("invalid IMSG_HOST_DNS received"); if ((cnt = host_dns(name, &hn)) > 0) { - buf = imsg_create(&ibuf, IMSG_HOST_DNS, + buf = imsg_create(ibuf, IMSG_HOST_DNS, imsg.hdr.peerid, cnt * sizeof(struct sockaddr_storage)); if (buf == NULL) @@ -253,7 +257,7 @@ dispatch_imsg(void) for (h = hn; h != NULL; h = h->next) { imsg_add(buf, &h->ss, sizeof(h->ss)); } - imsg_close(&ibuf, buf); + imsg_close(ibuf, buf); } break; default: |