@@ -79,7 +79,7 @@ static void set_remote_domain(const char *src_domain_name) {
79
79
}
80
80
81
81
/* initialize data_protocol_version */
82
- static int handle_agent_handshake (libvchan_t * vchan , int remote_send_first )
82
+ static int handle_agent_handshake (libvchan_t * vchan , bool remote_send_first )
83
83
{
84
84
struct msg_header hdr ;
85
85
struct peer_info info ;
@@ -534,6 +534,23 @@ static size_t compute_service_length(const char *const remote_cmdline, const cha
534
534
return service_length ;
535
535
}
536
536
537
+ static void handshake_and_go (libvchan_t * data_vchan ,
538
+ struct buffer * stdin_buffer ,
539
+ bool remote_send_first ,
540
+ int prepare_ret )
541
+ {
542
+ if (data_vchan == NULL || !libvchan_is_open (data_vchan )) {
543
+ LOG (ERROR , "Failed to open data vchan connection" );
544
+ exit (1 );
545
+ }
546
+ int data_protocol_version = handle_agent_handshake (data_vchan , remote_send_first );
547
+ if (data_protocol_version < 0 )
548
+ exit (1 );
549
+ if (prepare_ret < 0 )
550
+ handle_failed_exec (data_vchan );
551
+ select_loop (data_vchan , data_protocol_version , stdin_buffer );
552
+ }
553
+
537
554
int main (int argc , char * * argv )
538
555
{
539
556
int opt ;
@@ -551,7 +568,6 @@ int main(int argc, char **argv)
551
568
int src_domain_id = 0 ; /* if not -c given, the process is run in dom0 */
552
569
int connection_timeout = 5 ;
553
570
struct service_params svc_params ;
554
- int data_protocol_version ;
555
571
int prepare_ret ;
556
572
bool kill = false;
557
573
@@ -665,16 +681,7 @@ int main(int argc, char **argv)
665
681
data_vchan = libvchan_client_init (data_domain , data_port );
666
682
alarm (0 );
667
683
signal (SIGALRM , old_handler );
668
- if (!data_vchan || !libvchan_is_open (data_vchan )) {
669
- LOG (ERROR , "Failed to open data vchan connection" );
670
- exit (1 );
671
- }
672
- data_protocol_version = handle_agent_handshake (data_vchan , true);
673
- if (data_protocol_version < 0 )
674
- exit (1 );
675
- if (prepare_ret < 0 )
676
- handle_failed_exec (data_vchan );
677
- select_loop (data_vchan , data_protocol_version , & stdin_buffer );
684
+ handshake_and_go (data_vchan , & stdin_buffer , true, prepare_ret );
678
685
} else {
679
686
s = connect_unix_socket (domname );
680
687
negotiate_connection_params (s ,
@@ -713,16 +720,7 @@ int main(int argc, char **argv)
713
720
exit (1 );
714
721
}
715
722
wait_for_vchan_client_with_timeout (data_vchan , connection_timeout );
716
- if (!libvchan_is_open (data_vchan )) {
717
- LOG (ERROR , "Failed to open data vchan connection" );
718
- exit (1 );
719
- }
720
- data_protocol_version = handle_agent_handshake (data_vchan , 0 );
721
- if (data_protocol_version < 0 )
722
- exit (1 );
723
- if (prepare_ret < 0 )
724
- handle_failed_exec (data_vchan );
725
- select_loop (data_vchan , data_protocol_version , & stdin_buffer );
723
+ handshake_and_go (data_vchan , & stdin_buffer , false, prepare_ret );
726
724
}
727
725
}
728
726
0 commit comments