[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] tools/libxenstat: Fix infinite loop when QEMU dies
commit cd5058316c2ce4966fd7c2852216c47a0dc11618 Author: Hans Reiser <hr@xxxxxxxxxxxxxxxxx> AuthorDate: Mon Nov 9 14:36:00 2020 +0000 Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> CommitDate: Fri Jan 22 14:28:44 2021 +0000 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@xxxxxxxxxxxxxxxxx> Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- tools/libs/stat/xenstat_qmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libs/stat/xenstat_qmp.c b/tools/libs/stat/xenstat_qmp.c index 19b236e7b6..0c5748ba68 100644 --- a/tools/libs/stat/xenstat_qmp.c +++ b/tools/libs/stat/xenstat_qmp.c @@ -298,7 +298,7 @@ static int qmp_read(int qfd, unsigned char **qstats) pfd[0].events = POLLIN; while ((n = poll(pfd, 1, 10)) > 0) { if (pfd[0].revents & POLLIN) { - if ((n = read(qfd, buf, sizeof(buf))) < 0) { + if ((n = read(qfd, buf, sizeof(buf))) <= 0) { free(*qstats); return 0; } -- generated by git-patchbot for /home/xen/git/xen.git#staging
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |