Index: sys/kern/kern_prot.c =================================================================== --- sys/kern/kern_prot.c +++ sys/kern/kern_prot.c @@ -158,24 +158,36 @@ #endif int sys_getpgid(struct thread *td, struct getpgid_args *uap) +{ + pid_t pgid; + int error; + + error = kern_getpgid(td, uap->pid, &pgid); + if (error == 0) + td->td_retval[0] = pgid; + return (error); +} + +int +kern_getpgid(struct thread *td, pid_t pid, pid_t *pgid) { struct proc *p; int error; - if (uap->pid == 0) { + if (pid == 0) { p = td->td_proc; PROC_LOCK(p); } else { - p = pfind(uap->pid); + p = pfind(pid); if (p == NULL) return (ESRCH); error = p_cansee(td, p); - if (error) { + if (error != 0) { PROC_UNLOCK(p); return (error); } } - td->td_retval[0] = p->p_pgrp->pg_id; + *pgid = p->p_pgrp->pg_id; PROC_UNLOCK(p); return (0); } Index: sys/sys/syscallsubr.h =================================================================== --- sys/sys/syscallsubr.h +++ sys/sys/syscallsubr.h @@ -158,6 +158,7 @@ int kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, size_t *countp, enum uio_seg bufseg, int mode); int kern_getitimer(struct thread *, u_int, struct itimerval *); +int kern_getpgid(struct thread *, pid_t, pid_t *); int kern_getppid(struct thread *); int kern_getpeername(struct thread *td, int fd, struct sockaddr **sa, socklen_t *alen);