diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-05 19:10:25 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-05 19:10:25 +0000 |
commit | b23fd4b94033681d702393178a99a2a173e00950 (patch) | |
tree | da80f62677d9db5e93a4c5089f649f57e3f10d92 /usr.sbin | |
parent | 8633e7a422fd44a7026d84004d5478bd31c55c39 (diff) |
correctly handle SIGCHLD.
SIGCHLD does _not_ translate to "a child process went kaboom".
waitpid() and check status; if the child exited or terminated log & quit
ok claudio@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpd/bgpd.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 9b35693422d..a60a7a8c3d8 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.55 2004/01/05 18:21:51 henning Exp $ */ +/* $OpenBSD: bgpd.c,v 1.56 2004/01/05 19:10:24 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -38,6 +38,7 @@ void sighdlr(int); void usage(void); int main(int, char *[]); +int check_child(pid_t, const char *); int reconfigure(char *, struct bgpd_config *, struct mrt_config *, struct peer *); int dispatch_imsg(struct imsgbuf *, int, struct mrt_config *); @@ -47,6 +48,7 @@ int rfd = -1; volatile sig_atomic_t mrtdump = 0; volatile sig_atomic_t quit = 0; volatile sig_atomic_t reconfig = 0; +volatile sig_atomic_t sigchld = 0; struct imsgbuf ibuf_se; struct imsgbuf ibuf_rde; @@ -56,9 +58,11 @@ sighdlr(int sig) switch (sig) { case SIGTERM: case SIGINT: - case SIGCHLD: quit = 1; break; + case SIGCHLD: + sigchld = 1; + break; case SIGHUP: reconfig = 1; break; @@ -281,6 +285,14 @@ main(int argc, char *argv[]) reconfig = 0; } + if (sigchld) { + if (check_child(io_pid, "session engine")) + quit = 1; + if (check_child(rde_pid, "route decision engine")) + quit = 1; + sigchld = 0; + } + if (mrtdump == 1) { mrt_alrm(&mrtconf, &ibuf_rde); mrtdump = 0; @@ -310,6 +322,26 @@ main(int argc, char *argv[]) } int +check_child(pid_t pid, const char *pname) +{ + int status; + + if (waitpid(pid, &status, WNOHANG) > 0) { + if (WIFEXITED(status)) { + logit(LOG_CRIT, "Lost child: %s exited", pname); + return (1); + } + if (WIFSIGNALED(status)) { + logit(LOG_CRIT, "Lost child: %s terminated; signal %d", + pname, WTERMSIG(status)); + return (1); + } + } + + return (0); +} + +int reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc, struct peer *peer_l) { |