mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-08-24 16:16:06 +00:00
change VmContainer's stdio's protocal
VmContainer.Tty: allocate tty or not VmContainer.Stdio: Stdio sequence number VmContainer.Stderr: Stderr sequence number if stderr is not share with stdout (currently used when VmContainer.Tty is false) And new stdio allocation code which respects the VmContainer.Tty. Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
+15
-1
@@ -7,6 +7,7 @@
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user