From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Michael Tokarev <mjt@tls.msk.ru>
Subject: [Qemu-devel] [PATCH 1/3] do not chdir(/) in qemu-nbd before opening all files
Date: Fri, 17 Feb 2012 12:43:46 +0100 [thread overview]
Message-ID: <1329479028-27650-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1329479028-27650-1-git-send-email-pbonzini@redhat.com>
From: Michael Tokarev <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 <mjt@tls.msk.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
qemu-nbd.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index eb61c33..e189cf8 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -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));
--
1.7.7.6
next prev parent reply other threads:[~2012-02-17 11:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-17 11:43 [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Paolo Bonzini
2012-02-17 11:43 ` Paolo Bonzini [this message]
2012-02-17 11:43 ` [Qemu-devel] [PATCH 2/3] open /dev/nbd in nbd_client_thread Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 3/3] nbd: add git tree to MAINTAINERS Paolo Bonzini
2012-02-17 13:53 ` [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1329479028-27650-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).