chardev: qemu_chr_open_fd(): add errp

Every caller already support errp, let's go further.

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy
2025-09-16 16:14:00 +03:00
committed by Daniel P. Berrangé
parent 6f607941b1
commit 69620c091d
6 changed files with 31 additions and 10 deletions

View File

@@ -206,14 +206,16 @@ int qmp_chardev_open_file_source(char *src, int flags, Error **errp)
}
/* 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 = FD_CHARDEV(chr);
g_autofree char *name = NULL;
if (fd_out >= 0) {
qemu_set_blocking(fd_out, false, &error_abort);
if (!qemu_set_blocking(fd_out, false, errp)) {
return false;
}
}
if (fd_out == fd_in && fd_in >= 0) {
@@ -221,7 +223,7 @@ void qemu_chr_open_fd(Chardev *chr,
name = g_strdup_printf("chardev-file-%s", chr->label);
qio_channel_set_name(QIO_CHANNEL(s->ioc_in), name);
s->ioc_out = QIO_CHANNEL(object_ref(s->ioc_in));
return;
return true;
}
if (fd_in >= 0) {
@@ -236,6 +238,8 @@ void qemu_chr_open_fd(Chardev *chr,
name = g_strdup_printf("chardev-file-out-%s", chr->label);
qio_channel_set_name(QIO_CHANNEL(s->ioc_out), name);
}
return true;
}
static void char_fd_class_init(ObjectClass *oc, const void *data)

View File

@@ -92,7 +92,11 @@ static void qmp_chardev_open_file(Chardev *chr,
}
}
qemu_chr_open_fd(chr, in, out);
if (!qemu_chr_open_fd(chr, in, out, errp)) {
qemu_close(out);
qemu_close(in);
return;
}
#endif
}

View File

@@ -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 != fd_in) {
close(fd_out);
}
return;
}
}
#endif /* !_WIN32 */

View File

@@ -276,7 +276,10 @@ static void qmp_chardev_open_serial(Chardev *chr,
}
tty_serial_init(fd, 115200, 'N', 8, 1);
qemu_chr_open_fd(chr, fd, fd);
if (!qemu_chr_open_fd(chr, fd, fd, errp)) {
close(fd);
return;
}
}
#endif /* __linux__ || __sun__ */

View File

@@ -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);
memset(&act, 0, sizeof(act));
act.sa_handler = term_stdio_handler;
sigaction(SIGCONT, &act, NULL);
qemu_chr_open_fd(chr, 0, 1);
stdio_allow_signal = !opts->has_signal || opts->signal;
qemu_chr_set_echo_stdio(chr, false);
}

View File

@@ -41,7 +41,7 @@ typedef struct FDChardev FDChardev;
DECLARE_INSTANCE_CHECKER(FDChardev, FD_CHARDEV,
TYPE_CHARDEV_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);
int qmp_chardev_open_file_source(char *src, int flags, Error **errp);
#endif /* CHAR_FD_H */