ia64/xen-unstable

changeset 2218:bcf4ddddff97

bitkeeper revision 1.1159.17.24 (411bf61edgcR_nOyvkAutrxUxR2tRg)

Add close-on-exec to open fd's on /dev/mem and /dev/xen/evtchn in xend.
author kaf24@scramble.cl.cam.ac.uk
date Thu Aug 12 22:58:38 2004 +0000 (2004-08-12)
parents 249ef8d5db7d
children c48fd545583a
files tools/python/xen/lowlevel/xu/xu.c
line diff
     1.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Thu Aug 12 18:05:11 2004 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Thu Aug 12 22:58:38 2004 +0000
     1.3 @@ -57,6 +57,19 @@
     1.4  #endif
     1.5  
     1.6  
     1.7 +/* Set the close-on-exec flag on a file descriptor.  Doesn't currently bother
     1.8 + * to check for errors. */
     1.9 +static void set_cloexec(int fd)
    1.10 +{
    1.11 +    int flags = fcntl(fd, F_GETFD, 0);
    1.12 +
    1.13 +    if ( flags < 0 )
    1.14 +	return;
    1.15 +
    1.16 +    flags |= FD_CLOEXEC;
    1.17 +    fcntl(fd, F_SETFD, flags);
    1.18 +}
    1.19 +
    1.20  /*
    1.21   * *********************** NOTIFIER ***********************
    1.22   */
    1.23 @@ -197,6 +210,7 @@ static PyObject *xu_notifier_new(PyObjec
    1.24          PyObject_Del((PyObject *)xun);
    1.25          return PyErr_SetFromErrno(PyExc_IOError);
    1.26      }
    1.27 +    set_cloexec(xun->evtchn_fd);
    1.28  
    1.29      return (PyObject *)xun;
    1.30  }
    1.31 @@ -896,6 +910,7 @@ static int __xu_port_connect(xu_port_obj
    1.32          PyErr_SetString(port_error, "Could not open '/dev/mem'");
    1.33          return -1;
    1.34      }
    1.35 +    set_cloexec(xup->mem_fd);
    1.36  
    1.37      /* Set the General-Purpose Subject whose page frame will be mapped. */
    1.38      (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)xup->remote_dom);