lxc: Refactor controller command building

Arranges things similar to the qemu driver. Will allow us to more easily
report command error output.
This commit is contained in:
Cole Robinson 2011-06-01 16:38:09 -04:00
parent 6973594ca8
commit af1e180f48

View File

@ -1281,7 +1281,8 @@ cleanup:
} }
static int lxcControllerStart(lxc_driver_t *driver, static virCommandPtr
lxcBuildControllerCmd(lxc_driver_t *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
int nveths, int nveths,
char **veths, char **veths,
@ -1289,13 +1290,9 @@ static int lxcControllerStart(lxc_driver_t *driver,
int logfile) int logfile)
{ {
int i; int i;
int ret = -1;
char *filterstr; char *filterstr;
char *outputstr; char *outputstr;
virCommandPtr cmd; virCommandPtr cmd;
off_t pos = -1;
char ebuf[1024];
char *timestamp;
cmd = virCommandNew(vm->def->emulator); cmd = virCommandNew(vm->def->emulator);
@ -1357,33 +1354,14 @@ static int lxcControllerStart(lxc_driver_t *driver,
goto cleanup; goto cleanup;
} }
/* Log timestamp */
if ((timestamp = virTimestamp()) == NULL) {
virReportOOMError();
goto cleanup;
}
if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 ||
safewrite(logfile, START_POSTFIX, strlen(START_POSTFIX)) < 0) {
VIR_WARN("Unable to write timestamp to logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
}
VIR_FREE(timestamp);
/* Log generated command line */
virCommandWriteArgLog(cmd, logfile);
if ((pos = lseek(logfile, 0, SEEK_END)) < 0)
VIR_WARN("Unable to seek to end of logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
virCommandPreserveFD(cmd, appPty); virCommandPreserveFD(cmd, appPty);
virCommandSetOutputFD(cmd, &logfile); virCommandSetOutputFD(cmd, &logfile);
virCommandSetErrorFD(cmd, &logfile); virCommandSetErrorFD(cmd, &logfile);
ret = virCommandRun(cmd, NULL); return cmd;
cleanup: cleanup:
virCommandFree(cmd); virCommandFree(cmd);
return ret; return NULL;
} }
@ -1411,6 +1389,10 @@ static int lxcVmStart(virConnectPtr conn,
int logfd = -1; int logfd = -1;
unsigned int nveths = 0; unsigned int nveths = 0;
char **veths = NULL; char **veths = NULL;
off_t pos = -1;
char ebuf[1024];
char *timestamp;
virCommandPtr cmd = NULL;
lxcDomainObjPrivatePtr priv = vm->privateData; lxcDomainObjPrivatePtr priv = vm->privateData;
if (!lxc_driver->cgroup) { if (!lxc_driver->cgroup) {
@ -1480,10 +1462,31 @@ static int lxcVmStart(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (lxcControllerStart(driver, if (!(cmd = lxcBuildControllerCmd(driver,
vm, vm,
nveths, veths, nveths, veths,
parentTty, logfd) < 0) parentTty, logfd)))
goto cleanup;
/* Log timestamp */
if ((timestamp = virTimestamp()) == NULL) {
virReportOOMError();
goto cleanup;
}
if (safewrite(logfd, timestamp, strlen(timestamp)) < 0 ||
safewrite(logfd, START_POSTFIX, strlen(START_POSTFIX)) < 0) {
VIR_WARN("Unable to write timestamp to logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
}
VIR_FREE(timestamp);
/* Log generated command line */
virCommandWriteArgLog(cmd, logfd);
if ((pos = lseek(logfd, 0, SEEK_END)) < 0)
VIR_WARN("Unable to seek to end of logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
if (virCommandRun(cmd, NULL) < 0)
goto cleanup; goto cleanup;
/* Connect to the controller as a client *first* because /* Connect to the controller as a client *first* because
@ -1529,6 +1532,7 @@ static int lxcVmStart(virConnectPtr conn,
rc = 0; rc = 0;
cleanup: cleanup:
virCommandFree(cmd);
if (VIR_CLOSE(logfd) < 0) { if (VIR_CLOSE(logfd) < 0) {
virReportSystemError(errno, "%s", _("could not close logfile")); virReportSystemError(errno, "%s", _("could not close logfile"));
rc = -1; rc = -1;