From patchwork Thu Apr 15 21:41:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?VGhvbWFzIELDg8KkY2hsZXI=?= X-Patchwork-Id: 92969 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3FLncsO022545 for ; Thu, 15 Apr 2010 21:49:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757850Ab0DOVtf (ORCPT ); Thu, 15 Apr 2010 17:49:35 -0400 Received: from gerolde.archlinux.org ([66.211.214.132]:55015 "EHLO archlinux.org" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757831Ab0DOVtd (ORCPT ); Thu, 15 Apr 2010 17:49:33 -0400 Received: from localhost.localdomain (port-87-193-186-180.static.qsc.de [87.193.186.180]) by archlinux.org (Postfix) with ESMTPSA id DF62390153; Thu, 15 Apr 2010 17:41:23 -0400 (EDT) From: =?UTF-8?q?Thomas=20B=C3=A4chler?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, =?UTF-8?q?Thomas=20B=C3=A4chler?= Subject: [PATCH 2/2] Add a 'screen' backend to qemu-char.c Date: Thu, 15 Apr 2010 23:41:13 +0200 Message-Id: <1271367673-18975-2-git-send-email-thomas@archlinux.org> X-Mailer: git-send-email 1.7.0.5 In-Reply-To: <1271367673-18975-1-git-send-email-thomas@archlinux.org> References: <1271367673-18975-1-git-send-email-thomas@archlinux.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 15 Apr 2010 21:49:42 +0000 (UTC) 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 */ } },