summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2003-12-23 18:28:06 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2003-12-23 18:28:06 +0000
commitb6c69be74bf645bc3a3321ca0cf25e76d94b2d4c (patch)
tree7c72bc6dae10f956173d26c09d662878f4ba5146 /usr.sbin
parent9b96eff6adfd956d1e6536adc2bae1e2ebc95571 (diff)
send shutdown requests to the child processes and wait for a ackmessage from
them when shutting down. the rde needs the main process to clean up the routing table on exit so the parent process needs to be in service until the RDE is done. ok claudio@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/bgpd.c25
-rw-r--r--usr.sbin/bgpd/bgpd.h6
-rw-r--r--usr.sbin/bgpd/rde.c6
-rw-r--r--usr.sbin/bgpd/session.c23
4 files changed, 47 insertions, 13 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index 41524c49e32..7fe3f8fa382 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.19 2003/12/22 21:48:23 henning Exp $ */
+/* $OpenBSD: bgpd.c,v 1.20 2003/12/23 18:28:05 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -47,6 +47,11 @@ volatile sig_atomic_t quit = 0;
volatile sig_atomic_t reconfig = 0;
struct imsgbuf ibuf_se;
struct imsgbuf ibuf_rde;
+int se_done = 0;
+int rde_done = 0;
+
+#define QUIT_REQUESTED 1
+#define QUIT_INPROGRESS 2
void
sighdlr(int sig)
@@ -55,7 +60,7 @@ sighdlr(int sig)
case SIGTERM:
case SIGINT:
case SIGCHLD:
- quit = 1;
+ quit = QUIT_REQUESTED;
break;
case SIGHUP:
reconfig = 1;
@@ -194,7 +199,7 @@ main(int argc, char *argv[])
imsg_init(&ibuf_rde, pipe_m2r[0]);
rfd = kroute_init();
- while (quit == 0) {
+ while (quit != QUIT_INPROGRESS || se_done == 0 || rde_done == 0) {
pfd[PFD_PIPE_SESSION].fd = ibuf_se.sock;
pfd[PFD_PIPE_SESSION].events = POLLIN;
if (ibuf_se.w.queued)
@@ -248,6 +253,14 @@ main(int argc, char *argv[])
reconfig = 0;
}
+ if (quit == QUIT_REQUESTED) {
+ imsg_compose(&ibuf_se, IMSG_SHUTDOWN_REQUEST, 0,
+ NULL, 0);
+ imsg_compose(&ibuf_rde, IMSG_SHUTDOWN_REQUEST, 0,
+ NULL, 0);
+ quit = QUIT_INPROGRESS;
+ }
+
if (mrtdump == 1) {
mrt_alrm(&mrtconf, &ibuf_rde);
mrtdump = 0;
@@ -350,6 +363,12 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct mrt_config *conf)
if (kroute_delete(rfd, imsg.data))
fatal("kroute bytes left", 0);
break;
+ case IMSG_SHUTDOWN_DONE:
+ if (idx == PFD_PIPE_ROUTE)
+ rde_done = 1;
+ else
+ se_done = 1;
+ break;
default:
break;
}
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 5502ddb6762..0dbc1a49896 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.14 2003/12/23 01:06:21 henning Exp $ */
+/* $OpenBSD: bgpd.h,v 1.15 2003/12/23 18:28:05 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -211,7 +211,9 @@ enum imsg_type {
IMSG_MRT_END,
IMSG_KROUTE_ADD,
IMSG_KROUTE_CHANGE,
- IMSG_KROUTE_DELETE
+ IMSG_KROUTE_DELETE,
+ IMSG_SHUTDOWN_REQUEST,
+ IMSG_SHUTDOWN_DONE
};
struct imsg_hdr {
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 4580791503e..5355191b83d 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.19 2003/12/23 15:59:02 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.20 2003/12/23 18:28:05 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -253,6 +253,10 @@ rde_dispatch_imsg(struct imsgbuf *ibuf, int idx)
imsg_compose(&ibuf_main, IMSG_MRT_END,
imsg.hdr.peerid, NULL, 0);
break;
+ case IMSG_SHUTDOWN_REQUEST:
+ imsg_compose(&ibuf_main, IMSG_SHUTDOWN_DONE, 0,
+ NULL, 0);
+ break;
default:
break;
}
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index b8587a8a851..146daab0d4c 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.29 2003/12/23 16:11:06 henning Exp $ */
+/* $OpenBSD: session.c,v 1.30 2003/12/23 18:28:05 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -81,6 +81,7 @@ struct peer *getpeerbyip(in_addr_t);
struct bgpd_config *conf = NULL, *nconf = NULL;
volatile sig_atomic_t session_quit = 0;
int pending_reconf = 0;
+int sock = -1;
struct imsgbuf ibuf_rde;
struct imsgbuf ibuf_main;
@@ -126,7 +127,7 @@ setup_listener(void)
int
session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2])
{
- int sock, nfds, i, j, timeout;
+ int nfds, i, j, timeout;
pid_t pid;
time_t nextaction;
struct passwd *pw;
@@ -175,8 +176,10 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2])
while (session_quit == 0) {
bzero(&pfd, sizeof(pfd));
- pfd[PFD_LISTEN].fd = sock;
- pfd[PFD_LISTEN].events = POLLIN;
+ if (sock != -1) {
+ pfd[PFD_LISTEN].fd = sock;
+ pfd[PFD_LISTEN].events = POLLIN;
+ }
pfd[PFD_PIPE_MAIN].fd = ibuf_main.sock;
pfd[PFD_PIPE_MAIN].events = POLLIN;
pfd[PFD_PIPE_ROUTE].fd = ibuf_rde.sock;
@@ -281,9 +284,6 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2])
}
}
- session_terminate();
- shutdown(sock, SHUT_RDWR);
- close(sock);
logit(LOG_INFO, "session engine exiting");
_exit(0);
}
@@ -561,6 +561,10 @@ session_terminate(void)
for (p = conf->peers; p != NULL; p = p->next)
bgp_fsm(p, EVNT_STOP);
+
+ shutdown(sock, SHUT_RDWR);
+ close(sock);
+ sock = -1;
}
void
@@ -1279,6 +1283,11 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx)
pending_reconf = 0;
logit(LOG_INFO, "SE reconfigured");
break;
+ case IMSG_SHUTDOWN_REQUEST:
+ session_terminate();
+ imsg_compose(&ibuf_main, IMSG_SHUTDOWN_DONE, 0,
+ NULL, 0);
+ break;
default:
}
imsg_free(&imsg);