Hi,
attached patch splits out the qemu logfile opening into a separate
function which makes the code a bit more readable and I'll need this for
the libvirtd restart code.
Cheers,
-- Guido
>From b65295d7693274fb84a21597cafc9628799dacf7 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <[email protected]>
Date: Mon, 29 Dec 2008 14:37:06 +0100
Subject: [PATCH] split out opening of the domain logfile
---
src/qemu_driver.c | 83 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 47 insertions(+), 36 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 9a12b0b..cb61429 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -143,6 +143,52 @@ static int qemudMonitorCommand (const virDomainObjPtr vm,
static struct qemud_driver *qemu_driver = NULL;
+static int
+qemudLogFD(virConnectPtr conn, const char* logDir, const char* name)
+{
+ char logfile[PATH_MAX];
+ mode_t logmode;
+ uid_t uid = geteuid();
+ int fd = -1;
+
+ if ((strlen(logDir) + /* path */
+ 1 + /* Separator */
+ strlen(name) + /* basename */
+ 4 + /* suffix .log */
+ 1 /* NULL */) > PATH_MAX) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("config file path too long: %s/%s.log"),
+ logDir, name);
+ return -1;
+ }
+
+ strcpy(logfile, logDir);
+ strcat(logfile, "/");
+ strcat(logfile, name);
+ strcat(logfile, ".log");
+
+ logmode = O_CREAT | O_WRONLY;
+ if (uid != 0)
+ logmode |= O_TRUNC;
+ else
+ logmode |= O_APPEND;
+ if ((fd = open(logfile, logmode, S_IRUSR | S_IWUSR)) < 0) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("failed to create logfile %s: %s"),
+ logfile, strerror(errno));
+ return -1;
+ }
+ if (qemudSetCloseExec(fd) < 0) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Unable to set VM logfile close-on-exec flag %s"),
+ strerror(errno));
+ close(fd);
+ return -1;
+ }
+ return fd;
+}
+
+
static void
qemudAutostartConfigs(struct qemud_driver *driver) {
unsigned int i;
@@ -892,15 +938,12 @@ static int qemudStartVMDaemon(virConnectPtr conn,
const char **argv = NULL, **tmp;
const char **progenv = NULL;
int i, ret;
- char logfile[PATH_MAX];
struct stat sb;
int *tapfds = NULL;
int ntapfds = 0;
unsigned int qemuCmdFlags;
fd_set keepfd;
const char *emulator;
- uid_t uid = geteuid();
- mode_t logmode;
FD_ZERO(&keepfd);
@@ -922,21 +965,6 @@ static int qemudStartVMDaemon(virConnectPtr conn,
vm->def->graphics->data.vnc.port = port;
}
- if ((strlen(driver->logDir) + /* path */
- 1 + /* Separator */
- strlen(vm->def->name) + /* basename */
- 4 + /* suffix .log */
- 1 /* NULL */) > PATH_MAX) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("config file path too long: %s/%s.log"),
- driver->logDir, vm->def->name);
- return -1;
- }
- strcpy(logfile, driver->logDir);
- strcat(logfile, "/");
- strcat(logfile, vm->def->name);
- strcat(logfile, ".log");
-
if (virFileMakePath(driver->logDir) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("cannot create log directory %s: %s"),
@@ -944,25 +972,8 @@ static int qemudStartVMDaemon(virConnectPtr conn,
return -1;
}
- logmode = O_CREAT | O_WRONLY;
- if (uid != 0)
- logmode |= O_TRUNC;
- else
- logmode |= O_APPEND;
- if ((vm->logfile = open(logfile, logmode, S_IRUSR | S_IWUSR)) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to create logfile %s: %s"),
- logfile, strerror(errno));
+ if((vm->logfile = qemudLogFD(conn, driver->logDir, vm->def->name)) < 0)
return -1;
- }
- if (qemudSetCloseExec(vm->logfile) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Unable to set VM logfile close-on-exec flag %s"),
- strerror(errno));
- close(vm->logfile);
- vm->logfile = -1;
- return -1;
- }
emulator = vm->def->emulator;
if (!emulator)
--
1.6.0.3
--
Libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list