qemu-nbd: Do not close stderr
authorMax Reitz <mreitz@redhat.com>
Wed, 8 May 2019 21:18:18 +0000 (23:18 +0200)
committerEric Blake <eblake@redhat.com>
Thu, 13 Jun 2019 13:50:47 +0000 (08:50 -0500)
We kept old_stderr specifically so we could keep emitting error message
on stderr.  However, qemu_daemon() closes stderr.  Therefore, we need to
dup() stderr to old_stderr before invoking qemu_daemon().

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190508211820.17851-4-mreitz@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
qemu-nbd.c

index 99377a3f14e28df90c7d03eef4afd279341dceb9..a8cb39e51043a9f2731e1c8df26cfe1d7a3835ee 100644 (file)
@@ -1004,10 +1004,11 @@ int main(int argc, char **argv)
             exit(EXIT_FAILURE);
         } else if (pid == 0) {
             close(stderr_fd[0]);
+
+            old_stderr = dup(STDERR_FILENO);
             ret = qemu_daemon(1, 0);
 
             /* Temporarily redirect stderr to the parent's pipe...  */
-            old_stderr = dup(STDERR_FILENO);
             dup2(stderr_fd[1], STDERR_FILENO);
             if (ret < 0) {
                 error_report("Failed to daemonize: %s", strerror(errno));