All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eugene Teo <eugeneteo@kernel.sg>
To: Miklos Szeredi <mszeredi@suse.cz>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] proc: extend /proc/<pid>/fdinfo/<fd>
Date: Mon, 11 Feb 2008 22:23:57 +0800	[thread overview]
Message-ID: <20080211142357.GA3695@kernel.sg> (raw)
In-Reply-To: <1202720907.4739.36.camel@tucsk.pomaz.szeredi.hu>

Hi Miklos,

<quote sender="Miklos Szeredi">
> On Sat, 2008-02-09 at 20:01 +0800, Eugene Teo wrote:
> > This patch extends /proc/<pid>/fdinfo/<fd> to report information about open
> > files, and pathname. This information can be useful to know when debugging an
> > application.
> > 
> > For each file descriptor, the information is provided in the following format:
> > 
> > kerndev: ~/code/kernel# cat /proc/`pgrep pickup`/fdinfo/6
> > mode:   0622
> > dev:    253,0
> > ino:    21463057
> 
> These are already available via 'stat /proc/<pid>/fd/<fd>'
> 
> > uid:    89
> > gid:    89
> 
> AFAICS file->f_[ug]id are only used by the netfilter code, but I guess
> it wouldn't hurt to show them here.  But please add fields at the end of
> the file, instead of the beggining.

Ok, will do.

> > rdev:   0,0
> 
> This is in struct stat too.
> 
> > pos:    0
> > flags:  04002 FD_CLOEXEC # if close-on-exec flag is set
> 
> FD_CLOEXEC should be on a separate line, because it's not an O_FOO flag.
> > path:   /var/spool/postfix/public/pickup
> 
> readlink /proc/<pid>/fd/<fd>

Thanks for the review. I agree that some of the information can be omitted
since it can be accessed using stat and readlink. I still think it is useful
to have ino in the output though.

Here's the updated patch:

[PATCH] proc: extend /proc/<pid>/fdinfo/<fd>

This patch extends /proc/<pid>/fdinfo/<fd> to report information about open
files, and pathname. This information can be useful to know when debugging an
application.

For each file descriptor, the information is provided in the following format:

kerndev: ~/code/kernel$ cat /proc/`pgrep firefox-bin`/fdinfo/29
pos:    49152
flags:  02
uid:    500
gid:    500
ino:    13205793
fd_flags:       FD_CLOEXEC # if close-on-exec flag is set

Signed-off-by: Eugene Teo <eugeneteo@kernel.sg>
---
 fs/proc/base.c |   22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index c59852b..5ea5dee 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1402,7 +1402,7 @@ out:
 	return ~0U;
 }
 
-#define PROC_FDINFO_MAX 64
+#define PROC_FDINFO_MAX 128
 
 static int proc_fd_info(struct inode *inode, struct dentry **dentry,
 			struct vfsmount **mnt, char *info)
@@ -1428,12 +1428,26 @@ static int proc_fd_info(struct inode *inode, struct dentry **dentry,
 				*mnt = mntget(file->f_path.mnt);
 			if (dentry)
 				*dentry = dget(file->f_path.dentry);
-			if (info)
+			/* called by proc_fdinfo_read() */
+			if (info) {
+				struct fdtable *fdt = files_fdtable(files);
+				struct dentry *d = dget(file->f_path.dentry);
+				int gcoe = FD_ISSET(fd, fdt->close_on_exec);
+
 				snprintf(info, PROC_FDINFO_MAX,
 					 "pos:\t%lli\n"
-					 "flags:\t0%o\n",
+					 "flags:\t0%o\n"
+					 "uid:\t%d\n"
+					 "gid:\t%d\n"
+					 "ino:\t%ld\n"
+					 "fd_flags:\t%s\n",
 					 (long long) file->f_pos,
-					 file->f_flags);
+					 file->f_flags,
+					 file->f_uid, file->f_gid,
+					 d->d_inode->i_ino,
+					 gcoe ? "FD_CLOEXEC" : "0");
+				dput(d);
+			}
 			spin_unlock(&files->file_lock);
 			put_files_struct(files);
 			return 0;


  reply	other threads:[~2008-02-11 14:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-09 12:01 [PATCH] proc: extend /proc/<pid>/fdinfo/<fd> Eugene Teo
2008-02-11  9:08 ` Miklos Szeredi
2008-02-11 14:23   ` Eugene Teo [this message]
2008-02-11 10:20 ` KOSAKI Motohiro
2008-02-11 14:31   ` Eugene Teo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080211142357.GA3695@kernel.sg \
    --to=eugeneteo@kernel.sg \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mszeredi@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.