Fix containers not being shut down
This commit is contained in:
parent
a75dd1b0ec
commit
76d0770038
|
@ -107,14 +107,16 @@ void session(char *uuid, char *lang, char *imageHash)
|
||||||
"--user", "root",
|
"--user", "root",
|
||||||
"--hostname", lang,
|
"--hostname", lang,
|
||||||
"--name", container,
|
"--name", container,
|
||||||
image, "cat", "/var/run/riju/sentinel/fifo", NULL,
|
image, "bash", "-c",
|
||||||
|
"cat /var/run/riju/sentinel/fifo | while read -t2; do :; done",
|
||||||
|
NULL,
|
||||||
};
|
};
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
die("execvp failed");
|
die("execvp failed");
|
||||||
}
|
}
|
||||||
struct timespec ts; // 10ms
|
struct timespec ts_10ms; // 10ms
|
||||||
ts.tv_sec = 0;
|
ts_10ms.tv_sec = 0;
|
||||||
ts.tv_nsec = 1000 * 1000 * 10;
|
ts_10ms.tv_nsec = 1000 * 1000 * 10;
|
||||||
signal(SIGALRM, wait_alarm);
|
signal(SIGALRM, wait_alarm);
|
||||||
alarm(1);
|
alarm(1);
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -124,7 +126,7 @@ void session(char *uuid, char *lang, char *imageHash)
|
||||||
break;
|
break;
|
||||||
if (errno != ENXIO)
|
if (errno != ENXIO)
|
||||||
die("open failed");
|
die("open failed");
|
||||||
int rv = nanosleep(&ts, NULL);
|
int rv = nanosleep(&ts_10ms, NULL);
|
||||||
if (rv != 0 && errno != EINTR)
|
if (rv != 0 && errno != EINTR)
|
||||||
die("nanosleep failed");
|
die("nanosleep failed");
|
||||||
}
|
}
|
||||||
|
@ -133,6 +135,22 @@ void session(char *uuid, char *lang, char *imageHash)
|
||||||
die("unlink failed");
|
die("unlink failed");
|
||||||
if (rmdir(tmpdir) < 0)
|
if (rmdir(tmpdir) < 0)
|
||||||
die("rmdir failed");
|
die("rmdir failed");
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0)
|
||||||
|
die("fork failed");
|
||||||
|
else if (pid == 0) {
|
||||||
|
struct timespec ts_1s; // 10ms
|
||||||
|
ts_1s.tv_sec = 1;
|
||||||
|
ts_1s.tv_nsec = 0;
|
||||||
|
while (1) {
|
||||||
|
static const char ok[] = "ok\n";
|
||||||
|
if (write(fd, ok, sizeof(ok) / sizeof(char)) < 0)
|
||||||
|
die("write failed");
|
||||||
|
int rv = nanosleep(&ts_1s, NULL);
|
||||||
|
if (rv != 0 && errno != EINTR)
|
||||||
|
die("nanosleep failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
printf("riju: container ready\n"); // magic string
|
printf("riju: container ready\n"); // magic string
|
||||||
if (waitpid(pid, NULL, 0) <= 0)
|
if (waitpid(pid, NULL, 0) <= 0)
|
||||||
die("waitpid failed");
|
die("waitpid failed");
|
||||||
|
|
Loading…
Reference in New Issue