Move the process-table stuff to a more suitable file.
Remove filetable stuff from kern_sysctl.c
This commit is contained in:
parent
18e6fe0250
commit
45a4ad1146
@ -34,7 +34,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
|
||||
* $Id: kern_sysctl.c,v 1.38 1995/11/12 19:51:51 phk Exp $
|
||||
* $Id: kern_sysctl.c,v 1.39 1995/11/13 13:54:09 phk Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -724,10 +724,6 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
|
||||
return (0);
|
||||
case KERN_VNODE:
|
||||
return (sysctl_vnode(oldp, oldlenp));
|
||||
case KERN_PROC:
|
||||
return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp));
|
||||
case KERN_FILE:
|
||||
return (sysctl_file(oldp, oldlenp));
|
||||
#ifdef GPROF
|
||||
case KERN_PROF:
|
||||
return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp,
|
||||
@ -989,214 +985,6 @@ sysctl_rdstruct(oldp, oldlenp, newp, sp, len)
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get file structures.
|
||||
*/
|
||||
int
|
||||
sysctl_file(where, sizep)
|
||||
char *where;
|
||||
size_t *sizep;
|
||||
{
|
||||
int buflen, error;
|
||||
struct file *fp;
|
||||
char *start = where;
|
||||
|
||||
buflen = *sizep;
|
||||
if (where == NULL) {
|
||||
/*
|
||||
* overestimate by 10 files
|
||||
*/
|
||||
*sizep = sizeof(filehead) + (nfiles + 10) * sizeof(struct file);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* first copyout filehead
|
||||
*/
|
||||
if (buflen < sizeof(filehead)) {
|
||||
*sizep = 0;
|
||||
return (0);
|
||||
}
|
||||
error = copyout((caddr_t)&filehead, where, sizeof(filehead));
|
||||
if (error)
|
||||
return (error);
|
||||
buflen -= sizeof(filehead);
|
||||
where += sizeof(filehead);
|
||||
|
||||
/*
|
||||
* followed by an array of file structures
|
||||
*/
|
||||
for (fp = filehead; fp != NULL; fp = fp->f_filef) {
|
||||
if (buflen < sizeof(struct file)) {
|
||||
*sizep = where - start;
|
||||
return (ENOMEM);
|
||||
}
|
||||
error = copyout((caddr_t)fp, where, sizeof (struct file));
|
||||
if (error)
|
||||
return (error);
|
||||
buflen -= sizeof(struct file);
|
||||
where += sizeof(struct file);
|
||||
}
|
||||
*sizep = where - start;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* try over estimating by 5 procs
|
||||
*/
|
||||
#define KERN_PROCSLOP (5 * sizeof (struct kinfo_proc))
|
||||
|
||||
int
|
||||
sysctl_doproc(name, namelen, where, sizep)
|
||||
int *name;
|
||||
u_int namelen;
|
||||
char *where;
|
||||
size_t *sizep;
|
||||
{
|
||||
register struct proc *p;
|
||||
register struct kinfo_proc *dp = (struct kinfo_proc *)where;
|
||||
register int needed = 0;
|
||||
int buflen = where != NULL ? *sizep : 0;
|
||||
int doingzomb;
|
||||
struct eproc eproc;
|
||||
int error = 0;
|
||||
|
||||
if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
|
||||
return (EINVAL);
|
||||
p = (struct proc *)allproc;
|
||||
doingzomb = 0;
|
||||
again:
|
||||
for (; p != NULL; p = p->p_next) {
|
||||
/*
|
||||
* Skip embryonic processes.
|
||||
*/
|
||||
if (p->p_stat == SIDL)
|
||||
continue;
|
||||
/*
|
||||
* TODO - make more efficient (see notes below).
|
||||
* do by session.
|
||||
*/
|
||||
switch (name[0]) {
|
||||
|
||||
case KERN_PROC_PID:
|
||||
/* could do this with just a lookup */
|
||||
if (p->p_pid != (pid_t)name[1])
|
||||
continue;
|
||||
break;
|
||||
|
||||
case KERN_PROC_PGRP:
|
||||
/* could do this by traversing pgrp */
|
||||
if (p->p_pgrp == NULL || p->p_pgrp->pg_id != (pid_t)name[1])
|
||||
continue;
|
||||
break;
|
||||
|
||||
case KERN_PROC_TTY:
|
||||
if ((p->p_flag & P_CONTROLT) == 0 ||
|
||||
p->p_session == NULL ||
|
||||
p->p_session->s_ttyp == NULL ||
|
||||
p->p_session->s_ttyp->t_dev != (dev_t)name[1])
|
||||
continue;
|
||||
break;
|
||||
|
||||
case KERN_PROC_UID:
|
||||
if (p->p_ucred == NULL || p->p_ucred->cr_uid != (uid_t)name[1])
|
||||
continue;
|
||||
break;
|
||||
|
||||
case KERN_PROC_RUID:
|
||||
if (p->p_ucred == NULL || p->p_cred->p_ruid != (uid_t)name[1])
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (buflen >= sizeof(struct kinfo_proc)) {
|
||||
fill_eproc(p, &eproc);
|
||||
error = copyout((caddr_t)p, &dp->kp_proc,
|
||||
sizeof(struct proc));
|
||||
if (error)
|
||||
return (error);
|
||||
error = copyout((caddr_t)&eproc, &dp->kp_eproc,
|
||||
sizeof(eproc));
|
||||
if (error)
|
||||
return (error);
|
||||
dp++;
|
||||
buflen -= sizeof(struct kinfo_proc);
|
||||
}
|
||||
needed += sizeof(struct kinfo_proc);
|
||||
}
|
||||
if (doingzomb == 0) {
|
||||
p = zombproc;
|
||||
doingzomb++;
|
||||
goto again;
|
||||
}
|
||||
if (where != NULL) {
|
||||
*sizep = (caddr_t)dp - where;
|
||||
if (needed > *sizep)
|
||||
return (ENOMEM);
|
||||
} else {
|
||||
needed += KERN_PROCSLOP;
|
||||
*sizep = needed;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in an eproc structure for the specified process.
|
||||
*/
|
||||
void
|
||||
fill_eproc(p, ep)
|
||||
register struct proc *p;
|
||||
register struct eproc *ep;
|
||||
{
|
||||
register struct tty *tp;
|
||||
|
||||
bzero(ep, sizeof(*ep));
|
||||
|
||||
ep->e_paddr = p;
|
||||
if (p->p_cred) {
|
||||
ep->e_pcred = *p->p_cred;
|
||||
if (p->p_ucred)
|
||||
ep->e_ucred = *p->p_ucred;
|
||||
}
|
||||
if (p->p_stat != SIDL && p->p_stat != SZOMB && p->p_vmspace != NULL) {
|
||||
register struct vmspace *vm = p->p_vmspace;
|
||||
|
||||
#ifdef pmap_resident_count
|
||||
ep->e_vm.vm_rssize = pmap_resident_count(&vm->vm_pmap); /*XXX*/
|
||||
#else
|
||||
ep->e_vm.vm_rssize = vm->vm_rssize;
|
||||
#endif
|
||||
ep->e_vm.vm_tsize = vm->vm_tsize;
|
||||
ep->e_vm.vm_dsize = vm->vm_dsize;
|
||||
ep->e_vm.vm_ssize = vm->vm_ssize;
|
||||
#ifndef sparc
|
||||
ep->e_vm.vm_pmap = vm->vm_pmap;
|
||||
#endif
|
||||
}
|
||||
if (p->p_pptr)
|
||||
ep->e_ppid = p->p_pptr->p_pid;
|
||||
if (p->p_pgrp) {
|
||||
ep->e_sess = p->p_pgrp->pg_session;
|
||||
ep->e_pgid = p->p_pgrp->pg_id;
|
||||
ep->e_jobc = p->p_pgrp->pg_jobc;
|
||||
}
|
||||
if ((p->p_flag & P_CONTROLT) &&
|
||||
(ep->e_sess != NULL) &&
|
||||
((tp = ep->e_sess->s_ttyp) != NULL)) {
|
||||
ep->e_tdev = tp->t_dev;
|
||||
ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
|
||||
ep->e_tsess = tp->t_session;
|
||||
} else
|
||||
ep->e_tdev = NODEV;
|
||||
if (ep->e_sess && ep->e_sess->s_ttyvp)
|
||||
ep->e_flag = EPROC_CTTY;
|
||||
if (SESS_LEADER(p))
|
||||
ep->e_flag |= EPROC_SLEADER;
|
||||
if (p->p_wmesg) {
|
||||
strncpy(ep->e_wmesg, p->p_wmesg, WMESGLEN);
|
||||
ep->e_wmesg[WMESGLEN] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef COMPAT_43
|
||||
#include <sys/socket.h>
|
||||
#define KINFO_PROC (0<<8)
|
||||
|
@ -28,7 +28,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: sys_process.c,v 1.14 1995/05/30 08:05:58 rgrimes Exp $
|
||||
* $Id: sys_process.c,v 1.15 1995/11/12 06:43:06 bde Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -359,3 +359,9 @@ trace_req(p)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/tty.h>
|
||||
#include "/sys/kern/aaa.c"
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user