diff options
author | Denis V. Lunev <den@openvz.org> | 2023-07-17 16:55:43 +0200 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2023-07-19 15:25:27 -0500 |
commit | 1dc8215118ca5b99669c3bf27082a365aef16ea6 (patch) | |
tree | 32152734d70a66447164fb2825ed74d8e7c07b8f /qemu-nbd.c | |
parent | 5c56dd27a2c905c9cf2472d2fd057621ce5fd00d (diff) |
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>
Diffstat (limited to 'qemu-nbd.c')
-rw-r--r-- | qemu-nbd.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/qemu-nbd.c b/qemu-nbd.c index 186ce9474c..5a8ae1f747 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -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); } |