8000 Make close_range() support CLOSE_RANGE_CLOEXEC · freebsd/freebsd-src@267133c · GitHub
[go: up one dir, main page]

Skip to content

Commit 267133c

Browse files
Make close_range() support CLOSE_RANGE_CLOEXEC
1 parent 3c82ddc commit 267133c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

sys/kern/kern_descrip.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ kern_close(struct thread *td, int fd)
14221422
}
14231423

14241424
static int
1425-
close_range_cloexec(struct thread *td, u_int lowfd, u_int highfd)
1425+
close_range_flags(struct thread *td, u_int lowfd, u_int highfd, int flags)
14261426
{
14271427
struct filedesc *fdp;
14281428
struct fdescenttbl *fdt;
@@ -1439,8 +1439,12 @@ close_range_cloexec(struct thread *td, u_int lowfd, u_int highfd)
14391439
}
14401440
for (; fd <= highfd; fd++) {
14411441
fde = &fdt->fdt_ofiles[fd];
1442-
if (fde->fde_file != NULL)
1443-
fde->fde_flags |= UF_EXCLOSE;
1442+
if (fde->fde_file != NULL) {
1443+
if ((flags & CLOSE_RANGE_CLOEXEC) != 0)
1444+
fde->fde_flags |= UF_EXCLOSE;
1445+
if ((flags & CLOSE_RANGE_CLOFORK) != 0)
1446+
fde->fde_flags |= UF_FOCLOSE;
1447+
}
14441448
}
14451449
out_locked:
14461450
FILEDESC_XUNLOCK(fdp);
@@ -1498,8 +1502,8 @@ kern_close_range(struct thread *td, int flags, u_int lowfd, u_int highfd)
14981502
return (EINVAL);
14991503
}
15001504

1501-
if ((flags & CLOSE_RANGE_CLOEXEC) != 0)
1502-
return (close_range_cloexec(td, lowfd, highfd));
1505+
if ((flags & (CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_CLOFORK)) != 0)
1506+
return (close_range_flags(td, lowfd, highfd, flags));
15031507

15041508
return (close_range_impl(td, lowfd, highfd));
15051509
}
@@ -1519,7 +1523,7 @@ sys_close_range(struct thread *td, struct close_range_args *uap)
15191523
AUDIT_ARG_CMD(uap->highfd);
15201524
AUDIT_ARG_FFLAGS(uap->flags);
15211525

1522-
if ((uap->flags & ~(CLOSE_RANGE_CLOEXEC)) != 0)
1526+
if ((uap->flags & ~(CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_CLOFORK)) != 0)
15231527
return (EINVAL);
15241528
return (kern_close_range(td, uap->flags, uap->lowfd, uap->highfd));
15251529
}

sys/sys/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
* close_range() options.
211211
*/
212212
#define CLOSE_RANGE_CLOEXEC (1<<2)
213+
#define CLOSE_RANGE_CLOFORK (1<<3)
213214

214215
#endif /* __BSD_VISIBLE */
215216

0 commit comments

Comments
 (0)
0