use pipes for stdio when non tty

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-03-10 00:14:03 +08:00
parent eaae1ae3fb
commit 21d63485b1
2 changed files with 42 additions and 14 deletions
+3 -1
View File
@@ -252,7 +252,9 @@ int hyper_handle_event(int efd, struct epoll_event *event)
if (event->events & EPOLLERR) {
fprintf(stderr, "get epoll err of not epool in event\n");
return -1;
if (de->ops->hup)
de->ops->hup(de, efd);
return 0;
}
return 0;
+39 -13
View File
@@ -174,6 +174,41 @@ struct hyper_event_ops err_ops = {
/* don't need write buff, the stderr data is one way */
};
static int hyper_setup_exec_notty(struct hyper_exec *e)
{
if (e->errseq == 0)
return -1;
int inpipe[2];
if (pipe2(inpipe, O_CLOEXEC) < 0) {
fprintf(stderr, "creating stderr pipe failed\n");
return -1;
}
hyper_setfd_nonblock(inpipe[1]);
e->stdinev.fd = inpipe[1];
e->stdinfd = inpipe[0];
int outpipe[2];
if (pipe2(outpipe, O_CLOEXEC) < 0) {
fprintf(stderr, "creating stderr pipe failed\n");
return -1;
}
hyper_setfd_nonblock(outpipe[0]);
e->stdoutev.fd = outpipe[0];
e->stdoutfd = outpipe[1];
int errpipe[2];
if (pipe2(errpipe, O_CLOEXEC) < 0) {
fprintf(stderr, "creating stderr pipe failed\n");
return -1;
}
hyper_setfd_nonblock(errpipe[0]);
e->stderrev.fd = errpipe[0];
e->stderrfd = errpipe[1];
return 0;
}
int hyper_setup_exec_tty(struct hyper_exec *e)
{
int unlock = 0;
@@ -185,6 +220,10 @@ int hyper_setup_exec_tty(struct hyper_exec *e)
goto done;
}
if (!e->tty) { // don't use tty for stdio
return hyper_setup_exec_notty(e);
}
if (e->errseq > 0) {
int errpipe[2];
if (pipe2(errpipe, O_CLOEXEC) < 0) {
@@ -196,19 +235,6 @@ int hyper_setup_exec_tty(struct hyper_exec *e)
e->stderrfd = errpipe[1];
}
if (!e->tty) { // don't use tty for stdio
int iopair[2];
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, iopair) < 0) {
fprintf(stderr, "creating stdio pair failed\n");
return -1;
}
hyper_setfd_nonblock(iopair[0]);
e->stdinev.fd = iopair[0];
e->stdoutev.fd = dup(iopair[0]);
e->ptyfd = iopair[1];
goto done;
}
if (e->id) {
if (sprintf(path, "/tmp/hyper/%s/devpts/", e->id) < 0) {
fprintf(stderr, "get ptmx path failed\n");