Skip to contentSkip to conversation

Do not hang on full PTY

PATCH Applied Don Slutz 4 participants 7 messages Dec 22, 2014 – Jan 12, 2015

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

PATCH 1/1 Do not hang on full PTY

---
 qemu-char.c | 1 +
 1 file changed, 1 insertion(+)
qemu-char.c +1 -0
index ef84b53..6eec1d2 100644
@@ -1387,6 +1387,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
     }
 
     close(slave_fd);
+    qemu_set_nonblock(master_fd);
 
     chr = qemu_chr_alloc();
 
Signature · 1 line
1.8.4
#1 lore raw

qemu-char.c static CharDriverState *qemu_chr_open_pty(const char *id, · line 1392

Quoted 9 lines · Don Slutz
qemu-char.c +1 -0
@@ -1387,6 +1387,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
     }
 
     close(slave_fd);
+    qemu_set_nonblock(master_fd);
 
     chr = qemu_chr_alloc();

Hm. I'm not sure at all this is a trivial change. While the patch itself is trivial indeed, it changes behavour of the file descriptor significantly. Are all the places where this fd is subsequently used prepared for it being non-blocking? Oh well... ;)

Thanks,

/mjt

author
#2 lore raw
Quoted 10 lines · Michael Tokarev
Quoted 8 lines · Don Slutz
qemu-char.c +1 -0
@@ -1387,6 +1387,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
     }
 
     close(slave_fd);
+    qemu_set_nonblock(master_fd);
 
Quoted 7 lines

qemu-char.c static CharDriverState *qemu_chr_open_pty(const char *id, · line 1392

Quoted 1 line
qemu-char.c +0 -0
     chr = qemu_chr_alloc();

Hm. I'm not sure at all this is a trivial change. While the patch itself is trivial indeed, it changes behavour of the file descriptor significantly. Are all the places where this fd is subsequently used prepared for it being non-blocking? Oh well... ;)

I was not sure on this being trivial also, but it looked like it could be to me. The uses of this FD all looked that they handle non-blocking.

Here are the calls to qemu_set_nonblock in qemu-char.c (including this add) :

b qemu-char.c qemu_chr_open_fd 1070
qemu_set_nonblock(fd_out);
c qemu-char.c qemu_chr_open_stdio 1166
qemu_set_nonblock(0);
d qemu-char.c qemu_chr_open_pty 1390
qemu_set_nonblock(master_fd);
e qemu-char.c tcp_chr_add_client 2952
qemu_set_nonblock(fd);
f qemu-char.c qmp_chardev_open_serial 4060
qemu_set_nonblock(fd);
g qemu-char.c qmp_chardev_open_socket 4172
qemu_set_nonblock(s->listen_fd);

So there are many cases where the FD is non-blocking already.

Hope this info helps.

Quoted 5 lines

Thanks,

/mjt

#3 lore raw
Quoted 2 lines · Don Slutz

I was not sure on this being trivial also, but it looked like it could be to me. The uses of this FD all looked that they handle non-blocking.

Does g_io_channel_read_chars() definitely return G_IO_STATUS_NORMAL (and not, say, G_IO_STATUS_AGAIN) for an attempted read on a non-blocking fd with no data? Otherwise pty_chr_read() is going to call pty_chr_state(chr, 0) which I think means "the other end has hung up" and will take the fd out of the main loop's poll set.

thanks
-- PMM

author
#4 lore raw
Quoted 6 lines · Peter Maydell
Quoted 2 lines · Don Slutz

I was not sure on this being trivial also, but it looked like it could be to me. The uses of this FD all looked that they handle non-blocking.

Does g_io_channel_read_chars() definitely return G_IO_STATUS_NORMAL (and not, say, G_IO_STATUS_AGAIN) for an attempted read on a non-blocking fd with no data?

The only time I know of to get here in that state, is when the other end disconnects. Normally pty_chr_read will only be called when there is at least 1 character to read or a state change.

Quoted 3 lines

Otherwise pty_chr_read() is going to call
pty_chr_state(chr, 0) which I think means "the other end has hung up" and will take the fd out of the main loop's poll set.

Yes, that is correct. But it only happens when the other end disconnects. pty_chr_timer() also is involved here, so on a reconnect, the polling is re-enabled.

-Don Slutz

Quoted 3 lines

thanks
-- PMM

Reviewed-by
#5 lore raw
In reply to Peter Maydell
Quoted 7 lines · Peter Maydell
Quoted 2 lines · Don Slutz

I was not sure on this being trivial also, but it looked like it could be to me. The uses of this FD all looked that they handle non-blocking.

Does g_io_channel_read_chars() definitely return G_IO_STATUS_NORMAL (and not, say, G_IO_STATUS_AGAIN) for an attempted read on a non-blocking fd with no data?

It should return G_IO_STATUS_AGAIN. However, pty_chr_read() won't be called in the first place because the fd won't be readable and thus the chr->fd_in_tag GSource won't fire.

I think things more or less work right now just because PTYs are buffered in the kernel and there's no network involved, but Don's patch is good.

Michael, let me know if you're applying it yourself.

Paolo

Quoted 8 lines

Otherwise pty_chr_read() is going to call pty_chr_state(chr, 0) which I think means "the other end has hung up" and will take the fd out of the main loop's poll set.

thanks
-- PMM