* [PATCH 1/2] qemu-char.c: Fix memory leaks in qemu_chr_open_pty when openpty fails @ 2010-04-15 21:41 ` Thomas Bächler 0 siblings, 0 replies; 4+ messages in thread From: Thomas Bächler @ 2010-04-15 21:41 UTC (permalink / raw) To: qemu-devel; +Cc: kvm, Thomas Bächler --- qemu-char.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 05df971..d845572 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -986,6 +986,8 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) s = qemu_mallocz(sizeof(PtyCharDriver)); if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) { + qemu_free(chr); + qemu_free(s); return NULL; } -- 1.7.0.5 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 1/2] qemu-char.c: Fix memory leaks in qemu_chr_open_pty when openpty fails @ 2010-04-15 21:41 ` Thomas Bächler 0 siblings, 0 replies; 4+ messages in thread From: Thomas Bächler @ 2010-04-15 21:41 UTC (permalink / raw) To: qemu-devel; +Cc: Thomas Bächler, kvm --- qemu-char.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 05df971..d845572 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -986,6 +986,8 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) s = qemu_mallocz(sizeof(PtyCharDriver)); if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) { + qemu_free(chr); + qemu_free(s); return NULL; } -- 1.7.0.5 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] Add a 'screen' backend to qemu-char.c 2010-04-15 21:41 ` [Qemu-devel] " Thomas Bächler @ 2010-04-15 21:41 ` Thomas Bächler -1 siblings, 0 replies; 4+ messages in thread From: Thomas Bächler @ 2010-04-15 21:41 UTC (permalink / raw) To: qemu-devel; +Cc: kvm, Thomas Bächler This backend uses the 'pty' backend, but attaches the pseudo tty to a screen. A user can use 'screen:name' as a char device in a qemu options and run 'screen -R name' to attach to it. This is very useful for running headless qemu/qemu-kvm machines, where you can create screen sessions for the qemu monitor and serial console. --- qemu-char.c | 33 +++++++++++++++++++++++++++++++-- qemu-config.c | 3 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index d845572..d82e4c6 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -973,7 +973,9 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) CharDriverState *chr; PtyCharDriver *s; struct termios tty; - int slave_fd, len; + int slave_fd, len, r; + const char *screensession; + char *cmd; #if defined(__OpenBSD__) || defined(__DragonFly__) char pty_name[PATH_MAX]; #define q_ptsname(x) pty_name @@ -1001,7 +1003,29 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) chr->filename = qemu_malloc(len); snprintf(chr->filename, len, "pty:%s", q_ptsname(s->fd)); qemu_opt_set(opts, "path", q_ptsname(s->fd)); - fprintf(stderr, "char device redirected to %s\n", q_ptsname(s->fd)); + + if((screensession = qemu_opt_get(opts, "screen")) != NULL) { + if(strlen(screensession) == 0) { + qemu_free(chr); + qemu_free(s); + return NULL; + } + len = strlen(screensession) + strlen(q_ptsname(s->fd)) + 20; + cmd = qemu_malloc(len); + snprintf(cmd, len, "screen -S '%s' -dm '%s'", screensession, q_ptsname(s->fd)); + r = system(cmd); + qemu_free(cmd); + if(r == -1 || WEXITSTATUS(r) != 0) { + fprintf(stderr, "failed to launch screen\n"); + qemu_free(chr); + qemu_free(s); + return NULL; + } else { + fprintf(stderr, "char device attached to screen session %s\n", screensession); + } + } else { + fprintf(stderr, "char device redirected to %s\n", q_ptsname(s->fd)); + } chr->opaque = s; chr->chr_write = pty_chr_write; @@ -2343,6 +2367,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) qemu_opt_set(opts, "path", p); return opts; } + if (strstart(filename, "screen:", &p)) { + qemu_opt_set(opts, "backend", "pty"); + qemu_opt_set(opts, "screen", p); + return opts; + } if (strstart(filename, "tcp:", &p) || strstart(filename, "telnet:", &p)) { if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) { diff --git a/qemu-config.c b/qemu-config.c index 150157c..8ebf219 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -146,6 +146,9 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "signal", .type = QEMU_OPT_BOOL, + },{ + .name = "screen", + .type = QEMU_OPT_STRING, }, { /* end if list */ } }, -- 1.7.0.5 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/2] Add a 'screen' backend to qemu-char.c @ 2010-04-15 21:41 ` Thomas Bächler 0 siblings, 0 replies; 4+ messages in thread From: Thomas Bächler @ 2010-04-15 21:41 UTC (permalink / raw) To: qemu-devel; +Cc: Thomas Bächler, kvm This backend uses the 'pty' backend, but attaches the pseudo tty to a screen. A user can use 'screen:name' as a char device in a qemu options and run 'screen -R name' to attach to it. This is very useful for running headless qemu/qemu-kvm machines, where you can create screen sessions for the qemu monitor and serial console. --- qemu-char.c | 33 +++++++++++++++++++++++++++++++-- qemu-config.c | 3 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index d845572..d82e4c6 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -973,7 +973,9 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) CharDriverState *chr; PtyCharDriver *s; struct termios tty; - int slave_fd, len; + int slave_fd, len, r; + const char *screensession; + char *cmd; #if defined(__OpenBSD__) || defined(__DragonFly__) char pty_name[PATH_MAX]; #define q_ptsname(x) pty_name @@ -1001,7 +1003,29 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) chr->filename = qemu_malloc(len); snprintf(chr->filename, len, "pty:%s", q_ptsname(s->fd)); qemu_opt_set(opts, "path", q_ptsname(s->fd)); - fprintf(stderr, "char device redirected to %s\n", q_ptsname(s->fd)); + + if((screensession = qemu_opt_get(opts, "screen")) != NULL) { + if(strlen(screensession) == 0) { + qemu_free(chr); + qemu_free(s); + return NULL; + } + len = strlen(screensession) + strlen(q_ptsname(s->fd)) + 20; + cmd = qemu_malloc(len); + snprintf(cmd, len, "screen -S '%s' -dm '%s'", screensession, q_ptsname(s->fd)); + r = system(cmd); + qemu_free(cmd); + if(r == -1 || WEXITSTATUS(r) != 0) { + fprintf(stderr, "failed to launch screen\n"); + qemu_free(chr); + qemu_free(s); + return NULL; + } else { + fprintf(stderr, "char device attached to screen session %s\n", screensession); + } + } else { + fprintf(stderr, "char device redirected to %s\n", q_ptsname(s->fd)); + } chr->opaque = s; chr->chr_write = pty_chr_write; @@ -2343,6 +2367,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) qemu_opt_set(opts, "path", p); return opts; } + if (strstart(filename, "screen:", &p)) { + qemu_opt_set(opts, "backend", "pty"); + qemu_opt_set(opts, "screen", p); + return opts; + } if (strstart(filename, "tcp:", &p) || strstart(filename, "telnet:", &p)) { if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) { diff --git a/qemu-config.c b/qemu-config.c index 150157c..8ebf219 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -146,6 +146,9 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "signal", .type = QEMU_OPT_BOOL, + },{ + .name = "screen", + .type = QEMU_OPT_STRING, }, { /* end if list */ } }, -- 1.7.0.5 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-04-15 21:49 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-04-15 21:41 [PATCH 1/2] qemu-char.c: Fix memory leaks in qemu_chr_open_pty when openpty fails Thomas Bächler 2010-04-15 21:41 ` [Qemu-devel] " Thomas Bächler 2010-04-15 21:41 ` [PATCH 2/2] Add a 'screen' backend to qemu-char.c Thomas Bächler 2010-04-15 21:41 ` [Qemu-devel] " Thomas Bächler
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.