mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-29 16:44:03 +00:00
A partial implementation of the procfs cmdline pseudo-file. This
is enough to satisfy things like StarOffice. This is a hack, but doing it properly would be a LOT of work, and would require extensive grovelling around in the user address space to find the argv[]. Obtained from: Mostly from Andrzej Bialecki <abial@nask.pl>.
This commit is contained in:
parent
92e86f9920
commit
75ba77578f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=42301
@ -37,7 +37,7 @@
|
||||
* @(#)procfs.h 8.9 (Berkeley) 5/14/95
|
||||
*
|
||||
* From:
|
||||
* $Id: procfs.h,v 1.19 1998/05/19 00:00:13 tegge Exp $
|
||||
* $Id: procfs.h,v 1.20 1998/07/07 04:08:44 bde Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -56,7 +56,8 @@ typedef enum {
|
||||
Pnote, /* process notifier */
|
||||
Pnotepg, /* process group notifier */
|
||||
Pmap, /* memory map */
|
||||
Ptype /* executable type */
|
||||
Ptype, /* executable type */
|
||||
Pcmdline /* command line */
|
||||
} pfstype;
|
||||
|
||||
/*
|
||||
@ -154,6 +155,7 @@ int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct
|
||||
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_dotype __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
|
||||
/* Return 1 if process has special kernel digging privileges */
|
||||
int procfs_kmemaccess __P((struct proc *));
|
||||
|
@ -37,7 +37,7 @@
|
||||
* @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
|
||||
*
|
||||
* From:
|
||||
* $Id: procfs_status.c,v 1.10 1997/08/02 14:32:17 bde Exp $
|
||||
* $Id: procfs_status.c,v 1.11 1998/07/11 07:45:45 bde Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -147,3 +147,40 @@ procfs_dostatus(curp, p, pfs, uio)
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
procfs_docmdline(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps;
|
||||
int xlen;
|
||||
int error;
|
||||
char psbuf[256];
|
||||
|
||||
if (uio->uio_rw != UIO_READ)
|
||||
return (EOPNOTSUPP);
|
||||
|
||||
/*
|
||||
* For now, this is a hack. To implement this fully would require
|
||||
* groping around in the process address space to follow argv etc.
|
||||
*/
|
||||
ps = psbuf;
|
||||
bcopy(p->p_comm, ps, MAXCOMLEN);
|
||||
ps[MAXCOMLEN] = '\0';
|
||||
ps += strlen(ps);
|
||||
|
||||
ps += sprintf(ps, "\n");
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = min(xlen, uio->uio_resid);
|
||||
if (xlen <= 0)
|
||||
error = 0;
|
||||
else
|
||||
error = uiomove(ps, xlen, uio);
|
||||
return (error);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
*
|
||||
* @(#)procfs_subr.c 8.6 (Berkeley) 5/14/95
|
||||
*
|
||||
* $Id: procfs_subr.c,v 1.20 1997/12/09 05:03:41 sef Exp $
|
||||
* $Id: procfs_subr.c,v 1.21 1997/12/12 03:33:43 sef Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -181,6 +181,7 @@ procfs_allocvp(mp, vpp, pid, pfs_type)
|
||||
case Ptype:
|
||||
case Pmap:
|
||||
case Pstatus:
|
||||
case Pcmdline:
|
||||
pfs->pfs_mode = (VREAD) |
|
||||
(VREAD >> 3) |
|
||||
(VREAD >> 6);
|
||||
@ -282,6 +283,10 @@ procfs_rw(ap)
|
||||
rtval = procfs_dotype(curp, p, pfs, uio);
|
||||
break;
|
||||
|
||||
case Pcmdline:
|
||||
rtval = procfs_docmdline(curp, p, pfs, uio);
|
||||
break;
|
||||
|
||||
default:
|
||||
rtval = EOPNOTSUPP;
|
||||
break;
|
||||
|
@ -36,7 +36,7 @@
|
||||
*
|
||||
* @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95
|
||||
*
|
||||
* $Id: procfs_vnops.c,v 1.61 1998/07/11 07:45:46 bde Exp $
|
||||
* $Id: procfs_vnops.c,v 1.62 1998/12/04 22:54:51 archie Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -101,6 +101,7 @@ static struct proc_target {
|
||||
{ DT_REG, N("notepg"), Pnotepg, NULL },
|
||||
{ DT_REG, N("map"), Pmap, procfs_validmap },
|
||||
{ DT_REG, N("etype"), Ptype, procfs_validtype },
|
||||
{ DT_REG, N("cmdline"), Pcmdline, NULL },
|
||||
#undef N
|
||||
};
|
||||
static const int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
|
||||
@ -573,6 +574,7 @@ procfs_getattr(ap)
|
||||
case Pstatus:
|
||||
case Pnote:
|
||||
case Pnotepg:
|
||||
case Pcmdline:
|
||||
vap->va_nlink = 1;
|
||||
vap->va_uid = procp->p_ucred->cr_uid;
|
||||
vap->va_gid = procp->p_ucred->cr_gid;
|
||||
|
@ -37,7 +37,7 @@
|
||||
* @(#)procfs.h 8.9 (Berkeley) 5/14/95
|
||||
*
|
||||
* From:
|
||||
* $Id: procfs.h,v 1.19 1998/05/19 00:00:13 tegge Exp $
|
||||
* $Id: procfs.h,v 1.20 1998/07/07 04:08:44 bde Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -56,7 +56,8 @@ typedef enum {
|
||||
Pnote, /* process notifier */
|
||||
Pnotepg, /* process group notifier */
|
||||
Pmap, /* memory map */
|
||||
Ptype /* executable type */
|
||||
Ptype, /* executable type */
|
||||
Pcmdline /* command line */
|
||||
} pfstype;
|
||||
|
||||
/*
|
||||
@ -154,6 +155,7 @@ int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct
|
||||
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_dotype __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
|
||||
/* Return 1 if process has special kernel digging privileges */
|
||||
int procfs_kmemaccess __P((struct proc *));
|
||||
|
@ -37,7 +37,7 @@
|
||||
* @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
|
||||
*
|
||||
* From:
|
||||
* $Id: procfs_status.c,v 1.10 1997/08/02 14:32:17 bde Exp $
|
||||
* $Id: procfs_status.c,v 1.11 1998/07/11 07:45:45 bde Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -147,3 +147,40 @@ procfs_dostatus(curp, p, pfs, uio)
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
procfs_docmdline(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps;
|
||||
int xlen;
|
||||
int error;
|
||||
char psbuf[256];
|
||||
|
||||
if (uio->uio_rw != UIO_READ)
|
||||
return (EOPNOTSUPP);
|
||||
|
||||
/*
|
||||
* For now, this is a hack. To implement this fully would require
|
||||
* groping around in the process address space to follow argv etc.
|
||||
*/
|
||||
ps = psbuf;
|
||||
bcopy(p->p_comm, ps, MAXCOMLEN);
|
||||
ps[MAXCOMLEN] = '\0';
|
||||
ps += strlen(ps);
|
||||
|
||||
ps += sprintf(ps, "\n");
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = min(xlen, uio->uio_resid);
|
||||
if (xlen <= 0)
|
||||
error = 0;
|
||||
else
|
||||
error = uiomove(ps, xlen, uio);
|
||||
return (error);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
*
|
||||
* @(#)procfs_subr.c 8.6 (Berkeley) 5/14/95
|
||||
*
|
||||
* $Id: procfs_subr.c,v 1.20 1997/12/09 05:03:41 sef Exp $
|
||||
* $Id: procfs_subr.c,v 1.21 1997/12/12 03:33:43 sef Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -181,6 +181,7 @@ procfs_allocvp(mp, vpp, pid, pfs_type)
|
||||
case Ptype:
|
||||
case Pmap:
|
||||
case Pstatus:
|
||||
case Pcmdline:
|
||||
pfs->pfs_mode = (VREAD) |
|
||||
(VREAD >> 3) |
|
||||
(VREAD >> 6);
|
||||
@ -282,6 +283,10 @@ procfs_rw(ap)
|
||||
rtval = procfs_dotype(curp, p, pfs, uio);
|
||||
break;
|
||||
|
||||
case Pcmdline:
|
||||
rtval = procfs_docmdline(curp, p, pfs, uio);
|
||||
break;
|
||||
|
||||
default:
|
||||
rtval = EOPNOTSUPP;
|
||||
break;
|
||||
|
@ -36,7 +36,7 @@
|
||||
*
|
||||
* @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95
|
||||
*
|
||||
* $Id: procfs_vnops.c,v 1.61 1998/07/11 07:45:46 bde Exp $
|
||||
* $Id: procfs_vnops.c,v 1.62 1998/12/04 22:54:51 archie Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -101,6 +101,7 @@ static struct proc_target {
|
||||
{ DT_REG, N("notepg"), Pnotepg, NULL },
|
||||
{ DT_REG, N("map"), Pmap, procfs_validmap },
|
||||
{ DT_REG, N("etype"), Ptype, procfs_validtype },
|
||||
{ DT_REG, N("cmdline"), Pcmdline, NULL },
|
||||
#undef N
|
||||
};
|
||||
static const int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
|
||||
@ -573,6 +574,7 @@ procfs_getattr(ap)
|
||||
case Pstatus:
|
||||
case Pnote:
|
||||
case Pnotepg:
|
||||
case Pcmdline:
|
||||
vap->va_nlink = 1;
|
||||
vap->va_uid = procp->p_ucred->cr_uid;
|
||||
vap->va_gid = procp->p_ucred->cr_gid;
|
||||
|
Loading…
Reference in New Issue
Block a user