0001-Add-O_CLOEXEC-flag-to-open-2-and-fhopen-2.patch
| b/lib/libc/sys/open.2 | ||
|---|---|---|
| 30 | 30 |
.\" SUCH DAMAGE. |
| 31 | 31 |
.\" |
| 32 | 32 |
.\" @(#)open.2 8.2 (Berkeley) 11/16/93 |
| 33 |
.\" $FreeBSD: src/lib/libc/sys/open.2,v 1.11.2.9 2001/12/14 18:34:01 ru Exp $ |
|
| 34 |
.\" $DragonFly: src/lib/libc/sys/open.2,v 1.3 2005/07/29 23:16:04 hsu Exp $ |
|
| 33 |
.\" $FreeBSD: src/lib/libc/sys/open.2,v 1.43 2011/03/25 14:01:18 kib Exp $ |
|
| 35 | 34 |
.\" |
| 36 |
.Dd July 24, 2009
|
|
| 35 |
.Dd March 25, 2011
|
|
| 37 | 36 |
.Dt OPEN 2 |
| 38 | 37 |
.Os |
| 39 | 38 |
.Sh NAME |
| ... | ... | |
| 119 | 118 |
O_DIRECT eliminate or reduce cache effects |
| 120 | 119 |
O_FSYNC synchronous writes |
| 121 | 120 |
O_NOFOLLOW do not follow symlinks |
| 121 |
O_CLOEXEC set FD_CLOEXEC upon open |
|
| 122 | 122 |
.Ed |
| 123 | 123 |
.Pp |
| 124 | 124 |
Opening a file with |
| ... | ... | |
| 193 | 193 |
it will minimize the impact the data has on the cache. |
| 194 | 194 |
Use of this flag can drastically reduce performance if not used with care. |
| 195 | 195 |
.Pp |
| 196 |
.Dv O_CLOEXEC |
|
| 197 |
may be used to set |
|
| 198 |
.Dv FD_CLOEXEC |
|
| 199 |
flag for the newly returned file descriptor. |
|
| 200 |
.Pp |
|
| 196 | 201 |
If successful, |
| 197 | 202 |
.Fn open |
| 198 | 203 |
and |
| ... | ... | |
| 205 | 210 |
When a new file is created it is given the group of the directory |
| 206 | 211 |
which contains it. |
| 207 | 212 |
.Pp |
| 208 |
The new descriptor is set to remain open across |
|
| 213 |
Unless |
|
| 214 |
.Dv |
|
| 215 |
O_CLOEXEC |
|
| 216 |
flag was specified, |
|
| 217 |
the new descriptor is set to remain open across |
|
| 209 | 218 |
.Xr execve 2 |
| 210 | 219 |
system calls; see |
| 211 |
.Xr close 2 |
|
| 220 |
.Xr close 2 , |
|
| 221 |
.Xr fcntl 2 |
|
| 212 | 222 |
and |
| 213 |
.Xr fcntl 2 . |
|
| 223 |
.Dv O_CLOEXEC |
|
| 224 |
description. |
|
| 214 | 225 |
.Pp |
| 215 | 226 |
The system imposes a limit on the number of file descriptors |
| 216 | 227 |
open simultaneously by one process. |
| b/sys/kern/kern_descrip.c | ||
|---|---|---|
| 1498 | 1498 |
* MPSAFE |
| 1499 | 1499 |
*/ |
| 1500 | 1500 |
int |
| 1501 |
falloc(struct lwp *lp, struct file **resultfp, int *resultfd)
|
|
| 1501 |
fallocf(struct lwp *lp, struct file **resultfp, int *resultfd, int flags)
|
|
| 1502 | 1502 |
{
|
| 1503 | 1503 |
static struct timeval lastfail; |
| 1504 | 1504 |
static int curfail; |
| ... | ... | |
| 1532 | 1532 |
fp->f_ops = &badfileops; |
| 1533 | 1533 |
fp->f_seqcount = 1; |
| 1534 | 1534 |
fsetcred(fp, cred); |
| 1535 |
if ((flags & O_CLOEXEC) != 0) |
|
| 1536 |
fp->f_flag |= UF_EXCLOSE; |
|
| 1535 | 1537 |
spin_lock(&filehead_spin); |
| 1536 | 1538 |
nfiles++; |
| 1537 | 1539 |
LIST_INSERT_HEAD(&filehead, fp, f_list); |
| ... | ... | |
| 1549 | 1551 |
return (error); |
| 1550 | 1552 |
} |
| 1551 | 1553 | |
| 1554 |
int |
|
| 1555 |
falloc(struct lwp *lp, struct file **resultfp, int *resultfd) |
|
| 1556 |
{
|
|
| 1557 |
return fallocf(lp, resultfp, resultfd, 0); |
|
| 1558 |
} |
|
| 1559 | ||
| 1552 | 1560 |
/* |
| 1553 | 1561 |
* Check for races against a file descriptor by determining that the |
| 1554 | 1562 |
* file pointer is still associated with the specified file descriptor, |
| b/sys/kern/vfs_syscalls.c | ||
|---|---|---|
| 1817 | 1817 |
if ((oflags & O_ACCMODE) == O_ACCMODE) |
| 1818 | 1818 |
return (EINVAL); |
| 1819 | 1819 |
flags = FFLAGS(oflags); |
| 1820 |
error = falloc(lp, &nfp, NULL);
|
|
| 1820 |
error = fallocf(lp, &nfp, NULL, flags);
|
|
| 1821 | 1821 |
if (error) |
| 1822 | 1822 |
return (error); |
| 1823 | 1823 |
fp = nfp; |
| ... | ... | |
| 4218 | 4218 |
* WARNING! no f_nchandle will be associated when fhopen()ing a |
| 4219 | 4219 |
* directory. XXX |
| 4220 | 4220 |
*/ |
| 4221 |
if ((error = falloc(td->td_lwp, &nfp, &indx)) != 0)
|
|
| 4221 |
if ((error = fallocf(td->td_lwp, &nfp, &indx, fmode)) != 0)
|
|
| 4222 | 4222 |
goto bad; |
| 4223 | 4223 |
fp = nfp; |
| 4224 | 4224 | |
| b/sys/sys/fcntl.h | ||
|---|---|---|
| 93 | 93 | |
| 94 | 94 |
/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */ |
| 95 | 95 |
#define O_NOCTTY 0x8000 /* don't assign controlling terminal */ |
| 96 |
#define O_CLOEXEC 0x10000 /* atomically set FD_CLOEXEC */ |
|
| 96 | 97 | |
| 97 | 98 |
/* Attempt to bypass the buffer cache */ |
| 98 | 99 |
#define O_DIRECT 0x00010000 |
| b/sys/sys/filedesc.h | ||
|---|---|---|
| 155 | 155 |
int dupfdopen (struct filedesc *, int, int, int, int); |
| 156 | 156 |
int fdalloc (struct proc *p, int want, int *result); |
| 157 | 157 |
int fdavail (struct proc *p, int n); |
| 158 |
int fallocf(struct lwp *lp, struct file **resultfp, int *resultfd, int flags); |
|
| 158 | 159 |
int falloc (struct lwp *lp, struct file **resultfp, int *resultfd); |
| 159 | 160 |
void fsetfd (struct filedesc *fdp, struct file *fp, int fd); |
| 160 | 161 |
int fgetfdflags(struct filedesc *fdp, int fd, int *flagsp); |
| 161 |
- |
|