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
This commit is contained in:
parent
c344203e48
commit
45443f35b5
|
|
@ -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_FROM 0 /* copy file descriptor from remote process */
|
||||||
#define COPYFD_TO 1 /* copy file descriptor to remote process */
|
#define COPYFD_TO 1 /* copy file descriptor to remote process */
|
||||||
#define COPYFD_CLOSE 2 /* close file descriptor in 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);
|
int closenb(int fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -532,7 +532,7 @@ int do_copyfd(void)
|
||||||
struct vnode *vp;
|
struct vnode *vp;
|
||||||
struct smap *sp;
|
struct smap *sp;
|
||||||
endpoint_t endpt;
|
endpoint_t endpt;
|
||||||
int r, fd, what, slot;
|
int r, fd, what, flags, slot;
|
||||||
|
|
||||||
/* This should be replaced with an ACL check. */
|
/* This should be replaced with an ACL check. */
|
||||||
if (!super_user) return(EPERM);
|
if (!super_user) return(EPERM);
|
||||||
|
|
@ -541,6 +541,9 @@ int do_copyfd(void)
|
||||||
fd = job_m_in.m_lsys_vfs_copyfd.fd;
|
fd = job_m_in.m_lsys_vfs_copyfd.fd;
|
||||||
what = job_m_in.m_lsys_vfs_copyfd.what;
|
what = job_m_in.m_lsys_vfs_copyfd.what;
|
||||||
|
|
||||||
|
flags = what & COPYFD_FLAGS;
|
||||||
|
what &= ~COPYFD_FLAGS;
|
||||||
|
|
||||||
if (isokendpt(endpt, &slot) != OK) return(EINVAL);
|
if (isokendpt(endpt, &slot) != OK) return(EINVAL);
|
||||||
rfp = &fproc[slot];
|
rfp = &fproc[slot];
|
||||||
|
|
||||||
|
|
@ -608,6 +611,7 @@ int do_copyfd(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
rfp = fp;
|
rfp = fp;
|
||||||
|
flags &= ~COPYFD_CLOEXEC;
|
||||||
|
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case COPYFD_TO:
|
case COPYFD_TO:
|
||||||
|
|
@ -619,6 +623,8 @@ int do_copyfd(void)
|
||||||
/* If found, fill the slot and return the slot number. */
|
/* If found, fill the slot and return the slot number. */
|
||||||
if (fd < OPEN_MAX) {
|
if (fd < OPEN_MAX) {
|
||||||
rfp->fp_filp[fd] = rfilp;
|
rfp->fp_filp[fd] = rfilp;
|
||||||
|
if (flags & COPYFD_CLOEXEC)
|
||||||
|
FD_SET(fd, &rfp->fp_cloexec_set);
|
||||||
rfilp->filp_count++;
|
rfilp->filp_count++;
|
||||||
r = fd;
|
r = fd;
|
||||||
} else
|
} else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user