Skip to content

Commit

Permalink
qemu-nbd: properly report error if qemu_daemon() is failed
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Denis V. Lunev authored and ebblake committed Jul 19, 2023
1 parent 5c56dd2 commit 1dc8215
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qemu-nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1dc8215

Please sign in to comment.