[libvirt] [PATCH 2/9] remove duplicate *SetCloseExec and *SetNonBlock functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jim Meyering <meyering@xxxxxxxxxx>

* src/qemu_driver.c: Use virSetCloseExec and virSetNonBlock,
rather than qemuSet* functions.  Suggested by Daniel P. Berrange.
* src/util.c (virSetCloseExec): Compile unconditionally.
* src/util.h (virSetCloseExec): Declare

libvirtd: link with libvirt_util, too
* qemud/Makefile.am (libvirtd_LDADD): Add ../src/libvirt_util.la,
for use of virSetCloseExec.
---
 qemud/Makefile.am |    1 +
 src/qemu_driver.c |   27 ++++-----------------------
 src/util.c        |    9 ++++-----
 src/util.h        |    1 +
 4 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/qemud/Makefile.am b/qemud/Makefile.am
index a0c161a..372b931 100644
--- a/qemud/Makefile.am
+++ b/qemud/Makefile.am
@@ -107,6 +107,7 @@ libvirtd_LDADD =					\
 if ! WITH_DRIVER_MODULES
 if WITH_QEMU
 libvirtd_LDADD += ../src/libvirt_driver_qemu.la
+libvirtd_LDADD += ../src/libvirt_util.la
 endif

 if WITH_LXC
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 596d940..c40fda4 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -91,25 +91,6 @@ static void qemuDriverUnlock(struct qemud_driver *driver)
     virMutexUnlock(&driver->lock);
 }

-static int qemudSetCloseExec(int fd) {
-    int flags;
-    return ((flags = fcntl(fd, F_GETFD)) < 0
-             || fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0
-            ? -1
-            : 0);
-}
-
-
-static int qemudSetNonBlock(int fd) {
-    int flags;
-    return ((flags = fcntl(fd, F_GETFL)) < 0
-             || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0
-            ? -1
-            : 0);
-}
-
-
-
 static void qemuDomainEventFlush(int timer, void *opaque);
 static void qemuDomainEventQueue(struct qemud_driver *driver,
                                  virDomainEventPtr event);
@@ -168,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);
@@ -200,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);
@@ -710,12 +691,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 7c7fe31..6c29872 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
@@ -182,10 +182,7 @@ int virSetNonBlock(int fd) {
     return 0;
 }

-
-#ifndef WIN32
-
-static int virSetCloseExec(int fd) {
+int virSetCloseExec(int fd) {
     int flags;
     if ((flags = fcntl(fd, F_GETFD)) < 0)
         return -1;
@@ -195,6 +192,8 @@ static int virSetCloseExec(int fd) {
     return 0;
 }

+#ifndef WIN32
+
 static int
 __virExec(virConnectPtr conn,
           const char *const*argv,
diff --git a/src/util.h b/src/util.h
index e731ba4..62df202 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,
-- 
1.6.1.2.418.gd79e6

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]