#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);
/*
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);
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];
}
rfp = fp;
+ flags &= ~COPYFD_CLOEXEC;
/* FALLTHROUGH */
case COPYFD_TO:
/* 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