Commit 52302d72748bd6c574bf2fd7c8be7f19d12db467

Authored by bellard
1 parent 333190eb

fix the no device case


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@715 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 10 additions and 5 deletions
hw/serial.c
... ... @@ -123,10 +123,12 @@ static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val)
123 123 s->lsr &= ~UART_LSR_THRE;
124 124 serial_update_irq(s);
125 125  
126   - ch = val;
127   - do {
128   - ret = write(s->out_fd, &ch, 1);
129   - } while (ret != 1);
  126 + if (s->out_fd >= 0) {
  127 + ch = val;
  128 + do {
  129 + ret = write(s->out_fd, &ch, 1);
  130 + } while (ret != 1);
  131 + }
130 132 s->thr_ipending = 1;
131 133 s->lsr |= UART_LSR_THRE;
132 134 s->lsr |= UART_LSR_TEMT;
... ... @@ -267,7 +269,10 @@ SerialState *serial_init(int base, int irq, int fd)
267 269 register_ioport_write(base, 8, 1, serial_ioport_write, s);
268 270 register_ioport_read(base, 8, 1, serial_ioport_read, s);
269 271  
270   - if (fd != 0) {
  272 + if (fd < 0) {
  273 + /* no associated device */
  274 + s->out_fd = -1;
  275 + } else if (fd != 0) {
271 276 qemu_add_fd_read_handler(fd, serial_can_receive1, serial_receive1, s);
272 277 s->out_fd = fd;
273 278 } else {
... ...