Received: from eggs.gnu.org ([140.186.70.92]:51662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RmnlH-0000av-LJ for qemu-devel@nongnu.org; Mon, 16 Jan 2012 09:42:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RmnlF-0000NB-JR for qemu-devel@nongnu.org; Mon, 16 Jan 2012 09:42:15 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:57060) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RmnlF-0000MQ-C8 for qemu-devel@nongnu.org; Mon, 16 Jan 2012 09:42:13 -0500 From: Michael Tokarev Date: Mon, 16 Jan 2012 18:37:44 +0400 Message-Id: <20120116144203.D36CF283@gandalf.tls.msk.ru> Subject: [Qemu-devel] [PATCH v2] do not chdir(/) in qemu-nbd before opening all files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , mjt@tls.msk.ru When qemu-nbd becomes a daemon it calls daemon(3) with nochdir=0, so daemon(3) changes current directory to /. But at this time, qemu-nbd did not open any user-specified files yet, so by changing current directory, all non-absolute paths becomes wrong. The solution is to pass nochdir=1 to daemon(3) function, and to chdir("/") after all init has been performed, before entering the main loop, -- just like a good daemon should do. This patch is applicable for -stable. Signed-Off-By: Michael Tokarev --- qemu-nbd.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index e76c782..b1b5ae6 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -431,3 +431,3 @@ int main(int argc, char **argv) close(stderr_fd[0]); - ret = qemu_daemon(0, 0); + ret = qemu_daemon(1, 0); @@ -529,2 +529,8 @@ int main(int argc, char **argv) + /* now when the initialization is (almost) complete, chdir("/") + * to free any busy filesystems */ + if (chdir("/") < 0) { + err(EXIT_FAILURE, "Could not chdir to root directory"); + } + do { -- 1.7.2.5