Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 4d91dd9

Browse files
committed
use vsock for channel communication when available
Signed-off-by: Peng Tao <bergwolf@gmail.com>
1 parent 181d241 commit 4d91dd9

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

src/init.c

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,20 +1368,6 @@ static int hyper_loop(void)
13681368
return -1;
13691369
}
13701370

1371-
fprintf(stdout, "hyper_init_event hyper ctlfd event %p, ops %p, fd %d\n",
1372-
&hyper_epoll.ctl, &hyper_ctlfd_ops, hyper_epoll.ctl.fd);
1373-
if (hyper_init_event(&hyper_epoll.ctl, &hyper_ctlfd_ops, pod) < 0 ||
1374-
hyper_add_event(hyper_epoll.efd, &hyper_epoll.ctl, EPOLLIN) < 0) {
1375-
return -1;
1376-
}
1377-
1378-
fprintf(stdout, "hyper_init_event hyper ttyfd event %p, ops %p, fd %d\n",
1379-
&hyper_epoll.tty, &hyper_ttyfd_ops, hyper_epoll.tty.fd);
1380-
if (hyper_init_event(&hyper_epoll.tty, &hyper_ttyfd_ops, pod) < 0 ||
1381-
hyper_add_event(hyper_epoll.efd, &hyper_epoll.tty, EPOLLIN) < 0) {
1382-
return -1;
1383-
}
1384-
13851371
if (hyper_epoll.vsock_ctl_listener.fd > 0) {
13861372
fprintf(stdout, "hyper_init_event hyper vsock control channel listener event %p, ops %p, fd %d\n",
13871373
&hyper_epoll.vsock_ctl_listener, &hyper_vsock_ctl_listen_ops, hyper_epoll.vsock_ctl_listener.fd);
@@ -1395,6 +1381,20 @@ static int hyper_loop(void)
13951381
hyper_add_event(hyper_epoll.efd, &hyper_epoll.vsock_msg_listener, EPOLLIN) < 0) {
13961382
return -1;
13971383
}
1384+
} else {
1385+
fprintf(stdout, "hyper_init_event hyper ctlfd event %p, ops %p, fd %d\n",
1386+
&hyper_epoll.ctl, &hyper_ctlfd_ops, hyper_epoll.ctl.fd);
1387+
if (hyper_init_event(&hyper_epoll.ctl, &hyper_ctlfd_ops, pod) < 0 ||
1388+
hyper_add_event(hyper_epoll.efd, &hyper_epoll.ctl, EPOLLIN) < 0) {
1389+
return -1;
1390+
}
1391+
1392+
fprintf(stdout, "hyper_init_event hyper ttyfd event %p, ops %p, fd %d\n",
1393+
&hyper_epoll.tty, &hyper_ttyfd_ops, hyper_epoll.tty.fd);
1394+
if (hyper_init_event(&hyper_epoll.tty, &hyper_ttyfd_ops, pod) < 0 ||
1395+
hyper_add_event(hyper_epoll.efd, &hyper_epoll.tty, EPOLLIN) < 0) {
1396+
return -1;
1397+
}
13981398
}
13991399

14001400
events = calloc(MAXEVENTS, sizeof(*events));
@@ -1504,37 +1504,36 @@ int main(int argc, char *argv[])
15041504
}
15051505
#endif
15061506

1507-
hyper_epoll.ctl.fd = hyper_setup_ctl_channel(ctl_serial);
1508-
if (hyper_epoll.ctl.fd < 0) {
1509-
fprintf(stderr, "fail to setup hyper control serial port\n");
1510-
goto out1;
1511-
}
1512-
1513-
hyper_epoll.tty.fd = hyper_setup_tty_channel(tty_serial);
1514-
if (hyper_epoll.tty.fd < 0) {
1515-
fprintf(stderr, "fail to setup hyper tty serial port\n");
1516-
goto out2;
1517-
}
1518-
15191507
if (hyper_epoll.vsock_ctl_listener.fd > 0) {
15201508
if (hyper_setup_vsock_channel() < 0) {
15211509
fprintf(stderr, "fail to setup hyper vsock listener\n");
1522-
goto out3;
1510+
goto out;
1511+
}
1512+
} else {
1513+
hyper_epoll.ctl.fd = hyper_setup_ctl_channel(ctl_serial);
1514+
if (hyper_epoll.ctl.fd < 0) {
1515+
fprintf(stderr, "fail to setup hyper control serial port\n");
1516+
goto out;
1517+
}
1518+
1519+
hyper_epoll.tty.fd = hyper_setup_tty_channel(tty_serial);
1520+
if (hyper_epoll.tty.fd < 0) {
1521+
fprintf(stderr, "fail to setup hyper tty serial port\n");
1522+
goto out;
15231523
}
15241524
}
15251525

15261526
hyper_loop();
15271527

1528+
out:
15281529
if (hyper_epoll.vsock_ctl_listener.fd > 0)
15291530
close(hyper_epoll.vsock_ctl_listener.fd);
15301531
if (hyper_epoll.vsock_msg_listener.fd > 0)
15311532
close(hyper_epoll.vsock_msg_listener.fd);
1532-
1533-
out3:
1534-
close(hyper_epoll.tty.fd);
1535-
out2:
1536-
close(hyper_epoll.ctl.fd);
1537-
out1:
1533+
if (hyper_epoll.tty.fd > 0)
1534+
close(hyper_epoll.tty.fd);
1535+
if (hyper_epoll.ctl.fd > 0)
1536+
close(hyper_epoll.ctl.fd);
15381537
free(cmdline);
15391538

15401539
return 0;

0 commit comments

Comments
 (0)