ia64/xen-unstable

changeset 11147:59adc1f7dfca

[LIBXC] Set close-on-exec on the privcmd fd in libxc.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author kfraser@localhost.localdomain
date Tue Aug 15 16:25:04 2006 +0100 (2006-08-15)
parents f43729552603
children fdc4531aefe0
files tools/libxc/xc_linux.c
line diff
     1.1 --- a/tools/libxc/xc_linux.c	Tue Aug 15 16:21:12 2006 +0100
     1.2 +++ b/tools/libxc/xc_linux.c	Tue Aug 15 16:25:04 2006 +0100
     1.3 @@ -13,13 +13,43 @@
     1.4  
     1.5  #include <xen/memory.h>
     1.6  #include <xen/sys/evtchn.h>
     1.7 +#include <unistd.h>
     1.8 +#include <fcntl.h>
     1.9  
    1.10  int xc_interface_open(void)
    1.11  {
    1.12 +    int flags, saved_errno;
    1.13      int fd = open("/proc/xen/privcmd", O_RDWR);
    1.14 +
    1.15      if ( fd == -1 )
    1.16 +    {
    1.17          PERROR("Could not obtain handle on privileged command interface");
    1.18 +        return -1;
    1.19 +    }
    1.20 +
    1.21 +    /* Although we return the file handle as the 'xc handle' the API
    1.22 +       does not specify / guarentee that this integer is in fact
    1.23 +       a file handle. Thus we must take responsiblity to ensure
    1.24 +       it doesn't propagate (ie leak) outside the process */
    1.25 +    if ( (flags = fcntl(fd, F_GETFD)) < 0 )
    1.26 +    {
    1.27 +        PERROR("Could not get file handle flags");
    1.28 +        goto error;
    1.29 +    }
    1.30 +    flags |= FD_CLOEXEC;
    1.31 +    if ( fcntl(fd, F_SETFD, flags) < 0 )
    1.32 +    {
    1.33 +        PERROR("Could not set file handle flags");
    1.34 +        goto error;
    1.35 +    }
    1.36 +
    1.37      return fd;
    1.38 +
    1.39 + error:
    1.40 +    saved_errno = errno;
    1.41 +    close(fd);
    1.42 +    errno = saved_errno;
    1.43 +    return -1;
    1.44  }
    1.45  
    1.46  int xc_interface_close(int xc_handle)