direct-io.hg

changeset 11127:fdc4531aefe0

Set the close-on-exec flag on the xenstore fd in libxenstore.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author kfraser@localhost.localdomain
date Tue Aug 15 16:25:39 2006 +0100 (2006-08-15)
parents 59adc1f7dfca
children 5db6984e4503
files tools/xenstore/xs.c
line diff
     1.1 --- a/tools/xenstore/xs.c	Tue Aug 15 16:25:04 2006 +0100
     1.2 +++ b/tools/xenstore/xs.c	Tue Aug 15 16:25:39 2006 +0100
     1.3 @@ -101,23 +101,31 @@ int xs_fileno(struct xs_handle *h)
     1.4  static int get_socket(const char *connect_to)
     1.5  {
     1.6  	struct sockaddr_un addr;
     1.7 -	int sock, saved_errno;
     1.8 +	int sock, saved_errno, flags;
     1.9  
    1.10  	sock = socket(PF_UNIX, SOCK_STREAM, 0);
    1.11  	if (sock < 0)
    1.12  		return -1;
    1.13  
    1.14 +	if ((flags = fcntl(sock, F_GETFD)) < 0)
    1.15 +		goto error;
    1.16 +	flags |= FD_CLOEXEC;
    1.17 +	if (fcntl(sock, F_SETFD, flags) < 0)
    1.18 +		goto error;
    1.19 +
    1.20  	addr.sun_family = AF_UNIX;
    1.21  	strcpy(addr.sun_path, connect_to);
    1.22  
    1.23 -	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
    1.24 -		saved_errno = errno;
    1.25 -		close(sock);
    1.26 -		errno = saved_errno;
    1.27 -		return -1;
    1.28 -	}
    1.29 +	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
    1.30 +		goto error;
    1.31  
    1.32  	return sock;
    1.33 +
    1.34 +error:
    1.35 +	saved_errno = errno;
    1.36 +	close(sock);
    1.37 +	errno = saved_errno;
    1.38 +	return -1;
    1.39  }
    1.40  
    1.41  static int get_dev(const char *connect_to)