In order to satisfy static checkers that we don't have an fd leak,
a9c61ffaf153 added a close() of c->pidfile_fd, amongst others. However,
it only close()s it in the case where we daemonize into the background.
While less universally useful in the foreground / non-daemon case, it's
perfectly reasonable to still have a pidfile. We'll still write it, and
we should still close it.
Cc: Jon Maloy
Fixes: a9c61ffaf153 ("util, passt: Close daemon-lifetime fds on exit to avoid Coverity warning")
Signed-off-by: David Gibson
---
passt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/passt.c b/passt.c
index 65a07d72..cc847ec2 100644
--- a/passt.c
+++ b/passt.c
@@ -420,11 +420,13 @@ int main(int argc, char **argv)
if (!c->foreground) {
__daemon(c->pidfile_fd, devnull_fd);
- close(c->pidfile_fd);
- c->pidfile_fd = -1;
log_stderr = false;
} else {
pidfile_write(c->pidfile_fd, getpid());
+ }
+
+ if (c->pidfile_fd >= 0) {
+ close(c->pidfile_fd);
c->pidfile_fd = -1;
}
--
2.55.0