]> git.proxmox.com Git - qemu.git/commitdiff
do not chdir(/) in qemu-nbd before opening all files
authorMichael Tokarev <mjt@tls.msk.ru>
Mon, 16 Jan 2012 14:37:44 +0000 (18:37 +0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 17 Feb 2012 11:41:48 +0000 (12:41 +0100)
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 <mjt@tls.msk.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-nbd.c

index eb61c33acd490f3aa786db4b9388aa2823d17447..e189cf86f4c73469e8d375aaa7b3b5f721f3d893 100644 (file)
@@ -429,7 +429,7 @@ int main(int argc, char **argv)
         pid = fork();
         if (pid == 0) {
             close(stderr_fd[0]);
-            ret = qemu_daemon(0, 0);
+            ret = qemu_daemon(1, 0);
 
             /* Temporarily redirect stderr to the parent's pipe...  */
             dup2(stderr_fd[1], STDERR_FILENO);
@@ -527,6 +527,12 @@ int main(int argc, char **argv)
     qemu_set_fd_handler2(fd, nbd_can_accept, nbd_accept, NULL,
                          (void *)(uintptr_t)fd);
 
+    /* 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 {
         main_loop_wait(false);
     } while (!sigterm_reported && (persistent || !nbd_started || nb_fds > 0));