summaryrefslogtreecommitdiffstats
path: root/sys/compat
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2010-03-07 10:43:45 +0000
committered <ed@FreeBSD.org>2010-03-07 10:43:45 +0000
commit3c620db1c441443ca60d5e94e84d330f214c5ec7 (patch)
tree90abcee148c1dd40d1abe02e6224dcab77b3cd8d /sys/compat
parent6275a64fe8616fb701e918854dcb2db271b4c9b0 (diff)
downloadFreeBSD-src-3c620db1c441443ca60d5e94e84d330f214c5ec7.zip
FreeBSD-src-3c620db1c441443ca60d5e94e84d330f214c5ec7.tar.gz
Make /proc/self/fd `work'.
On Linux, /proc/<pid>/fd is comparable to fdescfs, where it allows you to inspect the file descriptors used by each process. Glibc's ttyname() works by performing a readlink() on these nodes, since all nodes in this directory are symlinks. It is a bit hard to implement this in linprocfs right now, so I am not going to bother. Add a way to make ttyname(3) work, by adding a /proc/<pid>/fd symlink, which points to /dev/fd only if the calling process matches. When fdescfs is mounted, this will cause the readlink() in ttyname() to fail, causing it to fall back on manually finding a matching node in /dev. Discussed on: emulation@
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/linprocfs/linprocfs.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 541db2f..ba08fd2 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -1245,6 +1245,20 @@ linprocfs_domodules(PFS_FILL_ARGS)
#endif
/*
+ * Filler function for proc/pid/fd
+ */
+static int
+linprocfs_dofdescfs(PFS_FILL_ARGS)
+{
+
+ if (p == curproc)
+ sbuf_printf(sb, "/dev/fd");
+ else
+ sbuf_printf(sb, "unknown");
+ return (0);
+}
+
+/*
* Constructor
*/
static int
@@ -1312,6 +1326,8 @@ linprocfs_init(PFS_INIT_ARGS)
NULL, NULL, NULL, PFS_RD);
pfs_create_file(dir, "status", &linprocfs_doprocstatus,
NULL, NULL, NULL, PFS_RD);
+ pfs_create_link(dir, "fd", &linprocfs_dofdescfs,
+ NULL, NULL, NULL, 0);
/* /proc/scsi/... */
dir = pfs_create_dir(root, "scsi", NULL, NULL, NULL, 0);
OpenPOWER on IntegriCloud