Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ enum {
PROCESSASYNCEVENT,
};

// "hyperstart" is the special container ID for adding processes.
//
// The processes will be execve()-ed in the same namespaces as the
// hyperstart(init) process rather than in any container.
// This operation is "hyperstart-exec"
#define HYPERSTART_EXEC_CONTAINER "hyperstart"

/*
* control message format
* | ctrl id | length | payload (length-8) |
Expand Down
4 changes: 4 additions & 0 deletions src/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _CONTAINER_H_

#include "exec.h"
#include "api.h"

struct volume {
char *device;
Expand Down Expand Up @@ -61,4 +62,7 @@ void hyper_cleanup_container(struct hyper_container *container, struct hyper_pod
void hyper_cleanup_containers(struct hyper_pod *pod);
void hyper_free_container(struct hyper_container *c);

static inline int hyper_has_container(struct hyper_pod *pod, const char *id) {
return strcmp(id, HYPERSTART_EXEC_CONTAINER) == 0 || hyper_find_container(pod, id) != NULL;
}
#endif
7 changes: 6 additions & 1 deletion src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ int hyper_exec_cmd(struct hyper_pod *pod, char *json, int length)
return -1;
}

if (hyper_find_container(pod, exec->container_id) == NULL) {
if (!hyper_has_container(pod, exec->container_id)) {
fprintf(stderr, "call hyper_exec_cmd, no such container: %s\n", exec->container_id);
hyper_free_exec(exec);
return -1;
Expand Down Expand Up @@ -646,6 +646,11 @@ int hyper_run_process(struct hyper_exec *exec)
perror("fork prerequisite process failed");
goto close_tty;
} else if (pid == 0) {
if (strcmp(exec->container_id, HYPERSTART_EXEC_CONTAINER) == 0) {
hyper_send_type(pipe[1], getpid());
hyper_exec_process(exec, &io);
_exit(125);
}
hyper_do_exec_cmd(exec, pipe[1], &io);
}
fprintf(stdout, "prerequisite process pid %d\n", pid);
Expand Down
22 changes: 21 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,22 @@ static int hyper_setup_shared(struct hyper_pod *pod)
}
#endif

static int hyper_setup_virtual_hyperstart_exec_container(struct hyper_pod *pod)
{
if (hyper_mkdir("/tmp/hyper/" HYPERSTART_EXEC_CONTAINER, 0755) < 0) {
perror("create virtual hyperstart-exec container directory failed");
return -1;
}

// for creating ptymaster when adding process with terminal=true
if (symlink("/dev/pts", "/tmp/hyper/" HYPERSTART_EXEC_CONTAINER "/devpts") < 0) {
perror("create virtual hyperstart-exec container's /dev symlink failed");
return -1;
}

return 0;
}

static int hyper_setup_pod(struct hyper_pod *pod)
{
/* create sandbox directory */
Expand Down Expand Up @@ -505,6 +521,10 @@ static int hyper_setup_pod(struct hyper_pod *pod)
return -1;
}

if (hyper_setup_virtual_hyperstart_exec_container(pod) < 0) {
return -1;
}

return 0;
}

Expand Down Expand Up @@ -599,7 +619,7 @@ static int hyper_new_container(struct hyper_pod *pod, char *json, int length)
return -1;
}

if (hyper_find_container(pod, c->id) != NULL) {
if (hyper_has_container(pod, c->id)) {
fprintf(stderr, "container id conflicts");
hyper_cleanup_container(c, pod);
return -1;
Expand Down