Re: [diff] usr.sbin/smtpd: fix event handling upon exit
OK millert@ - todd
Re: [diff] usr.sbin/smtpd: fix event handling upon exit
Ping ? > On 14 Dec 2020, at 11:34, Gilles Chehade wrote: > > Hello, > > Upon termination, the parent process will call parent_shutdown() which will > in turn call mproc_clear() to properly terminate IPC with child processes. > > In mproc_clear(), event_del() is called but a check is lacking to ensure > event_add() was called prior to this. > > On OpenBSD, this doesn’t seem to cause any issue but on other systems with a > different libevent, calling event_del() without a matching event_add() either > causes a runtime warning or a crash upon exit. > > Gilles > > > diff --git a/usr.sbin/smtpd/mproc.c b/usr.sbin/smtpd/mproc.c > index bde229e1..dac38af2 100644 > --- a/usr.sbin/smtpd/mproc.c > +++ b/usr.sbin/smtpd/mproc.c > @@ -90,7 +90,8 @@ mproc_clear(struct mproc *p) > { > log_debug("debug: clearing p=%s, fd=%d, pid=%d", p->name, > p->imsgbuf.fd, p->pid); > > - event_del(>ev); > + if (p->events) > + event_del(>ev); > close(p->imsgbuf.fd); > imsg_clear(>imsgbuf); > } >
[diff] usr.sbin/smtpd: fix event handling upon exit
Hello, Upon termination, the parent process will call parent_shutdown() which will in turn call mproc_clear() to properly terminate IPC with child processes. In mproc_clear(), event_del() is called but a check is lacking to ensure event_add() was called prior to this. On OpenBSD, this doesn’t seem to cause any issue but on other systems with a different libevent, calling event_del() without a matching event_add() either causes a runtime warning or a crash upon exit. Gilles diff --git a/usr.sbin/smtpd/mproc.c b/usr.sbin/smtpd/mproc.c index bde229e1..dac38af2 100644 --- a/usr.sbin/smtpd/mproc.c +++ b/usr.sbin/smtpd/mproc.c @@ -90,7 +90,8 @@ mproc_clear(struct mproc *p) { log_debug("debug: clearing p=%s, fd=%d, pid=%d", p->name, p->imsgbuf.fd, p->pid); - event_del(>ev); + if (p->events) + event_del(>ev); close(p->imsgbuf.fd); imsg_clear(>imsgbuf); }