@@ -924,13 +924,12 @@ static int hyper_ctl_send_ready(int fd)
924924 return 0 ;
925925}
926926
927- static int hyper_setup_ctl_channel (char * name )
927+ static int hyper_setup_ctl_channel (char * name , bool is_serial )
928928{
929- int fd ;
930-
931- fd = hyper_open_channel (name , 0 );
929+ int fd = hyper_open_channel (name , 0 , is_serial );
932930 if (fd < 0 )
933931 return fd ;
932+
934933 if (hyper_ctl_send_ready (fd ) < 0 ) {
935934 close (fd );
936935 return -1 ;
@@ -939,9 +938,9 @@ static int hyper_setup_ctl_channel(char *name)
939938 return fd ;
940939}
941940
942- static int hyper_setup_tty_channel (char * name )
941+ static int hyper_setup_tty_channel (char * name , bool is_serial )
943942{
944- int ret = hyper_open_channel (name , O_NONBLOCK );
943+ int ret = hyper_open_channel (name , O_NONBLOCK , is_serial );
945944 if (ret < 0 )
946945 return -1 ;
947946
@@ -1061,8 +1060,7 @@ static int hyper_ttyfd_read(struct hyper_event *he, int efd, int events)
10611060{
10621061 struct hyper_buf * buf = & he -> rbuf ;
10631062 uint32_t len ;
1064- int size ;
1065- int ret ;
1063+ int size , ret ;
10661064
10671065 if (buf -> get < STREAM_HEADER_SIZE ) {
10681066 size = hyper_channel_read (he , efd , STREAM_HEADER_SIZE - buf -> get , events );
@@ -1524,10 +1522,34 @@ static int hyper_setup_init_process(void)
15241522 return 0 ;
15251523}
15261524
1525+ void read_cmdline (bool * use_serial )
1526+ {
1527+ char buf [512 ];
1528+ int size ;
1529+
1530+ int fd = open ("/proc/cmdline" , O_RDONLY | O_CLOEXEC );
1531+ if (fd < 0 ) {
1532+ perror ("fail to open /proc/cmdline" );
1533+ return ;
1534+ }
1535+ size = read (fd , buf , sizeof (buf ));
1536+ if (size < 0 ) {
1537+ perror ("fail to read /proc/cmdline" );
1538+ goto out ;
1539+ }
1540+
1541+ if (strstr (buf , HYPER_USE_SERAIL ))
1542+ * use_serial = true;
1543+
1544+ out :
1545+ close (fd );
1546+ return ;
1547+ }
1548+
15271549int main (int argc , char * argv [])
15281550{
1529- char * binary_name , * cmdline , * ctl_serial , * tty_serial ;
1530- bool is_init , has_vsock = false;
1551+ char * binary_name , * ctl_serial = NULL , * tty_serial = NULL ;
1552+ bool is_init , has_vsock = false, is_serial = false ;
15311553
15321554 binary_name = basename (argv [0 ]);
15331555 is_init = strncmp (binary_name , "init" , 5 ) == 0 ;
@@ -1536,20 +1558,26 @@ int main(int argc, char *argv[])
15361558 return -1 ;
15371559 }
15381560
1539- cmdline = read_cmdline ();
1540-
1561+ read_cmdline (& is_serial );
15411562#ifdef WITH_VBOX
15421563 ctl_serial = "/dev/ttyS0" ;
15431564 tty_serial = "/dev/ttyS1" ;
1565+ is_serial = true;
15441566
15451567 if (hyper_insmod ("/vboxguest.ko" ) < 0 ||
15461568 hyper_insmod ("/vboxsf.ko" ) < 0 ) {
15471569 fprintf (stderr , "fail to load modules\n" );
15481570 return -1 ;
15491571 }
15501572#else
1551- ctl_serial = "sh.hyper.channel.0" ;
1552- tty_serial = "sh.hyper.channel.1" ;
1573+ if (is_serial ) {
1574+ ctl_serial = "/dev/ttyS1" ;
1575+ tty_serial = "/dev/ttyS2" ;
1576+ } else {
1577+ ctl_serial = strdup ("sh.hyper.channel.0" );
1578+ tty_serial = strdup ("sh.hyper.channel.1" );
1579+ }
1580+
15531581 if (probe_vsock_device () <= 0 ) {
15541582 fprintf (stderr , "cannot find vsock device\n" );
15551583 } else if (hyper_cmd ("modprobe vmw_vsock_virtio_transport" ) < 0 ) {
@@ -1558,20 +1586,19 @@ int main(int argc, char *argv[])
15581586 has_vsock = true;
15591587 }
15601588#endif
1561-
15621589 if (has_vsock ) {
15631590 if (hyper_setup_vsock_channel () < 0 ) {
15641591 fprintf (stderr , "fail to setup hyper vsock listener\n" );
15651592 goto out ;
15661593 }
15671594 } else {
1568- hyper_epoll .ctl .fd = hyper_setup_ctl_channel (ctl_serial );
1595+ hyper_epoll .ctl .fd = hyper_setup_ctl_channel (ctl_serial , is_serial );
15691596 if (hyper_epoll .ctl .fd < 0 ) {
15701597 fprintf (stderr , "fail to setup hyper control serial port\n" );
15711598 goto out ;
15721599 }
15731600
1574- hyper_epoll .tty .fd = hyper_setup_tty_channel (tty_serial );
1601+ hyper_epoll .tty .fd = hyper_setup_tty_channel (tty_serial , is_serial );
15751602 if (hyper_epoll .tty .fd < 0 ) {
15761603 fprintf (stderr , "fail to setup hyper tty serial port\n" );
15771604 goto out ;
@@ -1589,7 +1616,6 @@ int main(int argc, char *argv[])
15891616 close (hyper_epoll .tty .fd );
15901617 if (hyper_epoll .ctl .fd > 0 )
15911618 close (hyper_epoll .ctl .fd );
1592- free (cmdline );
15931619
15941620 return 0 ;
15951621}
0 commit comments