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_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);
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user