Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <drepper@akkadia.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+9 -1
+9 -1
fs/proc/base.c
··· 1919 1919 spin_lock(&files->file_lock); 1920 1920 file = fcheck_files(files, fd); 1921 1921 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 + 1922 1930 if (path) { 1923 1931 *path = file->f_path; 1924 1932 path_get(&file->f_path); ··· 1936 1928 "pos:\t%lli\n" 1937 1929 "flags:\t0%o\n", 1938 1930 (long long) file->f_pos, 1939 - file->f_flags); 1931 + f_flags); 1940 1932 spin_unlock(&files->file_lock); 1941 1933 put_files_struct(files); 1942 1934 return 0;