mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-30 12:04:07 +00:00
Implement F_DUPFD_CLOEXEC command for fcntl(2), specified by SUSv4.
PR: standards/169962 Submitted by: Jukka A. Ukkonen <jau iki fi> MFC after: 1 week
This commit is contained in:
parent
eb35bc035c
commit
49d02b13bc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=238614
@ -113,6 +113,7 @@ static uma_zone_t file_zone;
|
||||
/* Flags for do_dup() */
|
||||
#define DUP_FIXED 0x1 /* Force fixed allocation */
|
||||
#define DUP_FCNTL 0x2 /* fcntl()-style errors */
|
||||
#define DUP_CLOEXEC 0x4 /* Atomically set FD_CLOEXEC. */
|
||||
|
||||
static int closefp(struct filedesc *fdp, int fd, struct file *fp,
|
||||
struct thread *td, int holdleaders);
|
||||
@ -479,6 +480,12 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
|
||||
error = do_dup(td, DUP_FCNTL, fd, tmp, td->td_retval);
|
||||
break;
|
||||
|
||||
case F_DUPFD_CLOEXEC:
|
||||
tmp = arg;
|
||||
error = do_dup(td, DUP_FCNTL | DUP_CLOEXEC, fd, tmp,
|
||||
td->td_retval);
|
||||
break;
|
||||
|
||||
case F_DUP2FD:
|
||||
tmp = arg;
|
||||
error = do_dup(td, DUP_FIXED, fd, tmp, td->td_retval);
|
||||
@ -895,6 +902,10 @@ do_dup(struct thread *td, int flags, int old, int new,
|
||||
* Duplicate the source descriptor.
|
||||
*/
|
||||
fdp->fd_ofiles[new] = fp;
|
||||
if ((flags & DUP_CLOEXEC) != 0)
|
||||
fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] | UF_EXCLOSE;
|
||||
else
|
||||
fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] & ~UF_EXCLOSE;
|
||||
fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] &~ UF_EXCLOSE;
|
||||
if (new > fdp->fd_lastfile)
|
||||
fdp->fd_lastfile = new;
|
||||
|
@ -225,6 +225,9 @@ typedef __pid_t pid_t;
|
||||
#define F_SETLK_REMOTE 14 /* debugging support for remote locks */
|
||||
#define F_READAHEAD 15 /* read ahead */
|
||||
#define F_RDAHEAD 16 /* Darwin compatible read ahead */
|
||||
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
|
||||
#define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */
|
||||
#endif
|
||||
|
||||
/* file descriptor flags (F_GETFD, F_SETFD) */
|
||||
#define FD_CLOEXEC 1 /* close-on-exec flag */
|
||||
|
Loading…
Reference in New Issue
Block a user