Support stdin once

We leave the stdin open on first client disconnect if stdin once
is not set in the container configuration.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2018-01-05 19:36:10 -08:00
parent 3ab6c36b83
commit a480b20652
2 changed files with 11 additions and 2 deletions

View file

@ -99,6 +99,7 @@ static inline void strv_cleanup(char ***strv)
static bool opt_terminal = false;
static bool opt_stdin = false;
static bool opt_leave_stdin_open = false;
static char *opt_cid = NULL;
static char *opt_cuuid = NULL;
static char *opt_runtime_path = NULL;
@ -117,6 +118,7 @@ static GOptionEntry opt_entries[] =
{
{ "terminal", 't', 0, G_OPTION_ARG_NONE, &opt_terminal, "Terminal", NULL },
{ "stdin", 'i', 0, G_OPTION_ARG_NONE, &opt_stdin, "Stdin", NULL },
{ "leave-stdin-open", 0, 0, G_OPTION_ARG_NONE, &opt_leave_stdin_open, "Leave stdin open when attached client disconnects", NULL },
{ "cid", 'c', 0, G_OPTION_ARG_STRING, &opt_cid, "Container ID", NULL },
{ "cuuid", 'u', 0, G_OPTION_ARG_STRING, &opt_cuuid, "Container UUID", NULL },
{ "runtime", 'r', 0, G_OPTION_ARG_STRING, &opt_runtime_path, "Runtime path", NULL },
@ -755,8 +757,12 @@ static gboolean conn_sock_cb(int fd, GIOCondition condition, G_GNUC_UNUSED gpoin
/* End of input */
conn_sock_shutdown(SHUT_RD);
if (masterfd_stdin >= 0 && opt_stdin) {
close(masterfd_stdin);
masterfd_stdin = -1;
if (!opt_leave_stdin_open) {
close(masterfd_stdin);
masterfd_stdin = -1;
} else {
ninfo("Not closing input");
}
}
return G_SOURCE_REMOVE;
}

View file

@ -189,6 +189,9 @@ func (r *Runtime) CreateContainer(c *Container, cgroupParent string) (err error)
if c.terminal {
args = append(args, "-t")
} else if c.stdin {
if !c.stdinOnce {
args = append(args, "--leave-stdin-open")
}
args = append(args, "-i")
}
logrus.WithFields(logrus.Fields{