]> git.proxmox.com Git - mirror_qemu.git/blobdiff - backends/tpm/tpm_util.c
tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR
[mirror_qemu.git] / backends / tpm / tpm_util.c
index a6e6d3e72f1598b49847f65d83cd78dd1ba31bae..1856589c3b77929f8aac06fd105632e426dee5c0 100644 (file)
@@ -112,12 +112,8 @@ static int tpm_util_request(int fd,
                             void *response,
                             size_t responselen)
 {
-    fd_set readfds;
+    GPollFD fds[1] = { {.fd = fd, .events = G_IO_IN } };
     int n;
-    struct timeval tv = {
-        .tv_sec = 1,
-        .tv_usec = 0,
-    };
 
     n = write(fd, request, requestlen);
     if (n < 0) {
@@ -127,11 +123,8 @@ static int tpm_util_request(int fd,
         return -EFAULT;
     }
 
-    FD_ZERO(&readfds);
-    FD_SET(fd, &readfds);
-
     /* wait for a second */
-    n = select(fd + 1, &readfds, NULL, NULL, &tv);
+    n = RETRY_ON_EINTR(g_poll(fds, 1, 1000));
     if (n != 1) {
         return -errno;
     }