From: "Thomas Bächler" <thomas@archlinux.org>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, "Thomas Bächler" <thomas@archlinux.org>
Subject: [PATCH 2/2] Add a 'screen' backend to qemu-char.c
Date: Thu, 15 Apr 2010 23:41:13 +0200 [thread overview]
Message-ID: <1271367673-18975-2-git-send-email-thomas@archlinux.org> (raw)
In-Reply-To: <1271367673-18975-1-git-send-email-thomas@archlinux.org>
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
WARNING: multiple messages have this Message-ID (diff)
From: "Thomas Bächler" <thomas@archlinux.org>
To: qemu-devel@nongnu.org
Cc: "Thomas Bächler" <thomas@archlinux.org>, kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 2/2] Add a 'screen' backend to qemu-char.c
Date: Thu, 15 Apr 2010 23:41:13 +0200 [thread overview]
Message-ID: <1271367673-18975-2-git-send-email-thomas@archlinux.org> (raw)
In-Reply-To: <1271367673-18975-1-git-send-email-thomas@archlinux.org>
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
next prev parent reply other threads:[~2010-04-15 21:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Thomas Bächler [this message]
2010-04-15 21:41 ` [Qemu-devel] [PATCH 2/2] Add a 'screen' backend to qemu-char.c Thomas Bächler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1271367673-18975-2-git-send-email-thomas@archlinux.org \
--to=thomas@archlinux.org \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.