From: David van Moolenbroek Date: Wed, 20 Jul 2016 13:03:03 +0000 (+0000) Subject: VFS: support close-on-exec flag for copyfd(2) X-Git-Url: http://zhaoyanbai.com/repos/rndc.html?a=commitdiff_plain;h=45443f35b5fbb37ddb8b53f6a25e7f19a75f49ea;p=minix.git VFS: support close-on-exec flag for copyfd(2) The flag is supported only when copying out file descriptors (i.e. COPYFD_TO). It will be used by UDS to support MSG_CMSG_CLOEXEC. Change-Id: I46bfd04b5f28e22ec48938e43e42f78d3931220d --- diff --git a/minix/include/minix/syslib.h b/minix/include/minix/syslib.h index b5f573863..1d0611f70 100644 --- a/minix/include/minix/syslib.h +++ b/minix/include/minix/syslib.h @@ -274,6 +274,8 @@ int copyfd(endpoint_t endpt, int fd, int what); #define COPYFD_FROM 0 /* copy file descriptor from remote process */ #define COPYFD_TO 1 /* copy file descriptor to remote process */ #define COPYFD_CLOSE 2 /* close file descriptor in remote process */ +#define COPYFD_CLOEXEC 0x8000 /* with COPYFD_TO: set close-on-exec flag */ +#define COPYFD_FLAGS 0xF000 /* flags mask */ int closenb(int fd); /* diff --git a/minix/servers/vfs/filedes.c b/minix/servers/vfs/filedes.c index ea7ee4a4e..7ddb51b42 100644 --- a/minix/servers/vfs/filedes.c +++ b/minix/servers/vfs/filedes.c @@ -532,7 +532,7 @@ int do_copyfd(void) struct vnode *vp; struct smap *sp; endpoint_t endpt; - int r, fd, what, slot; + int r, fd, what, flags, slot; /* This should be replaced with an ACL check. */ if (!super_user) return(EPERM); @@ -541,6 +541,9 @@ int do_copyfd(void) fd = job_m_in.m_lsys_vfs_copyfd.fd; what = job_m_in.m_lsys_vfs_copyfd.what; + flags = what & COPYFD_FLAGS; + what &= ~COPYFD_FLAGS; + if (isokendpt(endpt, &slot) != OK) return(EINVAL); rfp = &fproc[slot]; @@ -608,6 +611,7 @@ int do_copyfd(void) } rfp = fp; + flags &= ~COPYFD_CLOEXEC; /* FALLTHROUGH */ case COPYFD_TO: @@ -619,6 +623,8 @@ int do_copyfd(void) /* If found, fill the slot and return the slot number. */ if (fd < OPEN_MAX) { rfp->fp_filp[fd] = rfilp; + if (flags & COPYFD_CLOEXEC) + FD_SET(fd, &rfp->fp_cloexec_set); rfilp->filp_count++; r = fd; } else