Skip to content

Commit b8ea429

Browse files
author
Al Viro
committed
make __set_open_fd() set cloexec state as well
->close_on_exec[] state is maintained only for opened descriptors; as the result, anything that marks a descriptor opened has to set its cloexec state explicitly. As the result, all calls of __set_open_fd() are followed by __set_close_on_exec(); might as well fold it into __set_open_fd() so that cloexec state is defined as soon as the descriptor is marked opened. [braino fix folded] Signed-off-by: Al Viro <[email protected]>
1 parent e880d33 commit b8ea429

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

fs/file.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ static inline void __set_close_on_exec(unsigned int fd, struct fdtable *fdt,
248248
}
249249
}
250250

251-
static inline void __set_open_fd(unsigned int fd, struct fdtable *fdt)
251+
static inline void __set_open_fd(unsigned int fd, struct fdtable *fdt, bool set)
252252
{
253253
__set_bit(fd, fdt->open_fds);
254+
__set_close_on_exec(fd, fdt, set);
254255
fd /= BITS_PER_LONG;
255256
if (!~fdt->open_fds[fd])
256257
__set_bit(fd, fdt->full_fds_bits);
@@ -517,8 +518,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
517518
if (start <= files->next_fd)
518519
files->next_fd = fd + 1;
519520

520-
__set_open_fd(fd, fdt);
521-
__set_close_on_exec(fd, fdt, flags & O_CLOEXEC);
521+
__set_open_fd(fd, fdt, flags & O_CLOEXEC);
522522
error = fd;
523523

524524
out:
@@ -1186,8 +1186,7 @@ __releases(&files->file_lock)
11861186
goto Ebusy;
11871187
get_file(file);
11881188
rcu_assign_pointer(fdt->fd[fd], file);
1189-
__set_open_fd(fd, fdt);
1190-
__set_close_on_exec(fd, fdt, flags & O_CLOEXEC);
1189+
__set_open_fd(fd, fdt, flags & O_CLOEXEC);
11911190
spin_unlock(&files->file_lock);
11921191

11931192
if (tofree)

0 commit comments

Comments
 (0)