From 53462aad719011c969e21fb039acd595ba027b9e Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 23 Jul 2012 18:45:23 -0400 Subject: [PATCH] logsave: fix fd leak which could cause logsave to hang The logsave program is leaking a file descriptor when it forks and execs the program which forks a process which hangs around. In the case of /etc/init.d/checkroot, this would be fsck. This file descriptor never gets closed, so it's still present when fsck runs e2fsck, and then if e2fsck has its own logging enabled using (in /etc/e2fsck.conf): [options] log_dir = /mnt log_filename = e2fsck-%N.%h.INFO.%D-%T log_dir_wait = true then e2fsck will fork off a process waiting for /mnt to get remounted read/write. This causes logsave to never get an EOF from its pipe, so it hangs waiting for the read to fail --- which won't happen due to the file descriptor leak which is still being held open by e2fsck's forked child process. And so /etc/init.d/checkroot hangs, and the root file system never gets remounted read/write, and we deadlock. Fix the problem by closing the pipe fd so the logsave program doesn't end up leaking it to its descendent processes. Addresses-Debian-Bug: #682592 Signed-off-by: "Theodore Ts'o" --- misc/logsave.c | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/logsave.c b/misc/logsave.c index c37473c..e783546 100644 --- a/misc/logsave.c +++ b/misc/logsave.c @@ -190,6 +190,7 @@ static int run_program(char **argv) dup2(fds[1],1); /* fds[1] replaces stdout */ dup2(fds[1],2); /* fds[1] replaces stderr */ close(fds[0]); /* don't need this here */ + close(fds[1]); execvp(argv[0], argv); perror(argv[0]); -- 1.8.3.1