libxl_qmp: Handle unexpected end-of-socket
PATCH 1/1 libxl_qmp: Handle unexpected end-of-socket
When read() return 0, the current code just tries again. But this leads to an infinite loop if QEMU died too soon.
Also, retry select if a signal was caught.
--- tools/libxl/libxl_qmp.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
tools/libxl/libxl_qmp.c +5 -1
@@ -385,18 +385,22 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)FD_ZERO (&rfds);FD_SET (qmp->qmp_fd, &rfds); +do_select_again: ret =select (qmp->qmp_fd +1 , &rfds,NULL ,NULL , &timeout);if (ret ==0 ) {LIBXL__LOG (qmp->ctx,LIBXL__LOG_ERROR ,"timeout" );return -1 ; }else if (ret <0 ) { +if (errno ==EINTR ) + goto do_select_again;LIBXL__LOG_ERRNO (qmp->ctx,LIBXL__LOG_ERROR ,"Select error" );return -1 ; } rd =read (qmp->qmp_fd, qmp->buffer,QMP_RECEIVE_BUFFER_SIZE );if (rd ==0 ) { -continue ; +LIBXL__LOG (qmp->ctx,LIBXL__LOG_ERROR ,"Unexpected end of socket" ); +return -1 ; }else if (rd <0 ) {LIBXL__LOG_ERRNO (qmp->ctx,LIBXL__LOG_ERROR ,"Socket read error" );return rd;
Signature · 1 line
tg: (6674c38..) fix/qmp-end-of-socket (depends on: master)
Anthony PERARD writes ("[Xen-devel] [PATCH] libxl_qmp: Handle unexpected end-of-socket"):
Quoted 2 lines
When
read()return 0, the current code just tries again. But this leads to an infinite loop if QEMU died too soon.
Right.
Quoted 1 line
Also, retry select if a signal was caught.
Why add another goto ? I think these goto-based loops are a bad idea, really.
tools/libxl/libxl_qmp.c static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp) · line 395
Quoted 2 lines
tools/libxl/libxl_qmp.c +2
-0+if (errno ==EINTR ) + goto do_select_again;
I think this could be "continue". Do you agree.
Thanks,
Ian.
Quoted 8 lines · Ian Jackson
Anthony PERARD writes ("[Xen-devel] [PATCH]
libxl_qmp: Handle unexpected end-of-socket"):Quoted 2 lines
When
read()return 0, the current code just tries again. But this leads to an infinite loop if QEMU died too soon.Right.
Quoted 1 line
Also, retry select if a signal was caught.
Quoted 7 lines
Why add another goto ? I think these goto-based loops are a bad idea, really.
Quoted 2 lines
+ if (errno == EINTR)
+ gotodo_select_again;I think this could be "continue". Do you agree.
Yes, I agree. I'll change that for a while and resend it.
Thanks,
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel
Quoted 8 lines · Ian Jackson
Anthony PERARD writes ("[Xen-devel] [PATCH]
libxl_qmp: Handle unexpected end-of-socket"):Quoted 2 lines
When
read()return 0, the current code just tries again. But this leads to an infinite loop if QEMU died too soon.Right.
Quoted 1 line
Also, retry select if a signal was caught.
Quoted 7 lines
Why add another goto ? I think these goto-based loops are a bad idea, really.
tools/libxl/libxl_qmp.c static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp) · line 395
Quoted 2 lines
tools/libxl/libxl_qmp.c +2
-0+if (errno ==EINTR ) + goto do_select_again;I think this could be "continue". Do you agree.
Also select(2) says:
On error, -1 is returned, and errno is set appropriately; the
sets and timeout become undefined, so do not rely on their contents after an error.
So by my reading you need to reinitialise the sets anyway.
Ian.