qrexec-lib: fail peer_client_init call when domain dies

Don't wait indefinitely.
This commit is contained in:
Marek Marczykowski-Górecki 2013-10-27 16:06:26 +01:00
parent 2739340559
commit 2ee40f16c2

View File

@ -170,9 +170,10 @@ char *peer_client_init(int dom, int port)
struct xs_handle *xs;
char buf[64];
char *name;
char *dummy;
char *dummy, *dummy2;
unsigned int len = 0;
char devbuf[128];
char dombuf[128];
unsigned int count;
char **vec;
@ -192,6 +193,7 @@ char *peer_client_init(int dom, int port)
snprintf(devbuf, sizeof(devbuf),
"/local/domain/%d/device/vchan/%d/event-channel", dom,
port);
snprintf(dombuf, sizeof(dombuf), "/local/domain/%d", dom);
xs_watch(xs, devbuf, devbuf);
do {
vec = xs_read_watch(xs, &count);
@ -201,6 +203,15 @@ char *peer_client_init(int dom, int port)
dummy = xs_read(xs, 0, devbuf, &len);
if (dummy)
free(dummy);
else {
/* check if domain still alive */
dummy2 = xs_read(xs, 0, dombuf, &len);
if (!dummy2) {
fprintf(stderr, "domain dead\n");
exit(1);
}
free(dummy2);
}
}
while (!dummy || !len); // wait for the server to create xenstore entries
xs_daemon_close(xs);