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

(cherry picked from commit f833ab9dd1)
This commit is contained in:
Konstantin Belousov 2021-10-15 22:01:42 +03:00
parent 19eec36599
commit 2e69ba48b9
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);