mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-17 15:27:36 +00:00
- Proc locking.
- Use queue macros. - Use NULL instead of 0 for pointers. Reviewed by: des
This commit is contained in:
parent
f5f7ddc668
commit
ec447af191
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=71471
@ -127,8 +127,7 @@ linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
}
|
||||
swapused = swaptotal - swapfree;
|
||||
memshared = 0;
|
||||
for (object = TAILQ_FIRST(&vm_object_list); object != NULL;
|
||||
object = TAILQ_NEXT(object, object_list))
|
||||
TAILQ_FOREACH(object, &vm_object_list, object_list)
|
||||
if (object->shadow_count > 1)
|
||||
memshared += object->resident_page_count;
|
||||
memshared *= PAGE_SIZE;
|
||||
@ -474,6 +473,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
*/
|
||||
sbuf_printf(&sb, "Pid:\t%d\n", p->p_pid);
|
||||
sbuf_printf(&sb, "PPid:\t%d\n", ppid);
|
||||
PROC_LOCK(p);
|
||||
sbuf_printf(&sb, "Uid:\t%d %d %d %d\n", p->p_cred->p_ruid,
|
||||
p->p_ucred->cr_uid,
|
||||
p->p_cred->p_svuid,
|
||||
@ -487,6 +487,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
sbuf_cat(&sb, "Groups:\t");
|
||||
for (i = 0; i < p->p_ucred->cr_ngroups; i++)
|
||||
sbuf_printf(&sb, "%d ", p->p_ucred->cr_groups[i]);
|
||||
PROC_UNLOCK(p);
|
||||
sbuf_putc(&sb, '\n');
|
||||
|
||||
/*
|
||||
@ -521,6 +522,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
* supports 64 signals, but this code is a long way from
|
||||
* running on anything but i386, so ignore that for now.
|
||||
*/
|
||||
PROC_LOCK(p);
|
||||
sbuf_printf(&sb, "SigPnd:\t%08x\n", p->p_siglist.__bits[0]);
|
||||
/*
|
||||
* I can't seem to find out where the signal mask is in
|
||||
@ -529,6 +531,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
sbuf_printf(&sb, "SigBlk:\t%08x\n", 0); /* XXX */
|
||||
sbuf_printf(&sb, "SigIgn:\t%08x\n", p->p_sigignore.__bits[0]);
|
||||
sbuf_printf(&sb, "SigCgt:\t%08x\n", p->p_sigcatch.__bits[0]);
|
||||
PROC_UNLOCK(p);
|
||||
|
||||
/*
|
||||
* Linux also prints the capability masks, but we don't have
|
||||
|
@ -127,8 +127,7 @@ linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
}
|
||||
swapused = swaptotal - swapfree;
|
||||
memshared = 0;
|
||||
for (object = TAILQ_FIRST(&vm_object_list); object != NULL;
|
||||
object = TAILQ_NEXT(object, object_list))
|
||||
TAILQ_FOREACH(object, &vm_object_list, object_list)
|
||||
if (object->shadow_count > 1)
|
||||
memshared += object->resident_page_count;
|
||||
memshared *= PAGE_SIZE;
|
||||
@ -474,6 +473,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
*/
|
||||
sbuf_printf(&sb, "Pid:\t%d\n", p->p_pid);
|
||||
sbuf_printf(&sb, "PPid:\t%d\n", ppid);
|
||||
PROC_LOCK(p);
|
||||
sbuf_printf(&sb, "Uid:\t%d %d %d %d\n", p->p_cred->p_ruid,
|
||||
p->p_ucred->cr_uid,
|
||||
p->p_cred->p_svuid,
|
||||
@ -487,6 +487,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
sbuf_cat(&sb, "Groups:\t");
|
||||
for (i = 0; i < p->p_ucred->cr_ngroups; i++)
|
||||
sbuf_printf(&sb, "%d ", p->p_ucred->cr_groups[i]);
|
||||
PROC_UNLOCK(p);
|
||||
sbuf_putc(&sb, '\n');
|
||||
|
||||
/*
|
||||
@ -521,6 +522,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
* supports 64 signals, but this code is a long way from
|
||||
* running on anything but i386, so ignore that for now.
|
||||
*/
|
||||
PROC_LOCK(p);
|
||||
sbuf_printf(&sb, "SigPnd:\t%08x\n", p->p_siglist.__bits[0]);
|
||||
/*
|
||||
* I can't seem to find out where the signal mask is in
|
||||
@ -529,6 +531,7 @@ linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
sbuf_printf(&sb, "SigBlk:\t%08x\n", 0); /* XXX */
|
||||
sbuf_printf(&sb, "SigIgn:\t%08x\n", p->p_sigignore.__bits[0]);
|
||||
sbuf_printf(&sb, "SigCgt:\t%08x\n", p->p_sigcatch.__bits[0]);
|
||||
PROC_UNLOCK(p);
|
||||
|
||||
/*
|
||||
* Linux also prints the capability masks, but we don't have
|
||||
|
@ -192,12 +192,15 @@ linprocfs_close(ap)
|
||||
* told to stop on an event, but then the requesting process
|
||||
* has gone away or forgotten about it.
|
||||
*/
|
||||
if ((ap->a_vp->v_usecount < 2)
|
||||
&& (p = pfind(pfs->pfs_pid))
|
||||
&& !(p->p_pfsflags & PF_LINGER)) {
|
||||
p->p_stops = 0;
|
||||
p->p_step = 0;
|
||||
wakeup(&p->p_step);
|
||||
if ((ap->a_vp->v_usecount < 2) && (p = pfind(pfs->pfs_pid))) {
|
||||
PROC_LOCK(p);
|
||||
if (!(p->p_pfsflags & PF_LINGER)) {
|
||||
p->p_stops = 0;
|
||||
p->p_step = 0;
|
||||
PROC_UNLOCK(p);
|
||||
wakeup(&p->p_step);
|
||||
} else
|
||||
PROC_UNLOCK(p);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -232,10 +235,14 @@ linprocfs_ioctl(ap)
|
||||
|
||||
switch (ap->a_command) {
|
||||
case PIOCBIS:
|
||||
PROC_LOCK(procp);
|
||||
procp->p_stops |= *(unsigned int*)ap->a_data;
|
||||
PROC_UNLOCK(procp);
|
||||
break;
|
||||
case PIOCBIC:
|
||||
PROC_LOCK(procp);
|
||||
procp->p_stops &= ~*(unsigned int*)ap->a_data;
|
||||
PROC_UNLOCK(procp);
|
||||
break;
|
||||
case PIOCSFL:
|
||||
/*
|
||||
@ -246,12 +253,18 @@ linprocfs_ioctl(ap)
|
||||
flags = (unsigned char)*(unsigned int*)ap->a_data;
|
||||
if (flags & NFLAGS && (error = suser(p)))
|
||||
return error;
|
||||
PROC_LOCK(procp);
|
||||
procp->p_pfsflags = flags;
|
||||
PROC_UNLOCK(procp);
|
||||
break;
|
||||
case PIOCGFL:
|
||||
PROC_LOCK(procp);
|
||||
*(unsigned int*)ap->a_data = (unsigned int)procp->p_pfsflags;
|
||||
PROC_UNLOCK(procp);
|
||||
/* FALLTHROUGH */
|
||||
case PIOCSTATUS:
|
||||
psp = (struct procfs_status *)ap->a_data;
|
||||
PROC_LOCK(procp);
|
||||
psp->state = (procp->p_step == 0);
|
||||
psp->flags = procp->p_pfsflags;
|
||||
psp->events = procp->p_stops;
|
||||
@ -261,29 +274,41 @@ linprocfs_ioctl(ap)
|
||||
} else {
|
||||
psp->why = psp->val = 0; /* Not defined values */
|
||||
}
|
||||
PROC_UNLOCK(procp);
|
||||
break;
|
||||
case PIOCWAIT:
|
||||
psp = (struct procfs_status *)ap->a_data;
|
||||
PROC_LOCK(procp);
|
||||
if (procp->p_step == 0) {
|
||||
error = tsleep(&procp->p_stype, PWAIT | PCATCH, "piocwait", 0);
|
||||
if (error)
|
||||
error = msleep(&procp->p_stype, &procp->p_mtx, PWAIT | PCATCH,
|
||||
"piocwait", 0);
|
||||
if (error) {
|
||||
PROC_UNLOCK(procp);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
psp->state = 1; /* It stopped */
|
||||
psp->flags = procp->p_pfsflags;
|
||||
psp->events = procp->p_stops;
|
||||
psp->why = procp->p_stype; /* why it stopped */
|
||||
psp->val = procp->p_xstat; /* any extra info */
|
||||
PROC_UNLOCK(procp);
|
||||
break;
|
||||
case PIOCCONT: /* Restart a proc */
|
||||
if (procp->p_step == 0)
|
||||
PROC_LOCK(procp);
|
||||
if (procp->p_step == 0) {
|
||||
PROC_UNLOCK(procp);
|
||||
return EINVAL; /* Can only start a stopped process */
|
||||
}
|
||||
PROC_UNLOCK(procp);
|
||||
if ((signo = *(int*)ap->a_data) != 0) {
|
||||
if (signo >= NSIG || signo <= 0)
|
||||
return EINVAL;
|
||||
psignal(procp, signo);
|
||||
}
|
||||
PROC_LOCK(procp);
|
||||
procp->p_step = 0;
|
||||
PROC_UNLOCK(procp);
|
||||
wakeup(&procp->p_step);
|
||||
break;
|
||||
default:
|
||||
@ -419,15 +444,19 @@ linprocfs_getattr(ap)
|
||||
switch (pfs->pfs_type) {
|
||||
case Proot:
|
||||
case Pself:
|
||||
procp = 0;
|
||||
procp = NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
procp = PFIND(pfs->pfs_pid);
|
||||
if (procp == 0 || procp->p_cred == NULL ||
|
||||
procp->p_ucred == NULL)
|
||||
if (procp == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
PROC_LOCK(procp);
|
||||
if (procp->p_cred == NULL || procp->p_ucred == NULL) {
|
||||
PROC_UNLOCK(procp);
|
||||
return (ENOENT);
|
||||
}
|
||||
PROC_UNLOCK(procp);
|
||||
if (p_can(ap->a_p, procp, P_CAN_SEE, NULL))
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -465,8 +494,10 @@ linprocfs_getattr(ap)
|
||||
switch (pfs->pfs_type) {
|
||||
case Pmem:
|
||||
/* Retain group kmem readablity. */
|
||||
PROC_LOCK(procp);
|
||||
if (procp->p_flag & P_SUGID)
|
||||
vap->va_mode &= ~(VREAD|VWRITE);
|
||||
PROC_UNLOCK(procp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -484,8 +515,10 @@ linprocfs_getattr(ap)
|
||||
|
||||
vap->va_nlink = 1;
|
||||
if (procp) {
|
||||
PROC_LOCK(procp);
|
||||
vap->va_uid = procp->p_ucred->cr_uid;
|
||||
vap->va_gid = procp->p_ucred->cr_gid;
|
||||
PROC_UNLOCK(procp);
|
||||
}
|
||||
|
||||
switch (pfs->pfs_type) {
|
||||
@ -543,10 +576,12 @@ linprocfs_getattr(ap)
|
||||
* change the owner to root - otherwise 'ps' and friends
|
||||
* will break even though they are setgid kmem. *SIGH*
|
||||
*/
|
||||
PROC_LOCK(procp);
|
||||
if (procp->p_flag & P_SUGID)
|
||||
vap->va_uid = 0;
|
||||
else
|
||||
vap->va_uid = procp->p_ucred->cr_uid;
|
||||
PROC_UNLOCK(procp);
|
||||
vap->va_gid = KMEM_GROUP;
|
||||
break;
|
||||
|
||||
@ -705,7 +740,7 @@ linprocfs_lookup(ap)
|
||||
break;
|
||||
|
||||
p = PFIND(pid);
|
||||
if (p == 0)
|
||||
if (p == NULL)
|
||||
break;
|
||||
|
||||
if (p_can(curp, p, P_CAN_SEE, NULL))
|
||||
@ -718,7 +753,7 @@ linprocfs_lookup(ap)
|
||||
return (linprocfs_root(dvp->v_mount, vpp));
|
||||
|
||||
p = PFIND(pfs->pfs_pid);
|
||||
if (p == 0)
|
||||
if (p == NULL)
|
||||
break;
|
||||
|
||||
for (pt = proc_targets, i = 0; i < nproc_targets; pt++, i++) {
|
||||
@ -843,7 +878,7 @@ linprocfs_readdir(ap)
|
||||
struct proc *p;
|
||||
|
||||
ALLPROC_LOCK(AP_SHARED);
|
||||
p = allproc.lh_first;
|
||||
p = LIST_FIRST(&allproc);
|
||||
for (; p && uio->uio_resid >= delen; i++, pcnt++) {
|
||||
bzero((char *) dp, delen);
|
||||
dp->d_reclen = delen;
|
||||
@ -902,23 +937,23 @@ linprocfs_readdir(ap)
|
||||
|
||||
default:
|
||||
while (pcnt < i) {
|
||||
p = p->p_list.le_next;
|
||||
if (!p)
|
||||
p = LIST_NEXT(p, p_list);
|
||||
if (p == NULL)
|
||||
goto done;
|
||||
if (p_can(curproc, p, P_CAN_SEE, NULL))
|
||||
continue;
|
||||
pcnt++;
|
||||
}
|
||||
while (p_can(curproc, p, P_CAN_SEE, NULL)) {
|
||||
p = p->p_list.le_next;
|
||||
if (!p)
|
||||
p = LIST_NEXT(p, p_list);
|
||||
if (p == NULL)
|
||||
goto done;
|
||||
}
|
||||
dp->d_fileno = PROCFS_FILENO(p->p_pid, Pproc);
|
||||
dp->d_namlen = sprintf(dp->d_name, "%ld",
|
||||
(long)p->p_pid);
|
||||
dp->d_type = DT_DIR;
|
||||
p = p->p_list.le_next;
|
||||
p = LIST_NEXT(p, p_list);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -928,9 +963,9 @@ linprocfs_readdir(ap)
|
||||
done:
|
||||
|
||||
#ifdef PROCFS_ZOMBIE
|
||||
if (p == 0 && doingzomb == 0) {
|
||||
if (p == NULL && doingzomb == 0) {
|
||||
doingzomb = 1;
|
||||
p = zombproc.lh_first;
|
||||
p = LIST_FIRST(&zombproc);
|
||||
goto again;
|
||||
}
|
||||
#endif
|
||||
@ -978,13 +1013,18 @@ linprocfs_readlink(ap)
|
||||
*/
|
||||
case Pexe:
|
||||
procp = PFIND(pfs->pfs_pid);
|
||||
if (procp != NULL)
|
||||
PROC_LOCK(procp);
|
||||
if (procp == NULL || procp->p_cred == NULL ||
|
||||
procp->p_ucred == NULL) {
|
||||
if (procp != NULL)
|
||||
PROC_UNLOCK(procp);
|
||||
printf("linprocfs_readlink: pid %d disappeared\n",
|
||||
pfs->pfs_pid);
|
||||
return (uiomove("unknown", sizeof("unknown") - 1,
|
||||
ap->a_uio));
|
||||
}
|
||||
PROC_UNLOCK(procp);
|
||||
error = textvp_fullpath(procp, &fullpath, &freepath);
|
||||
if (error != 0)
|
||||
return (uiomove("unknown", sizeof("unknown") - 1,
|
||||
|
Loading…
Reference in New Issue
Block a user