mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-09-06 13:41:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6680827faf | ||
|
|
7699c38b99 |
@@ -10,6 +10,7 @@
|
|||||||
init
|
init
|
||||||
build/hyper_daemon
|
build/hyper_daemon
|
||||||
build/hyper-initrd.img
|
build/hyper-initrd.img
|
||||||
|
build/cbfs.rom
|
||||||
build/root/*
|
build/root/*
|
||||||
build/*iso
|
build/*iso
|
||||||
build/daemon
|
build/daemon
|
||||||
|
|||||||
+8
-1
@@ -370,12 +370,12 @@ fail:
|
|||||||
int hyper_start_container(struct hyper_container *container)
|
int hyper_start_container(struct hyper_container *container)
|
||||||
{
|
{
|
||||||
int stacksize = getpagesize() * 4;
|
int stacksize = getpagesize() * 4;
|
||||||
void *stack = malloc(stacksize);
|
|
||||||
struct hyper_container_arg arg = {
|
struct hyper_container_arg arg = {
|
||||||
.c = container,
|
.c = container,
|
||||||
};
|
};
|
||||||
int flags = CLONE_NEWNS | SIGCHLD;
|
int flags = CLONE_NEWNS | SIGCHLD;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
|
void *stack;
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
if (container->image == NULL || container->exec.argv == NULL) {
|
if (container->image == NULL || container->exec.argv == NULL) {
|
||||||
@@ -389,6 +389,12 @@ int hyper_start_container(struct hyper_container *container)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stack = malloc(stacksize);
|
||||||
|
if (stack == NULL) {
|
||||||
|
perror("fail to allocate stack for container init");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pid = clone(hyper_container_init, stack + stacksize, flags, &arg);
|
pid = clone(hyper_container_init, stack + stacksize, flags, &arg);
|
||||||
free(stack);
|
free(stack);
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
@@ -412,6 +418,7 @@ int hyper_start_container(struct hyper_container *container)
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
fprintf(stdout, "container %s init exit code %d\n", container->id, -1);
|
fprintf(stdout, "container %s init exit code %d\n", container->id, -1);
|
||||||
|
|
||||||
container->exec.code = -1;
|
container->exec.code = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
+87
-1
@@ -631,12 +631,98 @@ static void hyper_print_uptime(void)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hyper_kill_process(int pid)
|
||||||
|
{
|
||||||
|
char path[64];
|
||||||
|
char *line = NULL, *ignore = "SigIgn:";
|
||||||
|
size_t len = 0;
|
||||||
|
ssize_t read;
|
||||||
|
FILE *file;
|
||||||
|
char *sub;
|
||||||
|
|
||||||
|
sprintf(path, "/proc/%u/status", pid);
|
||||||
|
|
||||||
|
fprintf(stdout, "fopen %s\n", path);
|
||||||
|
file = fopen(path, "r");
|
||||||
|
if (file == NULL) {
|
||||||
|
perror("can not open process proc status file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((read = getline(&line, &len, file)) != -1) {
|
||||||
|
long mask;
|
||||||
|
|
||||||
|
if (strstr(line, ignore) == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sub = line + strlen(ignore);
|
||||||
|
fprintf(stdout, "find sigign %s", sub);
|
||||||
|
|
||||||
|
mask = atol(sub);
|
||||||
|
fprintf(stdout, "mask is %ld\n", mask);
|
||||||
|
|
||||||
|
if ((mask >> (SIGTERM - 1)) & 0x1) {
|
||||||
|
fprintf(stdout, "signal term is ignored, kill it\n");
|
||||||
|
kill(pid, SIGKILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hyper_term_all(struct hyper_pod *pod)
|
||||||
|
{
|
||||||
|
int npids = 0;
|
||||||
|
int index = 0;
|
||||||
|
int pid;
|
||||||
|
DIR *dp;
|
||||||
|
struct dirent *de;
|
||||||
|
pid_t *pids = NULL;
|
||||||
|
|
||||||
|
dp = opendir("/proc");
|
||||||
|
if (dp == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while ((de = readdir(dp)) && de != NULL) {
|
||||||
|
if (!isdigit(de->d_name[0]))
|
||||||
|
continue;
|
||||||
|
pid = atoi(de->d_name);
|
||||||
|
if (pid == 1)
|
||||||
|
continue;
|
||||||
|
if (index <= npids) {
|
||||||
|
pids = realloc(pids, npids + 16384);
|
||||||
|
if (pids == NULL)
|
||||||
|
return;
|
||||||
|
npids += 16384;
|
||||||
|
}
|
||||||
|
|
||||||
|
pids[index++] = pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "Sending SIGTERM\n");
|
||||||
|
|
||||||
|
for (--index; index >= 0; --index) {
|
||||||
|
fprintf(stdout, "kill process %d\n", pids[index]);
|
||||||
|
kill(pids[index], SIGTERM);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pids);
|
||||||
|
closedir(dp);
|
||||||
|
|
||||||
|
for (index = 0; index < pod->c_num; index++) {
|
||||||
|
hyper_kill_process(pod->c[index].exec.pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void hyper_cleanup_pod(struct hyper_pod *pod)
|
static void hyper_cleanup_pod(struct hyper_pod *pod)
|
||||||
{
|
{
|
||||||
close(pod->sig.fd);
|
close(pod->sig.fd);
|
||||||
hyper_reset_event(&pod->sig);
|
hyper_reset_event(&pod->sig);
|
||||||
|
|
||||||
hyper_kill_all();
|
hyper_term_all(pod);
|
||||||
hyper_handle_exit(pod, pod->ctl.fd, 1, 0);
|
hyper_handle_exit(pod, pod->ctl.fd, 1, 0);
|
||||||
|
|
||||||
pod->init_pid = 0;
|
pod->init_pid = 0;
|
||||||
|
|||||||
+1
-1
@@ -406,7 +406,7 @@ void hyper_shutdown(struct hyper_pod *pod)
|
|||||||
{
|
{
|
||||||
hyper_send_finish(pod);
|
hyper_send_finish(pod);
|
||||||
|
|
||||||
hyper_kill_all();
|
//hyper_kill_all();
|
||||||
|
|
||||||
hyper_unmount_all();
|
hyper_unmount_all();
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ int hyper_setfd_block(int fd);
|
|||||||
int hyper_setfd_nonblock(int fd);
|
int hyper_setfd_nonblock(int fd);
|
||||||
void hyper_shutdown(struct hyper_pod *pod);
|
void hyper_shutdown(struct hyper_pod *pod);
|
||||||
int hyper_send_finish(struct hyper_pod *pod);
|
int hyper_send_finish(struct hyper_pod *pod);
|
||||||
void hyper_kill_all(void);
|
|
||||||
void hyper_unmount_all(void);
|
void hyper_unmount_all(void);
|
||||||
int hyper_insmod(char *module);
|
int hyper_insmod(char *module);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user