On Mon, Jul 17, 2023 at 04:55:44PM +0200, Denis V. Lunev wrote:
> Fail on error, we are in trouble.
> 
> Signed-off-by: Denis V. Lunev <[email protected]>
> CC: Eric Blake <[email protected]>
> CC: Vladimir Sementsov-Ogievskiy <[email protected]>
> ---
>  qemu-nbd.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index f27613cb57..cd0e965705 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -323,7 +323,12 @@ 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);
> +        int err = dup2(STDOUT_FILENO, STDERR_FILENO);
> +        if (err < 0) {

Shorter to drop the temporary variable, and just do:

   if (dup2(...) < 0) {

> +            error_report("Could not set stderr to /dev/null: %s",
> +                         strerror(errno));
> +            exit(EXIT_FAILURE);
> +        }
>      }

Either way,
Reviewed-by: Eric Blake <[email protected]>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


Reply via email to