@@ -307,7 +307,7 @@ static void init(int xid)
307
307
if (!opt_quiet )
308
308
LOG (ERROR , "Waiting for VM's qrexec agent." );
309
309
struct pollfd fds [1 ] = {{ .fd = pipes [0 ], .events = POLLIN | POLLHUP , .revents = 0 }};
310
- for (i = 0 ; i < startup_timeout ; i ++ ) {
310
+ for (;; ) {
311
311
int res = poll (fds , 1 , 1000 );
312
312
if (res < 0 )
313
313
err (1 , "poll()" );
@@ -320,18 +320,21 @@ static void init(int xid)
320
320
LOG (ERROR , "Connection to the VM failed" );
321
321
exit (1 );
322
322
}
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
+ }
326
334
}
327
335
if (!opt_quiet )
328
336
fprintf (stderr , "." );
329
- if (i == startup_timeout - 1 ) {
330
- break ;
331
- }
332
337
}
333
- LOG (ERROR , "Cannot connect to '%s' qrexec agent for %d seconds, giving up" , remote_domain_name , startup_timeout );
334
- exit (3 );
335
338
}
336
339
}
337
340
@@ -366,10 +369,17 @@ static void init(int xid)
366
369
}
367
370
}
368
371
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 );
370
374
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 );
373
383
}
374
384
375
385
protocol_version = handle_agent_hello (vchan , remote_domain_name );
0 commit comments