Skip to content

Commit 1117f72

Browse files
committed
vfs: show O_CLOEXE bit properly in /proc/<pid>/fdinfo/<fd> files
The CLOEXE bit is magical, and for performance (and semantic) reasons we don't actually maintain it in the file descriptor itself, but in a separate bit array. Which means that when we show f_flags, the CLOEXE status is shown incorrectly: we show the status not as it is now, but as it was when the file was opened. Fix that by looking up the bit properly in the 'fdt->close_on_exec' bit array. Uli needs this in order to re-implement the pfiles program: "For normal file descriptors (not sockets) this was the last piece of information which wasn't available. This is all part of my 'give Solaris users no reason to not switch' effort. I intend to offer the code to the util-linux-ng maintainers." Requested-by: Ulrich Drepper <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c214270 commit 1117f72

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/proc/base.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,14 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
19191919
spin_lock(&files->file_lock);
19201920
file = fcheck_files(files, fd);
19211921
if (file) {
1922+
unsigned int f_flags;
1923+
struct fdtable *fdt;
1924+
1925+
fdt = files_fdtable(files);
1926+
f_flags = file->f_flags & ~O_CLOEXEC;
1927+
if (FD_ISSET(fd, fdt->close_on_exec))
1928+
f_flags |= O_CLOEXEC;
1929+
19221930
if (path) {
19231931
*path = file->f_path;
19241932
path_get(&file->f_path);
@@ -1928,7 +1936,7 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
19281936
"pos:\t%lli\n"
19291937
"flags:\t0%o\n",
19301938
(long long) file->f_pos,
1931-
file->f_flags);
1939+
f_flags);
19321940
spin_unlock(&files->file_lock);
19331941
put_files_struct(files);
19341942
return 0;

0 commit comments

Comments
 (0)