[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/5] qemu-nbd: properly report error on error in dup2() after
From: |
Eric Blake |
Subject: |
Re: [PATCH 3/5] qemu-nbd: properly report error on error in dup2() after qemu_daemon() |
Date: |
Tue, 18 Jul 2023 12:45:34 -0500 |
User-agent: |
NeoMutt/20230517 |
On Mon, Jul 17, 2023 at 04:55:42PM +0200, Denis V. Lunev wrote:
> We are trying to temporary redirect stderr of daemonized process to
temporarily
> a pipe to report a error and get failed. In that case we could not
> use error_report() helper, but should write the message directly into
> the problematic pipe.
>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Eric Blake <eblake@redhat.com>
> CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> qemu-nbd.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 186ce9474c..4450cc826b 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -937,7 +937,20 @@ int main(int argc, char **argv)
> ret = qemu_daemon(1, 0);
>
errno from qemu_daemon...
> /* Temporarily redirect stderr to the parent's pipe... */
> - dup2(stderr_fd[1], STDERR_FILENO);
> + if (dup2(stderr_fd[1], STDERR_FILENO) < 0) {
...is still potentially lost here...
> + char str[256];
> + snprintf(str, sizeof(str),
> + "%s: Failed to link stderr to the pipe: %s\n",
> + g_get_prgname(), strerror(errno));
> + /*
> + * We are unable to use error_report() here as we need to get
> + * stderr pointed to the parent's pipe. Write to that pipe
> + * manually.
> + */
> + ret = write(stderr_fd[1], str, strlen(str));
> + exit(EXIT_FAILURE);
> + }
> +
> if (ret < 0) {
> error_report("Failed to daemonize: %s", strerror(errno));
...before use here.
Patch 4/5 addresses that, but I'm inclined to just swap the order of
the two patches when applying the series in my NBD tree.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
- [PATCH v2 0/5] qemu-nbd: fix regression with qemu-nbd --fork run over ssh, Denis V. Lunev, 2023/07/17
- [PATCH 3/5] qemu-nbd: properly report error on error in dup2() after qemu_daemon(), Denis V. Lunev, 2023/07/17
- Re: [PATCH 3/5] qemu-nbd: properly report error on error in dup2() after qemu_daemon(),
Eric Blake <=
- [PATCH 2/5] qemu-nbd: fix regression with qemu-nbd --fork run over ssh, Denis V. Lunev, 2023/07/17
- [PATCH 5/5] qemu-nbd: handle dup2() error when qemu-nbd finished setup process, Denis V. Lunev, 2023/07/17
- [PATCH 1/5] qemu-nbd: pass structure into nbd_client_thread instead of plain char*, Denis V. Lunev, 2023/07/17
- [PATCH 4/5] qemu-nbd: properly report error if qemu_daemon() is failed, Denis V. Lunev, 2023/07/17
- [PATCH 6/5] qemu-nbd: make verbose bool and local variable in main(), Denis V. Lunev, 2023/07/17