mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Store the init PID in the virLXCController object
Keep a record of the init PID in the virLXCController object and create a virLXCControllerStopInit method for killing this process Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
ba797c73e6
commit
7a4bf9c39c
@ -86,6 +86,8 @@ struct _virLXCController {
|
|||||||
char *name;
|
char *name;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr def;
|
||||||
|
|
||||||
|
pid_t initpid;
|
||||||
|
|
||||||
size_t nveths;
|
size_t nveths;
|
||||||
char **veths;
|
char **veths;
|
||||||
};
|
};
|
||||||
@ -130,6 +132,17 @@ error:
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void virLXCControllerStopInit(virLXCControllerPtr ctrl)
|
||||||
|
{
|
||||||
|
if (ctrl->initpid == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
virPidAbort(ctrl->initpid);
|
||||||
|
ctrl->initpid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -137,6 +150,8 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
|||||||
if (!ctrl)
|
if (!ctrl)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
virLXCControllerStopInit(ctrl);
|
||||||
|
|
||||||
for (i = 0 ; i < ctrl->nveths ; i++)
|
for (i = 0 ; i < ctrl->nveths ; i++)
|
||||||
VIR_FREE(ctrl->veths[i]);
|
VIR_FREE(ctrl->veths[i]);
|
||||||
VIR_FREE(ctrl->veths);
|
VIR_FREE(ctrl->veths);
|
||||||
@ -791,22 +806,23 @@ static bool quit = false;
|
|||||||
static virMutex lock;
|
static virMutex lock;
|
||||||
static int sigpipe[2];
|
static int sigpipe[2];
|
||||||
|
|
||||||
static void lxcSignalChildHandler(int signum ATTRIBUTE_UNUSED)
|
static void virLXCControllerSignalChildHandler(int signum ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
ignore_value(write(sigpipe[1], "1", 1));
|
ignore_value(write(sigpipe[1], "1", 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lxcSignalChildIO(int watch ATTRIBUTE_UNUSED,
|
static void virLXCControllerSignalChildIO(int watch ATTRIBUTE_UNUSED,
|
||||||
int fd ATTRIBUTE_UNUSED,
|
int fd ATTRIBUTE_UNUSED,
|
||||||
int events ATTRIBUTE_UNUSED, void *opaque)
|
int events ATTRIBUTE_UNUSED,
|
||||||
|
void *opaque)
|
||||||
{
|
{
|
||||||
char buf[1];
|
char buf[1];
|
||||||
int ret;
|
int ret;
|
||||||
int *container = opaque;
|
virLXCControllerPtr ctrl = opaque;
|
||||||
|
|
||||||
ignore_value(read(sigpipe[0], buf, 1));
|
ignore_value(read(sigpipe[0], buf, 1));
|
||||||
ret = waitpid(-1, NULL, WNOHANG);
|
ret = waitpid(-1, NULL, WNOHANG);
|
||||||
if (ret == *container) {
|
if (ret == ctrl->initpid) {
|
||||||
virMutexLock(&lock);
|
virMutexLock(&lock);
|
||||||
quit = true;
|
quit = true;
|
||||||
virMutexUnlock(&lock);
|
virMutexUnlock(&lock);
|
||||||
@ -1174,12 +1190,12 @@ error:
|
|||||||
*
|
*
|
||||||
* Returns 0 on success or -1 in case of error
|
* Returns 0 on success or -1 in case of error
|
||||||
*/
|
*/
|
||||||
static int lxcControllerMain(int serverFd,
|
static int virLXCControllerMain(virLXCControllerPtr ctrl,
|
||||||
|
int serverFd,
|
||||||
int clientFd,
|
int clientFd,
|
||||||
int *hostFds,
|
int *hostFds,
|
||||||
int *contFds,
|
int *contFds,
|
||||||
size_t nFds,
|
size_t nFds)
|
||||||
pid_t container)
|
|
||||||
{
|
{
|
||||||
struct lxcConsole *consoles = NULL;
|
struct lxcConsole *consoles = NULL;
|
||||||
struct lxcMonitor monitor = {
|
struct lxcMonitor monitor = {
|
||||||
@ -1201,15 +1217,15 @@ static int lxcControllerMain(int serverFd,
|
|||||||
|
|
||||||
if (virEventAddHandle(sigpipe[0],
|
if (virEventAddHandle(sigpipe[0],
|
||||||
VIR_EVENT_HANDLE_READABLE,
|
VIR_EVENT_HANDLE_READABLE,
|
||||||
lxcSignalChildIO,
|
virLXCControllerSignalChildIO,
|
||||||
&container,
|
ctrl,
|
||||||
NULL) < 0) {
|
NULL) < 0) {
|
||||||
lxcError(VIR_ERR_INTERNAL_ERROR, "%s",
|
lxcError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Unable to watch signal pipe"));
|
_("Unable to watch signal pipe"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signal(SIGCHLD, lxcSignalChildHandler) == SIG_ERR) {
|
if (signal(SIGCHLD, virLXCControllerSignalChildHandler) == SIG_ERR) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Cannot install signal handler"));
|
_("Cannot install signal handler"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1339,13 +1355,12 @@ cleanup2:
|
|||||||
*
|
*
|
||||||
* Returns 0 on success or -1 in case of error
|
* Returns 0 on success or -1 in case of error
|
||||||
*/
|
*/
|
||||||
static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl,
|
static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl)
|
||||||
pid_t container)
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0 ; i < ctrl->nveths ; i++) {
|
for (i = 0 ; i < ctrl->nveths ; i++) {
|
||||||
if (virNetDevSetNamespace(ctrl->veths[i], container) < 0)
|
if (virNetDevSetNamespace(ctrl->veths[i], ctrl->initpid) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1460,7 +1475,6 @@ virLXCControllerRun(virLXCControllerPtr ctrl,
|
|||||||
int containerhandshake[2] = { -1, -1 };
|
int containerhandshake[2] = { -1, -1 };
|
||||||
int *containerTtyFDs = NULL;
|
int *containerTtyFDs = NULL;
|
||||||
char **containerTtyPaths = NULL;
|
char **containerTtyPaths = NULL;
|
||||||
pid_t container = -1;
|
|
||||||
virDomainFSDefPtr root;
|
virDomainFSDefPtr root;
|
||||||
char *devpts = NULL;
|
char *devpts = NULL;
|
||||||
char *devptmx = NULL;
|
char *devptmx = NULL;
|
||||||
@ -1611,7 +1625,7 @@ virLXCControllerRun(virLXCControllerPtr ctrl,
|
|||||||
if (lxcSetPersonality(ctrl->def) < 0)
|
if (lxcSetPersonality(ctrl->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((container = lxcContainerStart(ctrl->def,
|
if ((ctrl->initpid = lxcContainerStart(ctrl->def,
|
||||||
securityDriver,
|
securityDriver,
|
||||||
ctrl->nveths,
|
ctrl->nveths,
|
||||||
ctrl->veths,
|
ctrl->veths,
|
||||||
@ -1623,7 +1637,7 @@ virLXCControllerRun(virLXCControllerPtr ctrl,
|
|||||||
VIR_FORCE_CLOSE(control[1]);
|
VIR_FORCE_CLOSE(control[1]);
|
||||||
VIR_FORCE_CLOSE(containerhandshake[1]);
|
VIR_FORCE_CLOSE(containerhandshake[1]);
|
||||||
|
|
||||||
if (virLXCControllerMoveInterfaces(ctrl, container) < 0)
|
if (virLXCControllerMoveInterfaces(ctrl) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (lxcContainerSendContinue(control[0]) < 0) {
|
if (lxcContainerSendContinue(control[0]) < 0) {
|
||||||
@ -1671,7 +1685,7 @@ virLXCControllerRun(virLXCControllerPtr ctrl,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = lxcControllerMain(monitor, client, ttyFDs, containerTtyFDs, nttyFDs, container);
|
rc = virLXCControllerMain(ctrl, monitor, client, ttyFDs, containerTtyFDs, nttyFDs);
|
||||||
monitor = client = -1;
|
monitor = client = -1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -1695,7 +1709,7 @@ cleanup:
|
|||||||
VIR_FORCE_CLOSE(loopDevs[i]);
|
VIR_FORCE_CLOSE(loopDevs[i]);
|
||||||
VIR_FREE(loopDevs);
|
VIR_FREE(loopDevs);
|
||||||
|
|
||||||
virPidAbort(container);
|
virLXCControllerStopInit(ctrl);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user