procctl(2): add consistent shortcut P_ID:0 as curproc

Reported by:	bdrewery, emaste
Reviewed by:	emaste, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32513
This commit is contained in:
Konstantin Belousov 2021-10-15 22:01:42 +03:00
parent 7ae879b14a
commit f833ab9dd1
2 changed files with 13 additions and 5 deletions

View file

@ -62,6 +62,8 @@ The following identifier types are supported:
.It Dv P_PID
Control the process with the process ID
.Fa id .
.Fa id
zero is a shortcut for the calling process ID.
.It Dv P_PGID
Control processes belonging to the process group with the ID
.Fa id .

View file

@ -904,12 +904,18 @@ kern_procctl(struct thread *td, idtype_t idtype, id_t id, int com, void *data)
switch (idtype) {
case P_PID:
p = pfind(id);
if (p == NULL) {
error = ESRCH;
break;
if (id == 0) {
p = td->td_proc;
error = 0;
PROC_LOCK(p);
} else {
p = pfind(id);
if (p == NULL) {
error = ESRCH;
break;
}
error = p_cansee(td, p);
}
error = p_cansee(td, p);
if (error == 0)
error = kern_procctl_single(td, p, com, data);
PROC_UNLOCK(p);