qemu-nbd: Do not close stderr

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>
This commit is contained in:
Max Reitz 2019-05-08 23:18:18 +02:00 committed by Eric Blake
parent 6177b58431
commit e6df58a557

View File

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