Skip to content

Commit

Permalink
Fix broken pipe teardown.
Browse files Browse the repository at this point in the history
* Add missing close() calls to actually close the pipes, calling just
  msgbuf_clean() is not enough;
* Bring back some NOTREACHED lint comments. style(9) says they can be
  removed but in some cases they are useful to humans too;
* Add __dead to the shutdown functions;
* Some other minor changes to make eigrpd(8) more similar to the other
  routing daemons.
  • Loading branch information
rwestphal committed Sep 2, 2016
1 parent a42bb3c commit 1957d82
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
16 changes: 11 additions & 5 deletions eigrpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ main_sig_handler(int sig, short event, void *arg)
case SIGTERM:
case SIGINT:
eigrpd_shutdown();
/* NOTREACHED */
case SIGHUP:
if (eigrp_reload() == -1)
log_warnx("configuration reload failed");
Expand Down Expand Up @@ -272,6 +273,8 @@ main(int argc, char *argv[])
event_dispatch();

eigrpd_shutdown();
/* NOTREACHED */
return (0);
}

__dead void
Expand All @@ -280,16 +283,16 @@ eigrpd_shutdown(void)
pid_t pid;
int status;

/* close pipes */
msgbuf_clear(&iev_eigrpe->ibuf.w);
free(iev_eigrpe);
iev_eigrpe = NULL;
close(iev_eigrpe->ibuf.fd);
msgbuf_clear(&iev_rde->ibuf.w);
free(iev_rde);
iev_rde = NULL;
close(iev_rde->ibuf.fd);

config_clear(eigrpd_conf);
kr_shutdown();
config_clear(eigrpd_conf);

log_debug("waiting for children to terminate");
do {
pid = wait(&status);
if (pid == -1) {
Expand All @@ -301,6 +304,9 @@ eigrpd_shutdown(void)
"eigrp engine", WTERMSIG(status));
} while (pid != -1 || (pid == -1 && errno == EINTR));

free(iev_eigrpe);
free(iev_rde);

log_info("terminating");
exit(0);
}
Expand Down
17 changes: 10 additions & 7 deletions eigrpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "log.h"

void eigrpe_sig_handler(int, short, void *);
void eigrpe_shutdown(void);
__dead void eigrpe_shutdown(void);

static struct event ev4;
static struct event ev6;
Expand Down Expand Up @@ -173,11 +173,18 @@ eigrpe(int debug, int verbose, char *sockname)
return (0);
}

void
__dead void
eigrpe_shutdown(void)
{
control_cleanup(global.csock);
/* close pipes */
msgbuf_write(&iev_rde->ibuf.w);
msgbuf_clear(&iev_rde->ibuf.w);
close(iev_rde->ibuf.fd);
msgbuf_write(&iev_main->ibuf.w);
msgbuf_clear(&iev_main->ibuf.w);
close(iev_main->ibuf.fd);

control_cleanup(global.csock);
config_clear(econf);

event_del(&ev4);
Expand All @@ -186,11 +193,7 @@ eigrpe_shutdown(void)
close(global.eigrp_socket_v6);

/* clean up */
msgbuf_write(&iev_rde->ibuf.w);
msgbuf_clear(&iev_rde->ibuf.w);
free(iev_rde);
msgbuf_write(&iev_main->ibuf.w);
msgbuf_clear(&iev_main->ibuf.w);
free(iev_main);
free(pkt_ptr);

Expand Down
12 changes: 8 additions & 4 deletions rde.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "rde.h"

void rde_sig_handler(int sig, short, void *);
void rde_shutdown(void);
__dead void rde_shutdown(void);
void rde_dispatch_imsg(int, short, void *);
void rde_dispatch_parent(int, short, void *);

Expand Down Expand Up @@ -131,14 +131,18 @@ rde(int debug, int verbose)
return (0);
}

void
__dead void
rde_shutdown(void)
{
/* close pipes */
msgbuf_clear(&iev_eigrpe->ibuf.w);
close(iev_eigrpe->ibuf.fd);
msgbuf_clear(&iev_main->ibuf.w);
close(iev_main->ibuf.fd);

config_clear(rdeconf);

msgbuf_clear(&iev_eigrpe->ibuf.w);
free(iev_eigrpe);
msgbuf_clear(&iev_main->ibuf.w);
free(iev_main);

log_info("route decision engine exiting");
Expand Down

0 comments on commit 1957d82

Please sign in to comment.