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

[Xen-changelog] [xen-unstable] Set the close-on-exec flag on the xenstore fd in libxenstore.



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID fdc4531aefe06f7092e6c2113be76cbefaf77bf2
# Parent  59adc1f7dfca2e3182289fa2d422ddf1810016e9
Set the close-on-exec flag on the xenstore fd in libxenstore.
Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tools/xenstore/xs.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff -r 59adc1f7dfca -r fdc4531aefe0 tools/xenstore/xs.c
--- a/tools/xenstore/xs.c       Tue Aug 15 16:25:04 2006 +0100
+++ b/tools/xenstore/xs.c       Tue Aug 15 16:25:39 2006 +0100
@@ -101,23 +101,31 @@ static int get_socket(const char *connec
 static int get_socket(const char *connect_to)
 {
        struct sockaddr_un addr;
-       int sock, saved_errno;
+       int sock, saved_errno, flags;
 
        sock = socket(PF_UNIX, SOCK_STREAM, 0);
        if (sock < 0)
                return -1;
 
+       if ((flags = fcntl(sock, F_GETFD)) < 0)
+               goto error;
+       flags |= FD_CLOEXEC;
+       if (fcntl(sock, F_SETFD, flags) < 0)
+               goto error;
+
        addr.sun_family = AF_UNIX;
        strcpy(addr.sun_path, connect_to);
 
-       if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
-               saved_errno = errno;
-               close(sock);
-               errno = saved_errno;
-               return -1;
-       }
+       if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
+               goto error;
 
        return sock;
+
+error:
+       saved_errno = errno;
+       close(sock);
+       errno = saved_errno;
+       return -1;
 }
 
 static int get_dev(const char *connect_to)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.