tools/libxenstat: Fix infinite loop when QEMU dies
authorHans Reiser <hr@sec.uni-passau.de>
Mon, 9 Nov 2020 14:36:00 +0000 (14:36 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 22 Jan 2021 14:28:44 +0000 (14:28 +0000)
commitcd5058316c2ce4966fd7c2852216c47a0dc11618
tree87beee12215b43e5fcab9df3ec975ed8de706944
parentbb9afb7a465d3b7b438f2e11105409d24400f8f4
tools/libxenstat: Fix infinite loop when QEMU dies

Occasionally, "dead" xentop processes consuming 100% CPU time have been
observed.

When the QEMU process the qmp_read() function is communicating with
terminates, qmp_read() may enter an infinite loop.  poll() signals EOF (POLLIN
and POLLHUP set), the subsequent read() call returns 0, and then the function
calls poll() again, which still sees the EOF condition and will return again
immediately with POLLIN and POLLHUP set, repeating ad infinitum.

A simple fix is to terminate the loop when read returns 0 (under "normal"
instances, poll will return with POLLIN set only if there is data to read, so
read will always read >0 bytes, except if the socket has been closed).

Signed-off-by: Hans Reiser <hr@sec.uni-passau.de>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/libs/stat/xenstat_qmp.c