From b0d49913d5351cf811bb89ce07a67d776bdfe36a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 5 Feb 2009 16:27:17 +0000 Subject: [PATCH] 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. --- ChangeLog | 9 +++++++++ src/libvirt_private.syms | 1 + src/qemu_driver.c | 39 ++++----------------------------------- src/util.c | 4 ++-- src/util.h | 1 + 5 files changed, 17 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index aca5e6bb5f..1674f50011 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Thu Feb 5 17:03:35 +0100 2009 Jim Meyering + + 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 qemu_driver.c: use virReportSystemError in place of some qemudLog uses diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 17aefbec8d..4338da7e4b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -292,6 +292,7 @@ virEnumToString; virEventAddHandle; virEventRemoveHandle; virExec; +virSetCloseExec; virSetNonBlock; virFormatMacAddr; virGetHostname; diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 3a790c1fea..8d8d711cba 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -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; diff --git a/src/util.c b/src/util.c index 7c7fe3134c..96c1b00aef 100644 --- a/src/util.c +++ b/src/util.c @@ -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; diff --git a/src/util.h b/src/util.h index c5532648b9..4667b92e2f 100644 --- a/src/util.h +++ b/src/util.h @@ -39,6 +39,7 @@ enum { }; int virSetNonBlock(int fd); +int virSetCloseExec(int fd); int virExec(virConnectPtr conn, const char *const*argv,