Skip to content

Commit a9d11c0

Browse files
committed
Do not use a timeout if QREXEC_STARTUP_NOWAIT is set
This had the (undocumented) behavior of disabling all timeouts, but that was broken by a9aa1c5. Fixes: a9aa1c5 ("Use libvchan_client_init_async() instead of parent process timeout")
1 parent 6d66051 commit a9d11c0

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

daemon/qrexec-daemon.c

+19-13
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,21 @@ static void init(int xid, bool opt_direct)
288288
startup_timeout = MAX_STARTUP_TIME_DEFAULT;
289289
}
290290

291-
int pipes[2];
291+
int pipes[2] = { -1, -1 };
292+
bool have_timeout = getenv("QREXEC_STARTUP_NOWAIT") == NULL;
292293
if (!opt_direct) {
293-
if (pipe2(pipes, O_CLOEXEC))
294+
if (have_timeout && pipe2(pipes, O_CLOEXEC))
294295
err(1, "pipe2()");
295296
switch (pid=fork()) {
296297
case -1:
297298
PERROR("fork");
298299
exit(1);
299300
case 0:
300-
close(pipes[0]);
301+
if (have_timeout)
302+
close(pipes[0]);
301303
break;
302304
default:
303-
if (getenv("QREXEC_STARTUP_NOWAIT"))
305+
if (!have_timeout)
304306
exit(0);
305307
close(pipes[1]);
306308
if (!opt_quiet)
@@ -368,18 +370,22 @@ static void init(int xid, bool opt_direct)
368370
}
369371

370372
int wait_fd;
371-
vchan = libvchan_client_init_async(xid, VCHAN_BASE_PORT, &wait_fd);
373+
if (have_timeout) {
374+
vchan = libvchan_client_init_async(xid, VCHAN_BASE_PORT, &wait_fd);
375+
if (vchan != NULL && qubes_wait_for_vchan_connection_with_timeout(
376+
vchan, wait_fd, false, startup_timeout) < 0) {
377+
if (!opt_direct && write(pipes[1], "\1", 1)) {}
378+
LOG(ERROR, "qrexec connection timeout");
379+
exit(3);
380+
}
381+
} else {
382+
/* No timeout in this case */
383+
vchan = libvchan_client_init(xid, VCHAN_BASE_PORT);
384+
}
372385
if (!vchan) {
373386
LOG(ERROR, "Cannot create data vchan connection");
374387
exit(3);
375388
}
376-
if (qubes_wait_for_vchan_connection_with_timeout(
377-
vchan, wait_fd, false, startup_timeout) < 0) {
378-
if (!opt_direct && write(pipes[1], "\1", 1)) {}
379-
LOG(ERROR, "qrexec connection timeout");
380-
exit(3);
381-
}
382-
383389
protocol_version = handle_agent_hello(vchan, remote_domain_name);
384390
if (protocol_version < 0) {
385391
exit(1);
@@ -422,7 +428,7 @@ static void init(int xid, bool opt_direct)
422428
err(1, "sigaction");
423429
if (sigaction(SIGTERM, &sigterm_action, NULL))
424430
err(1, "sigaction");
425-
if (!opt_direct) {
431+
if (have_timeout && !opt_direct) {
426432
if (write(pipes[1], "", 1) != 1)
427433
err(1, "write(pipe)");
428434
close(pipes[1]);

0 commit comments

Comments
 (0)