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

[libvirt] [PATCHv2 24/27] build: don't hand-roll cloexec code



No need to repeat common code.

* src/util/bridge.c (brInit): Use virSetCloseExec.
(brSetInterfaceUp): Prefer unsigned flags.
* src/uml/uml_driver.c (umlSetCloseExec): Delete.
(umlStartVMDaemon): Use util version instead.
---

v2: new patch

 src/uml/uml_driver.c |   19 +++----------------
 src/util/bridge.c    |   19 +++++--------------
 2 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 9f66aee..801015a 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -113,19 +113,6 @@ static int umlOpenMonitor(struct uml_driver *driver,
 static int umlReadPidFile(struct uml_driver *driver,
                           virDomainObjPtr vm);

-static int umlSetCloseExec(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:
-    VIR_ERROR(_("Failed to set close-on-exec file descriptor flag"));
-    return -1;
-}
-
 static int umlStartVMDaemon(virConnectPtr conn,
                             struct uml_driver *driver,
                             virDomainObjPtr vm);
@@ -862,9 +849,9 @@ static int umlStartVMDaemon(virConnectPtr conn,
     }
     VIR_FREE(logfile);

-    if (umlSetCloseExec(logfd) < 0) {
-        virReportSystemError(errno,
-                             "%s", _("Unable to set VM logfile close-on-exec flag"));
+    if (virSetCloseExec(logfd) < 0) {
+        virReportSystemError(errno, "%s",
+                             _("Unable to set VM logfile close-on-exec flag"));
         VIR_FORCE_CLOSE(logfd);
         return -1;
     }
diff --git a/src/util/bridge.c b/src/util/bridge.c
index 7204e64..a6b5768 100644
--- a/src/util/bridge.c
+++ b/src/util/bridge.c
@@ -72,25 +72,16 @@ int
 brInit(brControl **ctlp)
 {
     int fd;
-    int flags;

     if (!ctlp || *ctlp)
         return EINVAL;

     fd = socket(AF_INET, SOCK_STREAM, 0);
-    if (fd < 0)
-        return errno;
-
-    if ((flags = fcntl(fd, F_GETFD)) < 0 ||
-        fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
-        int err = errno;
-        VIR_FORCE_CLOSE(fd);
-        return err;
-    }
-
-    if (VIR_ALLOC(*ctlp) < 0) {
+    if (fd < 0 ||
+        virSetCloseExec(fd) < 0 ||
+        VIR_ALLOC(*ctlp) < 0) {
         VIR_FORCE_CLOSE(fd);
-        return ENOMEM;
+        return errno;
     }

     (*ctlp)->fd = fd;
@@ -599,7 +590,7 @@ brSetInterfaceUp(brControl *ctl,
                  int up)
 {
     struct ifreq ifr;
-    int flags;
+    unsigned int flags;

     if (!ctl || !ifname)
         return EINVAL;
-- 
1.7.4.4


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