qemu-nbd: properly report error if qemu_daemon() is failed

errno has been overwritten by dup2() just below qemu_daemon() and thus
improperly returned to the caller. Fix accordingly.

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Eric Blake <eblake@redhat.com>
CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-ID: <20230717145544.194786-5-den@openvz.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: reorder patch series]
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Denis V. Lunev 2023-07-17 16:55:43 +02:00 committed by Eric Blake
parent 5c56dd27a2
commit 1dc8215118

View File

@ -932,14 +932,17 @@ int main(int argc, char **argv)
error_report("Failed to fork: %s", strerror(errno));
exit(EXIT_FAILURE);
} else if (pid == 0) {
int saved_errno;
close(stderr_fd[0]);
ret = qemu_daemon(1, 0);
saved_errno = errno; /* dup2 will overwrite error below */
/* Temporarily redirect stderr to the parent's pipe... */
dup2(stderr_fd[1], STDERR_FILENO);
if (ret < 0) {
error_report("Failed to daemonize: %s", strerror(errno));
error_report("Failed to daemonize: %s", strerror(saved_errno));
exit(EXIT_FAILURE);
}