Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/miscfs/procfs Make /proc/self a symlink to /proc/curproc...



details:   https://anonhg.NetBSD.org/src/rev/f029940d2ef9
branches:  trunk
changeset: 475996:f029940d2ef9
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Sep 02 23:33:45 1999 +0000

description:
Make /proc/self a symlink to /proc/curproc.  I've observed Linux programs
that expect /proc/self/cmdline to exist.

diffstat:

 sys/miscfs/procfs/procfs.h       |   3 +-
 sys/miscfs/procfs/procfs_subr.c  |   3 +-
 sys/miscfs/procfs/procfs_vnops.c |  44 ++++++++++++++++++++++++++++++----------
 3 files changed, 37 insertions(+), 13 deletions(-)

diffs (136 lines):

diff -r 2a8f16c8fe5c -r f029940d2ef9 sys/miscfs/procfs/procfs.h
--- a/sys/miscfs/procfs/procfs.h        Thu Sep 02 23:25:28 1999 +0000
+++ b/sys/miscfs/procfs/procfs.h        Thu Sep 02 23:33:45 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs.h,v 1.26 1999/03/24 05:51:27 mrg Exp $  */
+/*     $NetBSD: procfs.h,v 1.27 1999/09/02 23:33:45 thorpej Exp $      */
 
 /*
  * Copyright (c) 1993 Jan-Simon Pendry
@@ -45,6 +45,7 @@
 typedef enum {
        Proot,          /* the filesystem root */
        Pcurproc,       /* symbolic link for curproc */
+       Pself,          /* like curproc, but this is the Linux name */
        Pproc,          /* a process-specific sub-directory */
        Pfile,          /* the executable file */
        Pmem,           /* the process's memory image */
diff -r 2a8f16c8fe5c -r f029940d2ef9 sys/miscfs/procfs/procfs_subr.c
--- a/sys/miscfs/procfs/procfs_subr.c   Thu Sep 02 23:25:28 1999 +0000
+++ b/sys/miscfs/procfs/procfs_subr.c   Thu Sep 02 23:33:45 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_subr.c,v 1.27 1999/07/08 01:26:28 wrstuden Exp $        */
+/*     $NetBSD: procfs_subr.c,v 1.28 1999/09/02 23:33:45 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou.  All rights reserved.
@@ -140,6 +140,7 @@
                break;
 
        case Pcurproc:  /* /proc/curproc = lr-xr-xr-x */
+       case Pself:     /* /proc/self    = lr-xr-xr-x */
                pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
                vp->v_type = VLNK;
                break;
diff -r 2a8f16c8fe5c -r f029940d2ef9 sys/miscfs/procfs/procfs_vnops.c
--- a/sys/miscfs/procfs/procfs_vnops.c  Thu Sep 02 23:25:28 1999 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c  Thu Sep 02 23:33:45 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vnops.c,v 1.68 1999/08/25 14:42:36 sommerfeld Exp $     */
+/*     $NetBSD: procfs_vnops.c,v 1.69 1999/09/02 23:33:45 thorpej Exp $        */
 
 /*
  * Copyright (c) 1993 Jan-Simon Pendry
@@ -484,6 +484,7 @@
        switch (pfs->pfs_type) {
        case Proot:
        case Pcurproc:
+       case Pself:
                procp = 0;
                break;
 
@@ -576,6 +577,13 @@
                break;
        }
 
+       case Pself:
+               vap->va_nlink = 1;
+               vap->va_uid = 0;
+               vap->va_gid = 0;
+               vap->va_bytes = vap->va_size = sizeof("curproc");
+               break;
+
        case Pproc:
                vap->va_nlink = 2;
                vap->va_uid = procp->p_ucred->cr_uid;
@@ -706,7 +714,7 @@
        pid_t pid;
        struct pfsnode *pfs;
        struct proc *p;
-       int i, error, wantpunlock;
+       int i, error, wantpunlock, iscurproc = 0, isself = 0;
 
        *vpp = NULL;
        cnp->cn_flags &= ~PDIRUNLOCK;
@@ -730,8 +738,12 @@
                if (cnp->cn_flags & ISDOTDOT) 
                        return (EIO);
 
-               if (CNEQ(cnp, "curproc", 7)) {
-                       error = procfs_allocvp(dvp->v_mount, vpp, 0, Pcurproc);
+               iscurproc = CNEQ(cnp, "curproc", 7);
+               isself = CNEQ(cnp, "self", 4);
+
+               if (iscurproc || isself) {
+                       error = procfs_allocvp(dvp->v_mount, vpp, 0,
+                           iscurproc ? Pcurproc : Pself);
                        if ((error == 0) && (wantpunlock)) {
                                VOP_UNLOCK(dvp, 0);
                                cnp->cn_flags |= PDIRUNLOCK;
@@ -910,8 +922,9 @@
 
        /*
         * this is for the root of the procfs filesystem
-        * what is needed is a special entry for "curproc"
-        * followed by an entry for each process on allproc
+        * what is needed are special entries for "curproc"
+        * and "self" followed by an entry for each process
+        * on allproc
 #ifdef PROCFS_ZOMBIE
         * and deadproc and zombproc.
 #endif
@@ -956,8 +969,15 @@
 
                        case 2:
                                d.d_fileno = PROCFS_FILENO(0, Pcurproc);
-                               d.d_namlen = 7;
-                               memcpy(d.d_name, "curproc", 8);
+                               d.d_namlen = sizeof("curproc") - 1;
+                               memcpy(d.d_name, "curproc", sizeof("curproc"));
+                               d.d_type = DT_LNK;
+                               break;
+
+                       case 3:
+                               d.d_fileno = PROCFS_FILENO(0, Pself);
+                               d.d_namlen = sizeof("self") - 1;
+                               memcpy(d.d_name, "self", sizeof("self"));
                                d.d_type = DT_LNK;
                                break;
 
@@ -1025,11 +1045,13 @@
        char buf[16];           /* should be enough */
        int len;
 
-       if (VTOPFS(ap->a_vp)->pfs_fileno != PROCFS_FILENO(0, Pcurproc))
+       if (VTOPFS(ap->a_vp)->pfs_fileno == PROCFS_FILENO(0, Pcurproc))
+               len = sprintf(buf, "%ld", (long)curproc->p_pid);
+       else if (VTOPFS(ap->a_vp)->pfs_fileno == PROCFS_FILENO(0, Pself))
+               len = sprintf(buf, "%s", "curproc");
+       else
                return (EINVAL);
 
-       len = sprintf(buf, "%ld", (long)curproc->p_pid);
-
        return (uiomove((caddr_t)buf, len, ap->a_uio));
 }
 



Home | Main Index | Thread Index | Old Index