PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation
This commit is contained in:
parent
aa897b228c
commit
8aa2fc5ab8
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: README,v 1.4 1994/06/29 06:34:43 cgd Exp $ */
|
||||
/* $NetBSD: README,v 1.5 1999/03/12 18:45:40 christos Exp $ */
|
||||
|
||||
saute procfs lyonnais
|
||||
|
||||
@ -47,6 +47,8 @@ are:
|
||||
will get the "right" register values.
|
||||
a multi-proc kernel would need to do some
|
||||
synchronisation.
|
||||
cmdline - r/o. process command line parameters, separated
|
||||
by NULLs
|
||||
|
||||
this then looks like:
|
||||
|
||||
@ -76,13 +78,17 @@ total 0
|
||||
3273 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 curproc
|
||||
% ls -li /proc/curproc
|
||||
total 408
|
||||
3341 --w------- 1 jsp staff 0 Sep 21 15:06 ctl
|
||||
1554 -r-xr-xr-x 1 bin bin 90112 Mar 29 04:52 file
|
||||
3339 -rw------- 1 jsp staff 118784 Sep 21 15:06 mem
|
||||
3343 --w------- 1 jsp staff 0 Sep 21 15:06 note
|
||||
3344 --w------- 1 jsp staff 0 Sep 21 15:06 notepg
|
||||
3340 -rw------- 1 jsp staff 0 Sep 21 15:06 regs
|
||||
3342 -r--r--r-- 1 jsp staff 0 Sep 21 15:06 status
|
||||
total 460
|
||||
7692 -r--r--r-- 1 dolecek staff 0 Mar 12 12:02 cmdline
|
||||
7687 --w------- 1 dolecek staff 0 Mar 12 12:02 ctl
|
||||
2003 -r-xr-xr-x 1 root wheel 180224 Jan 31 23:32 file*
|
||||
7686 -rw------- 1 dolecek staff 108 Mar 12 12:02 fpregs
|
||||
7691 -r--r--r-- 1 dolecek staff 0 Mar 12 12:02 map
|
||||
7684 -rw------- 1 dolecek staff 282624 Mar 12 12:02 mem
|
||||
7689 --w------- 1 dolecek staff 0 Mar 12 12:02 note
|
||||
7690 --w------- 1 dolecek staff 0 Mar 12 12:02 notepg
|
||||
7685 -rw------- 1 dolecek staff 64 Mar 12 12:02 regs
|
||||
7688 -r--r--r-- 1 dolecek staff 0 Mar 12 12:02 status
|
||||
% df /proc/curproc /proc/curproc/file
|
||||
Filesystem 512-blocks Used Avail Capacity Mounted on
|
||||
proc 2 2 0 100% /proc
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: procfs.h,v 1.23 1999/01/25 02:20:08 msaitoh Exp $ */
|
||||
/* $NetBSD: procfs.h,v 1.24 1999/03/12 18:45:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Jan-Simon Pendry
|
||||
@ -54,7 +54,8 @@ typedef enum {
|
||||
Pstatus, /* process status */
|
||||
Pnote, /* process notifier */
|
||||
Pnotepg, /* process group notifier */
|
||||
Pmap /* memory map */
|
||||
Pmap, /* memory map */
|
||||
Pcmdline /* process command line args */
|
||||
} pfstype;
|
||||
|
||||
/*
|
||||
@ -107,15 +108,24 @@ vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
|
||||
int procfs_freevp __P((struct vnode *));
|
||||
int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
|
||||
struct vnode *procfs_findtextvp __P((struct proc *));
|
||||
int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
|
||||
int procfs_checkioperm __P((struct proc *p, struct proc *t));
|
||||
int procfs_checkioperm __P((struct proc *, struct proc *));
|
||||
|
||||
/* functions to check whether or not files should be displayed */
|
||||
int procfs_validfile __P((struct proc *));
|
||||
|
86
sys/miscfs/procfs/procfs_cmdline.c
Normal file
86
sys/miscfs/procfs/procfs_cmdline.c
Normal file
@ -0,0 +1,86 @@
|
||||
/* $NetBSD: procfs_cmdline.c,v 1.1 1999/03/12 18:45:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Jaromir Dolecek <dolecek@ics.muni.cz>
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jaromir Dolecek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/syslimits.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/exec.h>
|
||||
#include <miscfs/procfs/procfs.h>
|
||||
|
||||
/*
|
||||
* code for returning process's command line arguments
|
||||
*/
|
||||
int
|
||||
procfs_docmdline(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
struct ps_strings pss;
|
||||
char arg[ARG_MAX], *argv;
|
||||
int xlen, len, count, i;
|
||||
|
||||
/* don't write; can't work for zombies -- they don't have any stack */
|
||||
if (uio->uio_rw != UIO_READ || p->p_stat == SZOMB)
|
||||
return EOPNOTSUPP;
|
||||
|
||||
if (copyin(PS_STRINGS, &pss, sizeof(struct ps_strings)))
|
||||
return EFAULT;
|
||||
if (copyin(pss.ps_argvstr, &argv, sizeof(argv)))
|
||||
return EFAULT;
|
||||
len = 0;
|
||||
count = pss.ps_nargvstr;
|
||||
/* don't know how long the argument string is, so let's find out */
|
||||
while(count && len < ARG_MAX && copyin(argv+len, &arg[len], 1) == 0) {
|
||||
if (len > 0 && arg[len] == '\0') count--;
|
||||
len++;
|
||||
}
|
||||
if (len > 0) len--; /* exclude last NULL */
|
||||
|
||||
xlen = len - uio->uio_offset;
|
||||
xlen = imin(xlen, uio->uio_resid);
|
||||
if (xlen <= 0)
|
||||
return 0;
|
||||
else
|
||||
return (uiomove(arg + uio->uio_offset, xlen, uio));
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: procfs_subr.c,v 1.25 1999/01/25 02:20:08 msaitoh Exp $ */
|
||||
/* $NetBSD: procfs_subr.c,v 1.26 1999/03/12 18:45:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Christopher G. Demetriou. All rights reserved.
|
||||
@ -166,6 +166,7 @@ loop:
|
||||
|
||||
case Pmap: /* /proc/N/map = -r--r--r-- */
|
||||
case Pstatus: /* /proc/N/status = -r--r--r-- */
|
||||
case Pcmdline: /* /proc/N/cmdline = -r--r--r-- */
|
||||
pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
|
||||
vp->v_type = VREG;
|
||||
break;
|
||||
@ -264,6 +265,9 @@ procfs_rw(v)
|
||||
case Pmem:
|
||||
return (procfs_domem(curp, p, pfs, uio));
|
||||
|
||||
case Pcmdline:
|
||||
return (procfs_docmdline(curp, p, pfs, uio));
|
||||
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: procfs_vnops.c,v 1.60 1999/01/25 02:20:08 msaitoh Exp $ */
|
||||
/* $NetBSD: procfs_vnops.c,v 1.61 1999/03/12 18:45:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Jan-Simon Pendry
|
||||
@ -94,6 +94,7 @@ struct proc_target {
|
||||
{ DT_REG, N("note"), Pnote, NULL },
|
||||
{ DT_REG, N("notepg"), Pnotepg, NULL },
|
||||
{ DT_REG, N("map"), Pmap, procfs_validmap },
|
||||
{ DT_REG, N("cmdline"), Pcmdline, NULL },
|
||||
#undef N
|
||||
};
|
||||
static int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
|
||||
@ -532,6 +533,7 @@ procfs_getattr(v)
|
||||
case Pnote:
|
||||
case Pnotepg:
|
||||
case Pmap:
|
||||
case Pcmdline:
|
||||
vap->va_nlink = 1;
|
||||
vap->va_uid = procp->p_ucred->cr_uid;
|
||||
vap->va_gid = procp->p_ucred->cr_gid;
|
||||
@ -607,6 +609,7 @@ procfs_getattr(v)
|
||||
case Pnote:
|
||||
case Pnotepg:
|
||||
case Pmap:
|
||||
case Pcmdline:
|
||||
vap->va_bytes = vap->va_size = 0;
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user