diff --git a/src/exec.c b/src/exec.c index bdb1cd8..eb4d483 100644 --- a/src/exec.c +++ b/src/exec.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -188,6 +189,18 @@ int hyper_setup_exec_tty(struct hyper_exec *e) e->errfd = 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->e.fd = 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"); @@ -229,6 +242,7 @@ int hyper_setup_exec_tty(struct hyper_exec *e) e->ptyfd = open(ptmx, O_RDWR | O_NOCTTY | O_CLOEXEC); fprintf(stdout, "get pty device for exec %s\n", ptmx); +done: fprintf(stdout, "%s pts event %p, fd %d %d\n", __func__, &e->e, e->e.fd, e->ptyfd); return 0; @@ -257,7 +271,7 @@ int hyper_dup_exec_tty(int to, struct hyper_exec *e) goto out; } - if (e->seq && (ioctl(fd, TIOCSCTTY, NULL) < 0)) { + if (e->tty && (ioctl(fd, TIOCSCTTY, NULL) < 0)) { perror("ioctl pty device for execcmd failed"); goto out; } diff --git a/src/exec.h b/src/exec.h index 56320ca..97cb986 100644 --- a/src/exec.h +++ b/src/exec.h @@ -11,6 +11,7 @@ struct hyper_exec { char *id; char **argv; int argc; + int tty; // use tty or not uint64_t seq; uint64_t errseq; int pid; diff --git a/src/parse.c b/src/parse.c index 5500929..fc529f6 100644 --- a/src/parse.c +++ b/src/parse.c @@ -497,6 +497,14 @@ static int hyper_parse_container(struct hyper_pod *pod, struct hyper_container * fprintf(stdout, "container rootfs %s\n", c->rootfs); i++; } else if (json_token_streq(json, t, "tty") && t->size == 1) { + if (!json_token_streq(json, &toks[++i], "false")) { + c->exec.tty = 1; + fprintf(stdout, "container uses terminal\n"); + } else { + fprintf(stdout, "container doesn't use terminal\n"); + } + i++; + } else if (json_token_streq(json, t, "stdio") && t->size == 1) { c->exec.seq = json_token_ll(json, &toks[++i]); fprintf(stdout, "container seq %" PRIu64 "\n", c->exec.seq); i++;