From ae5fc471ea02f8898a35daf88b4a3fe381335af0 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 23 Oct 2017 11:35:38 -0400 Subject: [PATCH 1/3] Make attach sockets directory an argument in Conmon This is required to enable ongoing work in libpod Signed-off-by: Matthew Heon --- conmon/conmon.c | 9 +++++++-- oci/oci.go | 4 ++++ server/container_attach.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index 05789882..94124d4c 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -111,6 +111,7 @@ static char *opt_log_path = NULL; static char *opt_exit_dir = NULL; static int opt_timeout = 0; static int64_t opt_log_size_max = -1; +static char *opt_socket_path = NULL; static GOptionEntry opt_entries[] = { { "terminal", 't', 0, G_OPTION_ARG_NONE, &opt_terminal, "Terminal", NULL }, @@ -128,6 +129,7 @@ static GOptionEntry opt_entries[] = { "log-path", 'l', 0, G_OPTION_ARG_STRING, &opt_log_path, "Log file path", NULL }, { "timeout", 'T', 0, G_OPTION_ARG_INT, &opt_timeout, "Timeout in seconds", NULL }, { "log-size-max", 0, 0, G_OPTION_ARG_INT64, &opt_log_size_max, "Maximum size of log file", NULL }, + { "socket-path", 0, 0, G_OPTION_ARG_STRING, &opt_socket_path, "Location of container attach sockets", NULL }, { NULL } }; @@ -989,14 +991,14 @@ static char *setup_attach_socket(void) * Create a symlink so we don't exceed unix domain socket * path length limit. */ - attach_symlink_dir_path = g_build_filename("/var/run/crio", opt_cuuid, NULL); + attach_symlink_dir_path = g_build_filename(opt_socket_path, opt_cuuid, NULL); if (unlink(attach_symlink_dir_path) == -1 && errno != ENOENT) pexit("Failed to remove existing symlink for attach socket directory"); if (symlink(opt_bundle_path, attach_symlink_dir_path) == -1) pexit("Failed to create symlink for attach socket"); - attach_sock_path = g_build_filename("/var/run/crio", opt_cuuid, "attach", NULL); + attach_sock_path = g_build_filename(opt_socket_path, opt_cuuid, "attach", NULL); ninfo("attach sock path: %s", attach_sock_path); strncpy(attach_addr.sun_path, attach_sock_path, sizeof(attach_addr.sun_path) - 1); @@ -1157,6 +1159,9 @@ int main(int argc, char *argv[]) if (opt_log_path == NULL) nexit("Log file path not provided. Use --log-path"); + if (opt_socket_path == NULL) + nexit("Socket path not provided. Use --socket-path"); + start_pipe_fd = get_pipe_fd_from_env("_OCI_STARTPIPE"); if (start_pipe_fd >= 0) { /* Block for an initial write to the start pipe before diff --git a/oci/oci.go b/oci/oci.go index b5a433c3..73970c40 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -40,6 +40,8 @@ const ( SystemdCgroupsManager = "systemd" // ContainerExitsDir is the location of container exit dirs ContainerExitsDir = "/var/run/crio/exits" + // ContainerAttachSocketDir is the location for container attach sockets + ContainerAttachSocketDir = "/var/run/crio" // killContainerTimeout is the timeout that we wait for the container to // be SIGKILLed. @@ -177,6 +179,7 @@ func (r *Runtime) CreateContainer(c *Container, cgroupParent string) (err error) args = append(args, "-p", filepath.Join(c.bundlePath, "pidfile")) args = append(args, "-l", c.logPath) args = append(args, "--exit-dir", r.containerExitsDir) + args = append(args, "--socket-path", ContainerAttachSocketDir) if r.logSizeMax >= 0 { args = append(args, "--log-size-max", fmt.Sprintf("%v", r.logSizeMax)) } @@ -434,6 +437,7 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp args = append(args, fmt.Sprintf("%d", timeout)) } args = append(args, "-l", logPath) + args = append(args, "--socket-path", ContainerAttachSocketDir) pspec := rspec.Process{ Env: r.conmonEnv, diff --git a/server/container_attach.go b/server/container_attach.go index 2d2fe203..6a822858 100644 --- a/server/container_attach.go +++ b/server/container_attach.go @@ -67,7 +67,7 @@ func (ss streamService) Attach(containerID string, inputStream io.Reader, output } }) - attachSocketPath := filepath.Join("/var/run/crio", c.ID(), "attach") + attachSocketPath := filepath.Join(oci.ContainerAttachSocketDir, c.ID(), "attach") conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: attachSocketPath, Net: "unixpacket"}) if err != nil { return fmt.Errorf("failed to connect to container %s attach socket: %v", c.ID(), err) From 042f31fe685c28662fb5e5e9533a7a2f1b29bd64 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 24 Oct 2017 10:28:25 -0400 Subject: [PATCH 2/3] Add default CRI-O socket path back to conmon Signed-off-by: Matthew Heon --- conmon/conmon.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index 94124d4c..3fd14212 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -96,6 +96,8 @@ static inline void strv_cleanup(char ***strv) #define CMD_SIZE 1024 #define MAX_EVENTS 10 +#define DEFAULT_SOCKET_PATH "/var/lib/crio" + static bool opt_terminal = false; static bool opt_stdin = false; static char *opt_cid = NULL; @@ -111,7 +113,7 @@ static char *opt_log_path = NULL; static char *opt_exit_dir = NULL; static int opt_timeout = 0; static int64_t opt_log_size_max = -1; -static char *opt_socket_path = NULL; +static char *opt_socket_path = DEFAULT_SOCKET_PATH; static GOptionEntry opt_entries[] = { { "terminal", 't', 0, G_OPTION_ARG_NONE, &opt_terminal, "Terminal", NULL }, @@ -1159,9 +1161,6 @@ int main(int argc, char *argv[]) if (opt_log_path == NULL) nexit("Log file path not provided. Use --log-path"); - if (opt_socket_path == NULL) - nexit("Socket path not provided. Use --socket-path"); - start_pipe_fd = get_pipe_fd_from_env("_OCI_STARTPIPE"); if (start_pipe_fd >= 0) { /* Block for an initial write to the start pipe before From e66da6046d0e8eef1d5eeb949579ba6dd843f88c Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 24 Oct 2017 18:28:53 -0400 Subject: [PATCH 3/3] Rename conmon argument to socket-dir-path Signed-off-by: Matthew Heon --- conmon/conmon.c | 2 +- oci/oci.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index 3fd14212..66d1bbe0 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -131,7 +131,7 @@ static GOptionEntry opt_entries[] = { "log-path", 'l', 0, G_OPTION_ARG_STRING, &opt_log_path, "Log file path", NULL }, { "timeout", 'T', 0, G_OPTION_ARG_INT, &opt_timeout, "Timeout in seconds", NULL }, { "log-size-max", 0, 0, G_OPTION_ARG_INT64, &opt_log_size_max, "Maximum size of log file", NULL }, - { "socket-path", 0, 0, G_OPTION_ARG_STRING, &opt_socket_path, "Location of container attach sockets", NULL }, + { "socket-dir-path", 0, 0, G_OPTION_ARG_STRING, &opt_socket_path, "Location of container attach sockets", NULL }, { NULL } }; diff --git a/oci/oci.go b/oci/oci.go index 73970c40..9ed8dcf3 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -179,7 +179,7 @@ func (r *Runtime) CreateContainer(c *Container, cgroupParent string) (err error) args = append(args, "-p", filepath.Join(c.bundlePath, "pidfile")) args = append(args, "-l", c.logPath) args = append(args, "--exit-dir", r.containerExitsDir) - args = append(args, "--socket-path", ContainerAttachSocketDir) + args = append(args, "--socket-dir-path", ContainerAttachSocketDir) if r.logSizeMax >= 0 { args = append(args, "--log-size-max", fmt.Sprintf("%v", r.logSizeMax)) } @@ -437,7 +437,7 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp args = append(args, fmt.Sprintf("%d", timeout)) } args = append(args, "-l", logPath) - args = append(args, "--socket-path", ContainerAttachSocketDir) + args = append(args, "--socket-dir-path", ContainerAttachSocketDir) pspec := rspec.Process{ Env: r.conmonEnv,