Skip to contentSkip to conversation

qemu-char: retry g_poll on EINTR

PATCH In review Paolo Bonzini 2 participants 2 messages Dec 1, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-char: retry g_poll on EINTR

This is a case where pty_chr_update_read_handler_locked's lack of error checking can produce incorrect values. We are not using SIGUSR1 anymore, so this is quite theoretical, but easy to fix.

---
 qemu-char.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
qemu-char.c +6 -1
index 5448b0f..2969c44 100644
@@ -1241,11 +1241,16 @@ static void pty_chr_update_read_handler_locked(CharDriverState *chr)
 {
     PtyCharDriver *s = chr->opaque;
     GPollFD pfd;
+    int rc;
 
     pfd.fd = g_io_channel_unix_get_fd(s->fd);
     pfd.events = G_IO_OUT;
     pfd.revents = 0;
-    g_poll(&pfd, 1, 0);
+    do {
+        rc = g_poll(&pfd, 1, 0);
+    } while (rc == -1 && errno == EINTR);
+    assert(rc >= 0);
+
     if (pfd.revents & G_IO_HUP) {
         pty_chr_state(chr, 0);
     } else {
Signature · 1 line
2.5.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Paolo Bonzini

This is a case where pty_chr_update_read_handler_locked's lack of error checking can produce incorrect values. We are not using SIGUSR1 anymore, so this is quite theoretical, but easy to fix.

---
 qemu-char.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
qemu-char.c +0 -0
index 5448b0f..2969c44 100644
@@ -1241,11 +1241,16 @@ static void pty_chr_update_read_handler_locked(CharDriverState *chr)
 {
     PtyCharDriver *s = chr->opaque;

qemu-char.c static void pty_chr_update_read_handler_locked(CharDriverState *chr) · line 1251

Quoted 10 lines
qemu-char.c +4 -1
     GPollFD pfd;
+    int rc;
 
     pfd.fd = g_io_channel_unix_get_fd(s->fd);
     pfd.events = G_IO_OUT;
     pfd.revents = 0;
-    g_poll(&pfd, 1, 0);
+    do {
+        rc = g_poll(&pfd, 1, 0);
+    } while (rc == -1 && errno == EINTR);

Could use TFR(), but that's a matter of taste. Both ways aleady exist in this file.

qemu-char.c static void pty_chr_update_read_handler_locked(CharDriverState *chr) · line 1252

Quoted 1 line
qemu-char.c +1 -0
+    assert(rc >= 0);

Documented errors other than EINTR:

EFAULT The array given as argument was not contained in the
calling program's address space.

EINVAL The nfds value exceeds the RLIMIT_NOFILE value.

ENOMEM There was no space to allocate file descriptor tables.

Aborting feels okay to me.

qemu-char.c static void pty_chr_update_read_handler_locked(CharDriverState *chr) · line 1256

Quoted 4 lines
qemu-char.c +1 -0
+
     if (pfd.revents & G_IO_HUP) {
         pty_chr_state(chr, 0);
     } else {