From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH 1 of 13] Implement "info chardev" command. (Gerd Hoffmann)
Date: Mon, 2 Mar 2009 17:13:12 +0000 [thread overview]
Message-ID: <49AC13A8.5070002@eu.citrix.com> (raw)
Import "Implement "info chardev" command." from qemu
mainstream.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5575 c046a42c-6fe2-441c-8c8c-71466251a162
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
diff -r 4c26bca47749 gdbstub.c
--- a/gdbstub.c Mon Feb 09 10:40:12 2009 +0000
+++ b/gdbstub.c Mon Feb 16 11:08:06 2009 +0000
@@ -1852,7 +1852,7 @@
port = gdbstub_port_name;
}
- chr = qemu_chr_open(port);
+ chr = qemu_chr_open("gdb", port);
if (!chr)
return -1;
diff -r 4c26bca47749 hw/usb-serial.c
--- a/hw/usb-serial.c Mon Feb 09 10:40:12 2009 +0000
+++ b/hw/usb-serial.c Mon Feb 16 11:08:06 2009 +0000
@@ -521,6 +521,8 @@
USBSerialState *s;
CharDriverState *cdrv;
unsigned short vendorid = 0x0403, productid = 0x6001;
+ char label[32];
+ static int index;
while (*filename && *filename != ':') {
const char *p;
@@ -555,7 +557,8 @@
if (!s)
return NULL;
- cdrv = qemu_chr_open(filename);
+ snprintf(label, sizeof(label), "usbserial%d", index++);
+ cdrv = qemu_chr_open(label, filename);
if (!cdrv)
goto fail;
s->cs = cdrv;
diff -r 4c26bca47749 monitor.c
--- a/monitor.c Mon Feb 09 10:40:12 2009 +0000
+++ b/monitor.c Mon Feb 16 11:08:06 2009 +0000
@@ -1477,6 +1477,8 @@
"", "show the version of qemu" },
{ "network", "", do_info_network,
"", "show the network state" },
+ { "chardev", "", qemu_chr_info,
+ "", "show the character devices" },
{ "block", "", do_info_block,
"", "show the block devices" },
{ "blockstats", "", do_info_blockstats,
diff -r 4c26bca47749 qemu-char.h
--- a/qemu-char.h Mon Feb 09 10:40:12 2009 +0000
+++ b/qemu-char.h Mon Feb 16 11:08:06 2009 +0000
@@ -1,6 +1,7 @@
#ifndef QEMU_CHAR_H
#define QEMU_CHAR_H
+#include "sys-queue.h"
/* character device */
#define CHR_EVENT_BREAK 0 /* serial break char */
@@ -56,9 +57,12 @@
void *opaque;
int focus;
QEMUBH *bh;
+ char *label;
+ char *filename;
+ TAILQ_ENTRY(CharDriverState) next;
};
-CharDriverState *qemu_chr_open(const char *filename);
+CharDriverState *qemu_chr_open(const char *label, const char *filename);
void qemu_chr_close(CharDriverState *chr);
void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
@@ -73,6 +77,7 @@
int qemu_chr_can_read(CharDriverState *s);
void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
void qemu_chr_accept_input(CharDriverState *s);
+void qemu_chr_info(void);
/* async I/O support */
diff -r 4c26bca47749 vl.c
--- a/vl.c Mon Feb 09 10:40:12 2009 +0000
+++ b/vl.c Mon Feb 16 11:08:06 2009 +0000
@@ -2645,7 +2645,7 @@
CharDriverState *chr;
PtyCharDriver *s;
struct termios tty;
- int slave_fd;
+ int slave_fd, len;
#if defined(__OpenBSD__)
char pty_name[PATH_MAX];
#define q_ptsname(x) pty_name
@@ -2673,6 +2673,9 @@
tcsetattr(slave_fd, TCSAFLUSH, &tty);
close(slave_fd);
+ len = strlen(q_ptsname(s->fd)) + 5;
+ chr->filename = qemu_malloc(len);
+ snprintf(chr->filename, len, "pty:%s", q_ptsname(s->fd));
fprintf(stderr, "char device redirected to %s\n", q_ptsname(s->fd));
chr->opaque = s;
@@ -3829,88 +3832,113 @@
return NULL;
}
-CharDriverState *qemu_chr_open(const char *filename)
+static TAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs
+= TAILQ_HEAD_INITIALIZER(chardevs);
+
+CharDriverState *qemu_chr_open(const char *label, const char *filename)
{
const char *p;
+ CharDriverState *chr;
if (!strcmp(filename, "vc")) {
- return text_console_init(&display_state, 0);
- } else if (strstart(filename, "vc:", &p)) {
- return text_console_init(&display_state, p);
- } else if (!strcmp(filename, "null")) {
- return qemu_chr_open_null();
+ chr = text_console_init(&display_state, 0);
+ } else
+ if (strstart(filename, "vc:", &p)) {
+ chr = text_console_init(&display_state, p);
+ } else
+ if (!strcmp(filename, "null")) {
+ chr = qemu_chr_open_null();
} else
if (strstart(filename, "tcp:", &p)) {
- return qemu_chr_open_tcp(p, 0, 0);
+ chr = qemu_chr_open_tcp(p, 0, 0);
} else
if (strstart(filename, "telnet:", &p)) {
- return qemu_chr_open_tcp(p, 1, 0);
+ chr = qemu_chr_open_tcp(p, 1, 0);
} else
if (strstart(filename, "udp:", &p)) {
- return qemu_chr_open_udp(p);
+ chr = qemu_chr_open_udp(p);
} else
if (strstart(filename, "mon:", &p)) {
- CharDriverState *drv = qemu_chr_open(p);
- if (drv) {
- drv = qemu_chr_open_mux(drv);
- monitor_init(drv, !nographic);
- return drv;
- }
- printf("Unable to open driver: %s\n", p);
- return 0;
+ chr = qemu_chr_open(label, p);
+ if (chr) {
+ chr = qemu_chr_open_mux(chr);
+ monitor_init(chr, !nographic);
+ } else {
+ printf("Unable to open driver: %s\n", p);
+ }
} else
#ifndef _WIN32
if (strstart(filename, "unix:", &p)) {
- return qemu_chr_open_tcp(p, 0, 1);
+ chr = qemu_chr_open_tcp(p, 0, 1);
} else if (strstart(filename, "file:", &p)) {
- return qemu_chr_open_file_out(p);
+ chr = qemu_chr_open_file_out(p);
} else if (strstart(filename, "pipe:", &p)) {
- return qemu_chr_open_pipe(p);
+ chr = qemu_chr_open_pipe(p);
} else if (!strcmp(filename, "pty")) {
- return qemu_chr_open_pty();
+ chr = qemu_chr_open_pty();
} else if (!strcmp(filename, "stdio")) {
- return qemu_chr_open_stdio();
+ chr = qemu_chr_open_stdio();
} else
#if defined(__linux__)
if (strstart(filename, "/dev/parport", NULL)) {
- return qemu_chr_open_pp(filename);
+ chr = qemu_chr_open_pp(filename);
} else
#endif
#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__)
if (strstart(filename, "/dev/", NULL)) {
- return qemu_chr_open_tty(filename);
+ chr = qemu_chr_open_tty(filename);
} else
#endif
#else /* !_WIN32 */
if (strstart(filename, "COM", NULL)) {
- return qemu_chr_open_win(filename);
+ chr = qemu_chr_open_win(filename);
} else
if (strstart(filename, "pipe:", &p)) {
- return qemu_chr_open_win_pipe(p);
+ chr = qemu_chr_open_win_pipe(p);
} else
if (strstart(filename, "con:", NULL)) {
- return qemu_chr_open_win_con(filename);
+ chr = qemu_chr_open_win_con(filename);
} else
if (strstart(filename, "file:", &p)) {
- return qemu_chr_open_win_file_out(p);
+ chr = qemu_chr_open_win_file_out(p);
} else
#endif
#ifdef CONFIG_BRLAPI
if (!strcmp(filename, "braille")) {
- return chr_baum_init();
- } else
-#endif
- {
- return NULL;
- }
+ chr = chr_baum_init();
+ } else
+#endif
+ {
+ chr = NULL;
+ }
+
+ if (chr) {
+ if (!chr->filename)
+ chr->filename = qemu_strdup(filename);
+ chr->label = qemu_strdup(label);
+ TAILQ_INSERT_TAIL(&chardevs, chr, next);
+ }
+ return chr;
}
void qemu_chr_close(CharDriverState *chr)
{
+ TAILQ_REMOVE(&chardevs, chr, next);
if (chr->chr_close)
chr->chr_close(chr);
+ qemu_free(chr->filename);
+ qemu_free(chr->label);
qemu_free(chr);
+}
+
+void qemu_chr_info(void)
+{
+ CharDriverState *chr;
+
+ TAILQ_FOREACH(chr, &chardevs, next) {
+ term_printf("%s: filename=%s\n", chr->label, chr->filename);
+ }
}
#ifdef CONFIG_PASSTHROUGH
@@ -10062,7 +10090,7 @@
}
}
if (monitor_device) {
- monitor_hd = qemu_chr_open(monitor_device);
+ monitor_hd = qemu_chr_open("monitor", monitor_device);
if (!monitor_hd) {
fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
exit(1);
@@ -10073,7 +10101,9 @@
for(i = 0; i < MAX_SERIAL_PORTS; i++) {
const char *devname = serial_devices[i];
if (devname && strcmp(devname, "none")) {
- serial_hds[i] = qemu_chr_open(devname);
+ char label[32];
+ snprintf(label, sizeof(label), "serial%d", i);
+ serial_hds[i] = qemu_chr_open(label, devname);
if (!serial_hds[i]) {
fprintf(stderr, "qemu: could not open serial device '%s'\n",
devname);
@@ -10088,7 +10118,9 @@
for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
const char *devname = parallel_devices[i];
if (devname && strcmp(devname, "none")) {
- parallel_hds[i] = qemu_chr_open(devname);
+ char label[32];
+ snprintf(label, sizeof(label), "parallel%d", i);
+ parallel_hds[i] = qemu_chr_open(label, devname);
if (!parallel_hds[i]) {
fprintf(stderr, "qemu: could not open parallel device '%s'\n",
devname);
reply other threads:[~2009-03-02 17:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=49AC13A8.5070002@eu.citrix.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/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.