From owner-svn-src-head@FreeBSD.ORG Sun Mar 7 10:43:45 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DD9A1106566C; Sun, 7 Mar 2010 10:43:45 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CD18F8FC12; Sun, 7 Mar 2010 10:43:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o27AhjZp023637; Sun, 7 Mar 2010 10:43:45 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o27Ahjtn023635; Sun, 7 Mar 2010 10:43:45 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201003071043.o27Ahjtn023635@svn.freebsd.org> From: Ed Schouten Date: Sun, 7 Mar 2010 10:43:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r204825 - head/sys/compat/linprocfs X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2010 10:43:46 -0000 Author: ed Date: Sun Mar 7 10:43:45 2010 New Revision: 204825 URL: http://svn.freebsd.org/changeset/base/204825 Log: Make /proc/self/fd `work'. On Linux, /proc//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//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@ Modified: head/sys/compat/linprocfs/linprocfs.c Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Sun Mar 7 10:08:00 2010 (r204824) +++ head/sys/compat/linprocfs/linprocfs.c Sun Mar 7 10:43:45 2010 (r204825) @@ -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);