Skip to content

Commit

Permalink
qemu-nbd: handle dup2() error when qemu-nbd finished setup process
Browse files Browse the repository at this point in the history
Fail on error, we are in trouble.

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-6-den@openvz.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: avoid intermediate variable]
Signed-off-by: Eric Blake <eblake@redhat.com>
  • Loading branch information
Denis V. Lunev authored and ebblake committed Jul 19, 2023
1 parent e0892ce commit 173776f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions qemu-nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ static void *nbd_client_thread(void *arg)
opts->device, srcpath);
} else {
/* Close stderr so that the qemu-nbd process exits. */
dup2(STDOUT_FILENO, STDERR_FILENO);
if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) {
error_report("Could not set stderr to /dev/null: %s",
strerror(errno));
exit(EXIT_FAILURE);
}
}

if (nbd_client(fd) < 0) {
Expand Down Expand Up @@ -1171,7 +1175,11 @@ int main(int argc, char **argv)
}

if (fork_process) {
dup2(STDOUT_FILENO, STDERR_FILENO);
if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) {
error_report("Could not set stderr to /dev/null: %s",
strerror(errno));
exit(EXIT_FAILURE);
}
}

state = RUNNING;
Expand Down

0 comments on commit 173776f

Please sign in to comment.