Revision d59044ef qemu-char.c
b/qemu-char.c | ||
---|---|---|
1230 | 1230 |
} |
1231 | 1231 |
} |
1232 | 1232 |
|
1233 |
static CharDriverState *qemu_chr_open_tty_fd(int fd) |
|
1234 |
{ |
|
1235 |
CharDriverState *chr; |
|
1236 |
|
|
1237 |
tty_serial_init(fd, 115200, 'N', 8, 1); |
|
1238 |
chr = qemu_chr_open_fd(fd, fd); |
|
1239 |
chr->chr_ioctl = tty_serial_ioctl; |
|
1240 |
chr->chr_close = qemu_chr_close_tty; |
|
1241 |
return chr; |
|
1242 |
} |
|
1243 |
|
|
1233 | 1244 |
static CharDriverState *qemu_chr_open_tty(QemuOpts *opts) |
1234 | 1245 |
{ |
1235 | 1246 |
const char *filename = qemu_opt_get(opts, "path"); |
1236 |
CharDriverState *chr; |
|
1237 | 1247 |
int fd; |
1238 | 1248 |
|
1239 | 1249 |
TFR(fd = qemu_open(filename, O_RDWR | O_NONBLOCK)); |
1240 | 1250 |
if (fd < 0) { |
1241 | 1251 |
return NULL; |
1242 | 1252 |
} |
1243 |
tty_serial_init(fd, 115200, 'N', 8, 1); |
|
1244 |
chr = qemu_chr_open_fd(fd, fd); |
|
1245 |
chr->chr_ioctl = tty_serial_ioctl; |
|
1246 |
chr->chr_close = qemu_chr_close_tty; |
|
1247 |
return chr; |
|
1253 |
return qemu_chr_open_tty_fd(fd); |
|
1248 | 1254 |
} |
1249 | 1255 |
#endif /* __linux__ || __sun__ */ |
1250 | 1256 |
|
... | ... | |
1666 | 1672 |
return 0; |
1667 | 1673 |
} |
1668 | 1674 |
|
1669 |
static CharDriverState *qemu_chr_open_win(QemuOpts *opts)
|
|
1675 |
static CharDriverState *qemu_chr_open_win_path(const char *filename)
|
|
1670 | 1676 |
{ |
1671 |
const char *filename = qemu_opt_get(opts, "path"); |
|
1672 | 1677 |
CharDriverState *chr; |
1673 | 1678 |
WinCharState *s; |
1674 | 1679 |
|
... | ... | |
1687 | 1692 |
return chr; |
1688 | 1693 |
} |
1689 | 1694 |
|
1695 |
static CharDriverState *qemu_chr_open_win(QemuOpts *opts) |
|
1696 |
{ |
|
1697 |
return qemu_chr_open_win_path(qemu_opt_get(opts, "path")); |
|
1698 |
} |
|
1699 |
|
|
1690 | 1700 |
static int win_chr_pipe_poll(void *opaque) |
1691 | 1701 |
{ |
1692 | 1702 |
CharDriverState *chr = opaque; |
... | ... | |
2765 | 2775 |
#endif |
2766 | 2776 |
#ifdef HAVE_CHARDEV_TTY |
2767 | 2777 |
{ .name = "tty", .open = qemu_chr_open_tty }, |
2778 |
{ .name = "serial", .open = qemu_chr_open_tty }, |
|
2768 | 2779 |
{ .name = "pty", .open = qemu_chr_open_pty }, |
2769 | 2780 |
#endif |
2770 | 2781 |
#ifdef HAVE_CHARDEV_PARPORT |
... | ... | |
3031 | 3042 |
return qemu_chr_open_win_file(out); |
3032 | 3043 |
} |
3033 | 3044 |
|
3045 |
static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp) |
|
3046 |
{ |
|
3047 |
switch (port->type) { |
|
3048 |
case CHARDEV_PORT_KIND_SERIAL: |
|
3049 |
return qemu_chr_open_win_path(port->device); |
|
3050 |
default: |
|
3051 |
error_setg(errp, "unknown chardev port (%d)", port->type); |
|
3052 |
return NULL; |
|
3053 |
} |
|
3054 |
} |
|
3055 |
|
|
3034 | 3056 |
#else /* WIN32 */ |
3035 | 3057 |
|
3036 | 3058 |
static int qmp_chardev_open_file_source(char *src, int flags, |
... | ... | |
3067 | 3089 |
return qemu_chr_open_fd(in, out); |
3068 | 3090 |
} |
3069 | 3091 |
|
3092 |
static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp) |
|
3093 |
{ |
|
3094 |
int flags, fd; |
|
3095 |
|
|
3096 |
switch (port->type) { |
|
3097 |
#ifdef HAVE_CHARDEV_TTY |
|
3098 |
case CHARDEV_PORT_KIND_SERIAL: |
|
3099 |
flags = O_RDWR; |
|
3100 |
fd = qmp_chardev_open_file_source(port->device, flags, errp); |
|
3101 |
if (error_is_set(errp)) { |
|
3102 |
return NULL; |
|
3103 |
} |
|
3104 |
socket_set_nonblock(fd); |
|
3105 |
return qemu_chr_open_tty_fd(fd); |
|
3106 |
#endif |
|
3107 |
default: |
|
3108 |
error_setg(errp, "unknown chardev port (%d)", port->type); |
|
3109 |
return NULL; |
|
3110 |
} |
|
3111 |
} |
|
3112 |
|
|
3070 | 3113 |
#endif /* WIN32 */ |
3071 | 3114 |
|
3072 | 3115 |
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, |
... | ... | |
3086 | 3129 |
case CHARDEV_BACKEND_KIND_FILE: |
3087 | 3130 |
chr = qmp_chardev_open_file(backend->file, errp); |
3088 | 3131 |
break; |
3132 |
case CHARDEV_BACKEND_KIND_PORT: |
|
3133 |
chr = qmp_chardev_open_port(backend->port, errp); |
|
3134 |
break; |
|
3089 | 3135 |
case CHARDEV_BACKEND_KIND_NULL: |
3090 | 3136 |
chr = qemu_chr_open_null(NULL); |
3091 | 3137 |
break; |
Also available in: Unified diff