char **veths;
int monitor;
char *ttyPath;
+ int handshakefd;
};
*
* Returns 0 on success or -1 in case of error
*/
-static int lxcContainerSetStdio(int control, int ttyfd)
+static int lxcContainerSetStdio(int control, int ttyfd, int handshakefd)
{
int rc = -1;
int open_max, i;
* close all FDs before executing the container */
open_max = sysconf (_SC_OPEN_MAX);
for (i = 0; i < open_max; i++)
- if (i != ttyfd && i != control) {
+ if (i != ttyfd && i != control && i != handshakefd) {
int tmpfd = i;
VIR_FORCE_CLOSE(tmpfd);
}
if (lxcContainerDropCapabilities() < 0)
goto cleanup;
- if (lxcContainerSetStdio(argv->monitor, ttyfd) < 0) {
+ if (lxcContainerSendContinue(argv->handshakefd) < 0) {
+ virReportSystemError(errno, "%s",
+ _("failed to send continue signal to controller"));
+ goto cleanup;
+ }
+
+ if (lxcContainerSetStdio(argv->monitor, ttyfd, argv->handshakefd) < 0) {
goto cleanup;
}
VIR_FREE(ttyPath);
VIR_FORCE_CLOSE(ttyfd);
VIR_FORCE_CLOSE(argv->monitor);
+ VIR_FORCE_CLOSE(argv->handshakefd);
if (ret == 0) {
/* this function will only return if an error occured */
unsigned int nveths,
char **veths,
int control,
+ int handshakefd,
char *ttyPath)
{
pid_t pid;
int flags;
int stacksize = getpagesize() * 4;
char *stack, *stacktop;
- lxc_child_argv_t args = { def, nveths, veths, control, ttyPath };
+ lxc_child_argv_t args = { def, nveths, veths, control, ttyPath,
+ handshakefd};
/* allocate a stack for the container */
if (VIR_ALLOC_N(stack, stacksize) < 0) {
{
int rc = -1;
int control[2] = { -1, -1};
+ int containerhandshake[2] = { -1, -1 };
int containerPty = -1;
char *containerPtyPath = NULL;
pid_t container = -1;
goto cleanup;
}
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, containerhandshake) < 0) {
+ virReportSystemError(errno, "%s",
+ _("socketpair failed"));
+ goto cleanup;
+ }
+
root = virDomainGetRootFilesystem(def);
if (lxcSetContainerResources(def) < 0)
nveths,
veths,
control[1],
+ containerhandshake[1],
containerPtyPath)) < 0)
goto cleanup;
VIR_FORCE_CLOSE(control[1]);
+ VIR_FORCE_CLOSE(containerhandshake[1]);
if (lxcControllerMoveInterfaces(nveths, veths, container) < 0)
goto cleanup;
goto cleanup;
}
+ if (lxcContainerWaitForContinue(containerhandshake[0]) < 0) {
+ virReportSystemError(errno, "%s",
+ _("error receiving signal from container"));
+ goto cleanup;
+ }
+
/* Now the container is running, there's no need for us to keep
any elevated capabilities */
if (lxcControllerClearCapabilities() < 0)
VIR_FREE(containerPtyPath);
VIR_FORCE_CLOSE(containerPty);
VIR_FORCE_CLOSE(handshakefd);
+ VIR_FORCE_CLOSE(containerhandshake[0]);
+ VIR_FORCE_CLOSE(containerhandshake[1]);
if (container > 1) {
int status;