From nobody Sun Sep 28 17:13:25 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757964928; cv=none; d=zohomail.com; s=zohoarc; b=lXT4zQLcOLdCnP+QzuQaOoVoutWpdLNqJ4YJd7soOpUC4G+ISdXcOBXDDWHc50B8xcFdX4jbLQ5tcOipVHMCsS4BLKGOx9xCLLZPsCQFga8ojc7qqOxfvyHct1Hdag2mDmDAcLlfN/Dy4rP5pkyShxA8oFUO8bPfX4jFw6GCaLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757964928; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hUqfmUSn/mZjfZQ9QHFz6axFHBATGjxge6kva+qLpew=; b=P/B3DZ6wJpq+dunpMMWtWVyEOtoBPqpFepVWo371vKnDRFNubprfwmk5lf0X7XHvy4/2upeGhyQoLlJwLjeAVb9BvtiKtOKaizusQxg/Ai1WrvD6uGD/BJee+N1BkUW3FRV0DBlmN4DSBpt5SDN9RQ8UOdMwvApd+FkYKlc7GJ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757964928092205.26714016020208; Mon, 15 Sep 2025 12:35:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uyEvx-00020j-OI; Mon, 15 Sep 2025 15:32:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uyEvk-0001rE-3m; Mon, 15 Sep 2025 15:32:04 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uyEvO-0001wa-NI; Mon, 15 Sep 2025 15:32:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 05006809BC; Mon, 15 Sep 2025 22:31:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:184::1:6]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AVVVql1FrOs0-xDAS6Xfu; Mon, 15 Sep 2025 22:31:21 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757964681; bh=hUqfmUSn/mZjfZQ9QHFz6axFHBATGjxge6kva+qLpew=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=jpp2ZGBJOMuJyRkg9nkJnnBhQz9ls5e7h5wjfLqapZI3oxFHUXgRo0pCNkBFjr7DH 1SIoGQiPNyTbjLiwcd1UBlPFODE/v5zuC3OfRIW1obtw6GYycvaoGZ+0Z1rsqPavvC Axuo3OT8y69X9ryYN3QAb1G5LOhPO6k3+BUXa2OI= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, peterx@redhat.com, qemu-block@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, marcandre.lureau@redhat.com, Paolo Bonzini Subject: [PATCH v4 11/12] chardev: qemu_chr_open_fd(): add errp Date: Mon, 15 Sep 2025 22:31:03 +0300 Message-ID: <20250915193105.230085-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250915193105.230085-1-vsementsov@yandex-team.ru> References: <20250915193105.230085-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757964929552116601 Every caller already support errp, let's go further. Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-fd.c | 12 ++++++++---- chardev/char-file.c | 6 +++++- chardev/char-pipe.c | 9 ++++++++- chardev/char-serial.c | 5 ++++- chardev/char-stdio.c | 7 +++++-- include/chardev/char-fd.h | 2 +- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/chardev/char-fd.c b/chardev/char-fd.c index 739dc68c36..4ee286f323 100644 --- a/chardev/char-fd.c +++ b/chardev/char-fd.c @@ -206,14 +206,16 @@ int qmp_chardev_open_file_source(char *src, int flags= , Error **errp) } =20 /* open a character device to a unix fd */ -void qemu_chr_open_fd(Chardev *chr, - int fd_in, int fd_out) +bool qemu_chr_open_fd(Chardev *chr, + int fd_in, int fd_out, Error **errp) { FDChardev *s =3D FD_CHARDEV(chr); g_autofree char *name =3D NULL; =20 if (fd_out >=3D 0) { - qemu_set_blocking(fd_out, false, &error_abort); + if (!qemu_set_blocking(fd_out, false, errp)) { + return false; + } } =20 if (fd_out =3D=3D fd_in && fd_in >=3D 0) { @@ -221,7 +223,7 @@ void qemu_chr_open_fd(Chardev *chr, name =3D g_strdup_printf("chardev-file-%s", chr->label); qio_channel_set_name(QIO_CHANNEL(s->ioc_in), name); s->ioc_out =3D QIO_CHANNEL(object_ref(s->ioc_in)); - return; + return true; } =20 if (fd_in >=3D 0) { @@ -236,6 +238,8 @@ void qemu_chr_open_fd(Chardev *chr, name =3D g_strdup_printf("chardev-file-out-%s", chr->label); qio_channel_set_name(QIO_CHANNEL(s->ioc_out), name); } + + return true; } =20 static void char_fd_class_init(ObjectClass *oc, const void *data) diff --git a/chardev/char-file.c b/chardev/char-file.c index a9e8c5e0d7..89e9cb849c 100644 --- a/chardev/char-file.c +++ b/chardev/char-file.c @@ -92,7 +92,11 @@ static void qmp_chardev_open_file(Chardev *chr, } } =20 - qemu_chr_open_fd(chr, in, out); + if (!qemu_chr_open_fd(chr, in, out, errp)) { + qemu_close(out); + qemu_close(in); + return; + } #endif } =20 diff --git a/chardev/char-pipe.c b/chardev/char-pipe.c index 3d1b0ce2d2..e9f3bb8290 100644 --- a/chardev/char-pipe.c +++ b/chardev/char-pipe.c @@ -150,7 +150,14 @@ static void qemu_chr_open_pipe(Chardev *chr, return; } } - qemu_chr_open_fd(chr, fd_in, fd_out); + + if (!qemu_chr_open_fd(chr, fd_in, fd_out, errp)) { + close(fd_in); + if (fd_out !=3D fd_in) { + close(fd_out); + } + return; + } } =20 #endif /* !_WIN32 */ diff --git a/chardev/char-serial.c b/chardev/char-serial.c index 1ff31dcde3..c622d758db 100644 --- a/chardev/char-serial.c +++ b/chardev/char-serial.c @@ -276,7 +276,10 @@ static void qmp_chardev_open_serial(Chardev *chr, } tty_serial_init(fd, 115200, 'N', 8, 1); =20 - qemu_chr_open_fd(chr, fd, fd); + if (!qemu_chr_open_fd(chr, fd, fd, errp)) { + close(fd); + return; + } } #endif /* __linux__ || __sun__ */ =20 diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index 193727e807..2568164a10 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -110,14 +110,17 @@ static void qemu_chr_open_stdio(Chardev *chr, if (!qemu_set_blocking(0, false, errp)) { return; } + + if (!qemu_chr_open_fd(chr, 0, 1, errp)) { + return; + } + atexit(term_exit); =20 memset(&act, 0, sizeof(act)); act.sa_handler =3D term_stdio_handler; sigaction(SIGCONT, &act, NULL); =20 - qemu_chr_open_fd(chr, 0, 1); - stdio_allow_signal =3D !opts->has_signal || opts->signal; qemu_chr_set_echo_stdio(chr, false); } diff --git a/include/chardev/char-fd.h b/include/chardev/char-fd.h index 9de0e440de..6fe43062ca 100644 --- a/include/chardev/char-fd.h +++ b/include/chardev/char-fd.h @@ -41,7 +41,7 @@ typedef struct FDChardev FDChardev; DECLARE_INSTANCE_CHECKER(FDChardev, FD_CHARDEV, TYPE_CHARDEV_FD) =20 -void qemu_chr_open_fd(Chardev *chr, int fd_in, int fd_out); +bool qemu_chr_open_fd(Chardev *chr, int fd_in, int fd_out, Error **errp); int qmp_chardev_open_file_source(char *src, int flags, Error **errp); =20 #endif /* CHAR_FD_H */ --=20 2.48.1