From 784b81e3fa3bac56fe2fee195da01582d2e46305 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Tue, 3 Jan 2006 13:13:17 +0000 Subject: Move the signal handler flags check between the poll() call and the poll fd handling. Do not access poll fd in case of an error or timeout. With and OK dlg@ --- usr.sbin/bgpd/bgpd.c | 55 +++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 8f9de80e839..86d74c65a11 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.127 2005/12/24 14:11:13 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.128 2006/01/03 13:13:16 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -112,7 +112,7 @@ main(int argc, char *argv[]) pid_t io_pid = 0, rde_pid = 0, pid; char *conffile; int debug = 0; - int ch, timeout; + int ch, timeout, nfds; int pipe_m2s[2]; int pipe_m2r[2]; int pipe_s2r[2]; @@ -268,12 +268,38 @@ main(int argc, char *argv[]) if (timeout > MAX_TIMEOUT) timeout = MAX_TIMEOUT; - if (poll(pfd, POLL_MAX, timeout * 1000) == -1) + if ((nfds = poll(pfd, POLL_MAX, timeout * 1000)) == -1) if (errno != EINTR) { log_warn("poll error"); quit = 1; } + if (reconfig) { + reconfig = 0; + log_info("rereading config"); + reconfigure(conffile, &conf, &mrt_l, &peer_l, rules_l); + } + + if (sigchld) { + sigchld = 0; + if (check_child(io_pid, "session engine")) { + quit = 1; + io_pid = 0; + } + if (check_child(rde_pid, "route decision engine")) { + quit = 1; + rde_pid = 0; + } + } + + if (mrtdump == 1) { + mrtdump = 0; + mrt_handler(&mrt_l); + } + + if (nfds == -1 || nfds == 0) + continue; + if (pfd[PFD_PIPE_SESSION].revents & POLLOUT) if (msgbuf_write(&ibuf_se->w) < 0) { log_warn("pipe write error (to SE)"); @@ -300,29 +326,6 @@ main(int argc, char *argv[]) if (kr_dispatch_msg() == -1) quit = 1; } - - if (reconfig) { - reconfig = 0; - log_info("rereading config"); - reconfigure(conffile, &conf, &mrt_l, &peer_l, rules_l); - } - - if (sigchld) { - sigchld = 0; - if (check_child(io_pid, "session engine")) { - quit = 1; - io_pid = 0; - } - if (check_child(rde_pid, "route decision engine")) { - quit = 1; - rde_pid = 0; - } - } - - if (mrtdump == 1) { - mrtdump = 0; - mrt_handler(&mrt_l); - } } signal(SIGCHLD, SIG_IGN); -- cgit v1.2.3