dup2 creates a new reference to a fd, so we have to close the old reference.

Signed-off-by: Christoph Hellwig <h...@lst.de>

---
 lib/logger.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Index: sheepdog/lib/logger.c
===================================================================
--- sheepdog.orig/lib/logger.c  2012-08-06 16:50:37.616672987 +0200
+++ sheepdog/lib/logger.c       2012-08-06 16:50:42.416672989 +0200
@@ -356,11 +356,16 @@ static notrace void rotate_log(void)
                rename(log_nowname, old_logfile);
        }
        new_fd = open(log_nowname, O_RDWR | O_CREAT | O_APPEND, 0644);
-       if (new_fd < 0)
-               syslog(LOG_ERR, "fail to create new log file\n");
+       if (new_fd < 0) {
+               syslog(LOG_ERR, "failed to create new log file\n");
+               exit(1);
+       }
 
-       dup2(new_fd, la->fd);
-       la->fd = new_fd;
+       if (dup2(new_fd, la->fd) < 0) {
+               syslog(LOG_ERR, "failed to dup2 the log fd\n");
+               exit(1);
+       }
+       close(new_fd);
 }
 
 notrace void log_write(int prio, const char *func, int line, const char *fmt, 
...)

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to