remove duplicate *SetCloseExec and *SetNonBlock functions

* src/qemu_driver.c: Use virSetCloseExec and virSetNonBlock,
rather than qemuSet* functions.  Suggested by Daniel P. Berrange.
* src/util.c (virSetCloseExec): Publicize.
* src/util.h (virSetCloseExec): Declare
* src/libvirt_private.syms: Add virSetCloseExec.
This commit is contained in:
Jim Meyering 2009-02-05 16:27:17 +00:00
parent 22c9bf6d8b
commit b0d49913d5
5 changed files with 17 additions and 37 deletions

View File

@ -1,3 +1,12 @@
Thu Feb 5 17:03:35 +0100 2009 Jim Meyering <meyering@redhat.com>
remove duplicate *SetCloseExec and *SetNonBlock functions
* src/qemu_driver.c: Use virSetCloseExec and virSetNonBlock,
rather than qemuSet* functions. Suggested by Daniel P. Berrange.
* src/util.c (virSetCloseExec): Publicize.
* src/util.h (virSetCloseExec): Declare
* src/libvirt_private.syms: Add virSetCloseExec.
Thu Feb 5 17:03:35 +0100 2009 Jim Meyering <meyering@redhat.com>
qemu_driver.c: use virReportSystemError in place of some qemudLog uses

View File

@ -292,6 +292,7 @@ virEnumToString;
virEventAddHandle;
virEventRemoveHandle;
virExec;
virSetCloseExec;
virSetNonBlock;
virFormatMacAddr;
virGetHostname;

View File

@ -91,37 +91,6 @@ static void qemuDriverUnlock(struct qemud_driver *driver)
virMutexUnlock(&driver->lock);
}
static int qemudSetCloseExec(int fd) {
int flags;
if ((flags = fcntl(fd, F_GETFD)) < 0)
goto error;
flags |= FD_CLOEXEC;
if ((fcntl(fd, F_SETFD, flags)) < 0)
goto error;
return 0;
error:
qemudLog(QEMUD_ERR,
"%s", _("Failed to set close-on-exec file descriptor flag\n"));
return -1;
}
static int qemudSetNonBlock(int fd) {
int flags;
if ((flags = fcntl(fd, F_GETFL)) < 0)
goto error;
flags |= O_NONBLOCK;
if ((fcntl(fd, F_SETFL, flags)) < 0)
goto error;
return 0;
error:
qemudLog(QEMUD_ERR,
"%s", _("Failed to set non-blocking file descriptor flag\n"));
return -1;
}
static void qemuDomainEventFlush(int timer, void *opaque);
static void qemuDomainEventQueue(struct qemud_driver *driver,
virDomainEventPtr event);
@ -180,7 +149,7 @@ qemudLogFD(virConnectPtr conn, const char* logDir, const char* name)
logfile);
return -1;
}
if (qemudSetCloseExec(fd) < 0) {
if (virSetCloseExec(fd) < 0) {
virReportSystemError(conn, errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
close(fd);
@ -212,7 +181,7 @@ qemudLogReadFD(virConnectPtr conn, const char* logDir, const char* name, off_t p
logfile);
return -1;
}
if (qemudSetCloseExec(fd) < 0) {
if (virSetCloseExec(fd) < 0) {
virReportSystemError(conn, errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
close(fd);
@ -721,12 +690,12 @@ static int qemudOpenMonitor(virConnectPtr conn,
_("Unable to open monitor path %s"), monitor);
return -1;
}
if (qemudSetCloseExec(monfd) < 0) {
if (virSetCloseExec(monfd) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"%s", _("Unable to set monitor close-on-exec flag"));
goto error;
}
if (qemudSetNonBlock(monfd) < 0) {
if (virSetNonBlock(monfd) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"%s", _("Unable to put monitor into non-blocking mode"));
goto error;

View File

@ -1,7 +1,7 @@
/*
* utils.c: common, generic utility functions
*
* Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
* Copyright (C) 2006, 2007, 2008, 2009 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
* Copyright (C) 2006, 2007 Binary Karma
* Copyright (C) 2006 Shuveb Hussain
@ -185,7 +185,7 @@ int virSetNonBlock(int fd) {
#ifndef WIN32
static int virSetCloseExec(int fd) {
int virSetCloseExec(int fd) {
int flags;
if ((flags = fcntl(fd, F_GETFD)) < 0)
return -1;

View File

@ -39,6 +39,7 @@ enum {
};
int virSetNonBlock(int fd);
int virSetCloseExec(int fd);
int virExec(virConnectPtr conn,
const char *const*argv,