Skip to content

Commit a9aa1c5

Browse files
committed
Use libvchan_client_init_async() instead of parent process timeout
This avoids leaving the child process running.
1 parent 61a8e1f commit a9aa1c5

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

daemon/qrexec-daemon.c

+22-12
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static void init(int xid)
307307
if (!opt_quiet)
308308
LOG(ERROR, "Waiting for VM's qrexec agent.");
309309
struct pollfd fds[1] = {{ .fd = pipes[0], .events = POLLIN | POLLHUP, .revents = 0 }};
310-
for (i=0;i<startup_timeout;i++) {
310+
for (;;) {
311311
int res = poll(fds, 1, 1000);
312312
if (res < 0)
313313
err(1, "poll()");
@@ -320,18 +320,21 @@ static void init(int xid)
320320
LOG(ERROR, "Connection to the VM failed");
321321
exit(1);
322322
}
323-
if (!opt_quiet)
324-
LOG(INFO, "Connected to VM");
325-
exit(0);
323+
switch (buf[0]) {
324+
case 0:
325+
if (!opt_quiet)
326+
LOG(INFO, "Connected to VM");
327+
exit(0);
328+
case 1:
329+
LOG(ERROR, "Cannot connect to '%s' qrexec agent for %d seconds, giving up", remote_domain_name, startup_timeout);
330+
exit(3);
331+
default:
332+
abort();
333+
}
326334
}
327335
if (!opt_quiet)
328336
fprintf(stderr, ".");
329-
if (i==startup_timeout-1) {
330-
break;
331-
}
332337
}
333-
LOG(ERROR, "Cannot connect to '%s' qrexec agent for %d seconds, giving up", remote_domain_name, startup_timeout);
334-
exit(3);
335338
}
336339
}
337340

@@ -366,10 +369,17 @@ static void init(int xid)
366369
}
367370
}
368371

369-
vchan = libvchan_client_init(xid, VCHAN_BASE_PORT);
372+
int wait_fd;
373+
vchan = libvchan_client_init_async(xid, VCHAN_BASE_PORT, &wait_fd);
370374
if (!vchan) {
371-
PERROR("cannot connect to qrexec agent");
372-
exit(1);
375+
LOG(ERROR, "Cannot create data vchan connection");
376+
exit(3);
377+
}
378+
if (qubes_wait_for_vchan_connection_with_timeout(
379+
vchan, wait_fd, false, startup_timeout) < 0) {
380+
if (write(pipes[1], "\1", 1)) {}
381+
LOG(ERROR, "qrexec connection timeout");
382+
exit(3);
373383
}
374384

375385
protocol_version = handle_agent_hello(vchan, remote_domain_name);

0 commit comments

Comments
 (0)