From f7faf7651c9e39ef73bdb70274b84487156944c7 Mon Sep 17 00:00:00 2001 From: Charles Forsyth Date: Tue, 17 Mar 2015 19:42:33 +0000 Subject: [PATCH] close log fd after dup2 to 2 --- u9fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/u9fs.c b/u9fs.c index 54989b7..cd30ea2 100644 --- a/u9fs.c +++ b/u9fs.c @@ -1785,8 +1785,11 @@ main(int argc, char **argv) if(fd < 0) sysfatal("cannot open log '%s'", logfile); - if(dup2(fd, 2) < 0) - sysfatal("cannot dup fd onto stderr"); + if(fd != 2){ + if(dup2(fd, 2) < 0) + sysfatal("cannot dup fd onto stderr"); + close(fd); + } fprint(2, "u9fs\nkill %d\n", (int)getpid()); fmtinstall('F', fcallconv);