Whamcloud - gitweb
logsave: fix fd leak which could cause logsave to hang
authorTheodore Ts'o <tytso@mit.edu>
Mon, 23 Jul 2012 22:45:23 +0000 (18:45 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 23 Jul 2012 22:45:23 +0000 (18:45 -0400)
commit53462aad719011c969e21fb039acd595ba027b9e
treead629ce818fe3513bdcfad45af430e72c6e61be4
parent89dd15db9fbcf289afca24751fb463245c5c6aee
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" <tytso@mit.edu>
misc/logsave.c