diff --git a/conmon/conmon.c b/conmon/conmon.c index 477b98bf..5af704e6 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -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; } diff --git a/oci/oci.go b/oci/oci.go index 658079a3..7a0e6488 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -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{