@@ -288,19 +288,21 @@ static void init(int xid, bool opt_direct)
288
288
startup_timeout = MAX_STARTUP_TIME_DEFAULT ;
289
289
}
290
290
291
- int pipes [2 ];
291
+ int pipes [2 ] = { -1 , -1 };
292
+ bool have_timeout = getenv ("QREXEC_STARTUP_NOWAIT" ) == NULL ;
292
293
if (!opt_direct ) {
293
- if (pipe2 (pipes , O_CLOEXEC ))
294
+ if (have_timeout && pipe2 (pipes , O_CLOEXEC ))
294
295
err (1 , "pipe2()" );
295
296
switch (pid = fork ()) {
296
297
case -1 :
297
298
PERROR ("fork" );
298
299
exit (1 );
299
300
case 0 :
300
- close (pipes [0 ]);
301
+ if (have_timeout )
302
+ close (pipes [0 ]);
301
303
break ;
302
304
default :
303
- if (getenv ( "QREXEC_STARTUP_NOWAIT" ) )
305
+ if (! have_timeout )
304
306
exit (0 );
305
307
close (pipes [1 ]);
306
308
if (!opt_quiet )
@@ -368,18 +370,22 @@ static void init(int xid, bool opt_direct)
368
370
}
369
371
370
372
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
+ }
372
385
if (!vchan ) {
373
386
LOG (ERROR , "Cannot create data vchan connection" );
374
387
exit (3 );
375
388
}
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
-
383
389
protocol_version = handle_agent_hello (vchan , remote_domain_name );
384
390
if (protocol_version < 0 ) {
385
391
exit (1 );
@@ -422,7 +428,7 @@ static void init(int xid, bool opt_direct)
422
428
err (1 , "sigaction" );
423
429
if (sigaction (SIGTERM , & sigterm_action , NULL ))
424
430
err (1 , "sigaction" );
425
- if (!opt_direct ) {
431
+ if (have_timeout && !opt_direct ) {
426
432
if (write (pipes [1 ], "" , 1 ) != 1 )
427
433
err (1 , "write(pipe)" );
428
434
close (pipes [1 ]);
0 commit comments