From b14bae48693e1fdddbe6bf1db67ea499735984e3 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 14 Nov 2016 17:46:58 +0100 Subject: [PATCH 1/2] conmon: Add --bundle and --pidfile command line options We need to be able pass both the bundle path and the pid file paths to conmon from ocid. The former is mandatory when creating an OCI container: https://github.com/opencontainers/runtime-spec/blob/master/runtime.md#create And it makes sense to provide a full path for the latter as the current hardcoded relative path may lead to errors if e.g. the runtime chdir() before creating the PID file. In both cases we try to create default reasonable values when they are left empty by the caller. Signed-off-by: Samuel Ortiz --- conmon/conmon.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index 0ef15d60..e1727ef6 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -63,11 +63,15 @@ static void tty_restore(void) static bool terminal = false; static char *cid = NULL; static char *runtime_path = NULL; +static char *bundle_path = NULL; +static char *pid_file = NULL; static GOptionEntry entries[] = { { "terminal", 't', 0, G_OPTION_ARG_NONE, &terminal, "Terminal", NULL }, { "cid", 'c', 0, G_OPTION_ARG_STRING, &cid, "Container ID", NULL }, { "runtime", 'r', 0, G_OPTION_ARG_STRING, &runtime_path, "Runtime path", NULL }, + { "bundle", 'b', 0, G_OPTION_ARG_STRING, &bundle_path, "Bundle path", NULL }, + { "pidfile", 'p', 0, G_OPTION_ARG_STRING, &pid_file, "PID file", NULL }, { NULL } }; @@ -75,6 +79,8 @@ int main(int argc, char *argv[]) { int ret; char cmd[CMD_SIZE]; + char cwd[PATH_MAX]; + char default_pid_file[PATH_MAX]; GError *err = NULL; _cleanup_free_ char *contents; int cpid = -1; @@ -108,6 +114,23 @@ int main(int argc, char *argv[]) if (runtime_path == NULL) nexit("Runtime path not provided. Use --runtime"); + if (bundle_path == NULL) { + if (getcwd(cwd, sizeof(cwd)) == NULL) { + nexit("Failed to get working directory"); + } + + bundle_path = cwd; + } + + if (pid_file == NULL) { + if (snprintf(default_pid_file, sizeof(default_pid_file), + "%s/pidfile-%s", cwd, cid) < 0) { + nexit("Failed to generate the pidfile path"); + } + + pid_file = default_pid_file; + } + /* Environment variables */ sync_pipe = getenv("_OCI_SYNCPIPE"); if (sync_pipe) { @@ -152,11 +175,11 @@ int main(int argc, char *argv[]) /* Create the container */ if (terminal) { snprintf(cmd, CMD_SIZE, - "%s create %s --pid-file pidfile --console %s", - runtime_path, cid, slname); + "%s create %s --bundle %s --pid-file %s --console %s", + runtime_path, cid, bundle_path, pid_file, slname); } else { - snprintf(cmd, CMD_SIZE, "%s create %s --pid-file pidfile", - runtime_path, cid); + snprintf(cmd, CMD_SIZE, "%s create %s --bundle %s --pid-file %s", + runtime_path, cid, bundle_path, pid_file); } ret = system(cmd); if (ret != 0) { From 5bbef5fc8831f8b9a6b0c9f9f73f2f0db70b1b64 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 14 Nov 2016 17:52:58 +0100 Subject: [PATCH 2/2] oci: Pass the bundle and pid file paths to conmon Signed-off-by: Samuel Ortiz --- oci/oci.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/oci/oci.go b/oci/oci.go index 0ce2fa36..abfa558b 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -102,6 +102,8 @@ func (r *Runtime) CreateContainer(c *Container) error { args := []string{"-c", c.name} args = append(args, "-r", r.path) + args = append(args, "-b", c.bundlePath) + args = append(args, "-p", filepath.Join(c.bundlePath, "pidfile")) if c.terminal { args = append(args, "-t") }