conmon: use runtime path from ocid

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-09-17 11:37:45 +02:00
parent 2d8691cb0a
commit 4a4897bbfe
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
3 changed files with 67 additions and 31 deletions

View file

@ -1,6 +1,9 @@
.PHONY: all clean ocid ocic .PHONY: all clean conmon ocid ocic
all: ocid ocic all: conmon ocid ocic
conmon:
make -C $@
ocid: ocid:
go build -o ocid ./cmd/server/main.go go build -o ocid ./cmd/server/main.go

View file

@ -33,9 +33,13 @@
#define _cleanup_(x) __attribute__((cleanup(x))) #define _cleanup_(x) __attribute__((cleanup(x)))
static inline void freep(void *p) { free(*(void **)p); } static inline void freep(void *p)
{
free(*(void **)p);
}
static inline void closep(int *fd) { static inline void closep(int *fd)
{
if (*fd >= 0) if (*fd >= 0)
close(*fd); close(*fd);
*fd = -1; *fd = -1;
@ -62,6 +66,7 @@ int main(int argc, char *argv[])
int opt; int opt;
bool terminal = FALSE; bool terminal = FALSE;
const char *cid = NULL; const char *cid = NULL;
const char *runtime_path = NULL;
char cmd[CMD_SIZE]; char cmd[CMD_SIZE];
GError *err = NULL; GError *err = NULL;
_cleanup_free_ char *contents; _cleanup_free_ char *contents;
@ -80,29 +85,38 @@ int main(int argc, char *argv[])
char *sync_pipe, *endptr; char *sync_pipe, *endptr;
int len; int len;
while ((opt = getopt(argc, argv, "tc:")) != -1) { while ((opt = getopt(argc, argv, "tc:r:")) != -1) {
switch(opt) { switch (opt) {
case 't': case 't':
terminal = TRUE; terminal = TRUE;
break; break;
case 'c': case 'c':
cid = optarg; cid = optarg;
break; break;
case 'r':
runtime_path = optarg;
break;
case '?': case '?':
if (optopt == 'c') if (optopt == 'c' || optopt == 'r')
nexit("Option -%c requires an argument.", optopt); nexit("Option -%c requires an argument.",
else if (isprint (optopt)) optopt);
else if (isprint(optopt))
nexit("Unknown option `-%c'.", optopt); nexit("Unknown option `-%c'.", optopt);
else else
nexit("Unknown option character `\\x%x'.\n", optopt); nexit("Unknown option character `\\x%x'.\n",
optopt);
default: default:
nexit("Usage: %s [-c container_id] [-t]", argv[0]); nexit
("Usage: %s -r runtime_path [-c container_id] [-t]",
argv[0]);
} }
} }
if (cid == NULL) { if (cid == NULL)
nexit("Container ID not passed"); nexit("Container ID not provided");
}
if (runtime_path == NULL)
nexit("Runtime path not provided");
sync_pipe = getenv("_OCI_SYNCPIPE"); sync_pipe = getenv("_OCI_SYNCPIPE");
if (sync_pipe) { if (sync_pipe) {
@ -132,7 +146,7 @@ int main(int argc, char *argv[])
pexit("Failed to grant access to slave pty"); pexit("Failed to grant access to slave pty");
/* Unlock the slave pty */ /* Unlock the slave pty */
if (unlockpt(mfd) == -1) { /* Unlock slave pty */ if (unlockpt(mfd) == -1) { /* Unlock slave pty */
pexit("Failed to unlock the slave pty"); pexit("Failed to unlock the slave pty");
} }
@ -146,9 +160,12 @@ int main(int argc, char *argv[])
/* Create the container */ /* Create the container */
if (terminal) { if (terminal) {
snprintf(cmd, CMD_SIZE, "runc create %s --pid-file pidfile --console %s", cid, slname); snprintf(cmd, CMD_SIZE,
"%s create %s --pid-file pidfile --console %s",
runtime_path, cid, slname);
} else { } else {
snprintf(cmd, CMD_SIZE, "runc create %s --pid-file pidfile", cid); snprintf(cmd, CMD_SIZE, "%s create %s --pid-file pidfile",
runtime_path, cid);
} }
ret = system(cmd); ret = system(cmd);
if (ret != 0) { if (ret != 0) {
@ -180,9 +197,11 @@ int main(int argc, char *argv[])
pexit("tcegetattr"); pexit("tcegetattr");
/* Settings for raw mode */ /* Settings for raw mode */
t.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL | IEXTEN); t.c_lflag &=
t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL | IEXTEN);
ISTRIP | IXON | IXOFF | IGNPAR | PARMRK); t.c_iflag &=
~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP |
IXON | IXOFF | IGNPAR | PARMRK);
t.c_oflag &= ~OPOST; t.c_oflag &= ~OPOST;
t.c_cc[VMIN] = 1; t.c_cc[VMIN] = 1;
t.c_cc[VTIME] = 0; t.c_cc[VTIME] = 0;
@ -214,33 +233,43 @@ int main(int argc, char *argv[])
for (int i = 0; i < ready; i++) { for (int i = 0; i < ready; i++) {
if (evlist[i].events & EPOLLIN) { if (evlist[i].events & EPOLLIN) {
if (evlist[i].data.fd == STDIN_FILENO) { if (evlist[i].data.fd == STDIN_FILENO) {
num_read = read(STDIN_FILENO, buf, BUF_SIZE); num_read =
read(STDIN_FILENO, buf,
BUF_SIZE);
if (num_read <= 0) if (num_read <= 0)
goto out; goto out;
if (write(mfd, buf, num_read) != num_read) { if (write(mfd, buf, num_read) !=
nwarn("partial/failed write (masterFd)"); num_read) {
nwarn
("partial/failed write (masterFd)");
goto out; goto out;
} }
} else if (evlist[i].data.fd == mfd) { } else if (evlist[i].data.fd == mfd) {
num_read = read(mfd, buf, BUF_SIZE); num_read =
read(mfd, buf, BUF_SIZE);
if (num_read <= 0) if (num_read <= 0)
goto out; goto out;
if (write(STDOUT_FILENO, buf, num_read) != num_read) { if (write
nwarn("partial/failed write (STDOUT_FILENO)"); (STDOUT_FILENO, buf,
num_read) != num_read) {
nwarn
("partial/failed write (STDOUT_FILENO)");
goto out; goto out;
} }
} }
} else if (evlist[i].events & (EPOLLHUP | EPOLLERR)) { } else if (evlist[i].events &
printf("closing fd %d\n", evlist[i].data.fd); (EPOLLHUP | EPOLLERR)) {
printf("closing fd %d\n",
evlist[i].data.fd);
if (close(evlist[i].data.fd) < 0) if (close(evlist[i].data.fd) < 0)
pexit("close"); pexit("close");
goto out; goto out;
} }
} }
} }
out: out:
tty_restore(); tty_restore();
} }
@ -253,9 +282,12 @@ out:
if (ret < 0) { if (ret < 0) {
pexit("Failed to allocate memory for status"); pexit("Failed to allocate memory for status");
} }
g_file_set_contents("exit", status_str, strlen(status_str), &err); g_file_set_contents("exit", status_str,
strlen(status_str), &err);
if (err) { if (err) {
fprintf(stderr, "Failed to write %s to exit file: %s\n", status_str, err->message); fprintf(stderr,
"Failed to write %s to exit file: %s\n",
status_str, err->message);
g_error_free(err); g_error_free(err);
exit(1); exit(1);
} }

View file

@ -85,6 +85,7 @@ func (r *Runtime) CreateContainer(c *Container) error {
defer parentPipe.Close() defer parentPipe.Close()
args := []string{"-c", c.name} args := []string{"-c", c.name}
args = append(args, "-r", r.path)
if c.terminal { if c.terminal {
args = append(args, "-t") args = append(args, "-t")
} }