@@ -30,6 +30,7 @@
#include "qemu/sockets.h"
#include "qemu/error-report.h"
#include "qemu/module.h"
+#include "qemu/env.h"
#include "qemu/qemu-print.h"
#include "chardev/char-io.h"
@@ -188,12 +189,14 @@ static void char_pty_finalize(Object *obj)
Chardev *chr = CHARDEV(obj);
PtyChardev *s = PTY_CHARDEV(obj);
+ unsetenv_fd(chr->label);
pty_chr_state(chr, 0);
object_unref(OBJECT(s->ioc));
pty_chr_timer_cancel(s);
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
}
+
static void char_pty_open(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
@@ -204,19 +207,28 @@ static void char_pty_open(Chardev *chr,
char pty_name[PATH_MAX];
char *name;
+ master_fd = getenv_fd(chr->label);
+ if (master_fd >= 0) {
+ chr->filename = g_strdup_printf("pty:unknown");
+ goto have_fd;
+ }
+
master_fd = qemu_openpty_raw(&slave_fd, pty_name);
if (master_fd < 0) {
error_setg_errno(errp, errno, "Failed to create PTY");
return;
}
-
+ if (!chr->close_on_cpr) {
+ setenv_fd(chr->label, master_fd);
+ }
close(slave_fd);
qemu_set_nonblock(master_fd);
-
chr->filename = g_strdup_printf("pty:%s", pty_name);
qemu_printf("char device redirected to %s (label %s)\n",
pty_name, chr->label);
+have_fd:
+ qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR);
s = PTY_CHARDEV(chr);
s->ioc = QIO_CHANNEL(qio_channel_file_new_fd(master_fd));
name = g_strdup_printf("chardev-pty-%s", chr->label);
Save and restore pty descriptors across cprsave and cprload. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> --- chardev/char-pty.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)