summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unistd.h3
-rw-r--r--lib/libc/sys/getpgrp.216
-rw-r--r--lib/libc/sys/getsid.29
-rw-r--r--sys/kern/kern_prot.c39
4 files changed, 46 insertions, 21 deletions
diff --git a/include/unistd.h b/include/unistd.h
index 65084f6c763..847abb38881 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unistd.h,v 1.32 2000/07/19 19:26:04 mickey Exp $ */
+/* $OpenBSD: unistd.h,v 1.33 2000/09/12 17:30:45 millert Exp $ */
/* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */
/*-
@@ -85,6 +85,7 @@ pid_t getpgrp __P((void));
pid_t getpid __P((void));
pid_t getpgid __P((pid_t));
pid_t getppid __P((void));
+pid_t getsid __P((pid_t));
uid_t getuid __P((void));
int isatty __P((int));
int link __P((const char *, const char *));
diff --git a/lib/libc/sys/getpgrp.2 b/lib/libc/sys/getpgrp.2
index 7ad5ef3799b..e278dcd070d 100644
--- a/lib/libc/sys/getpgrp.2
+++ b/lib/libc/sys/getpgrp.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getpgrp.2,v 1.6 1999/07/04 18:59:43 aaron Exp $
+.\" $OpenBSD: getpgrp.2,v 1.7 2000/09/12 17:30:45 millert Exp $
.\" $NetBSD: getpgrp.2,v 1.8 1995/02/27 12:33:09 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -71,6 +71,20 @@ and
.Fn tcsetpgrp
calls
are used to get/set the process group of the control terminal.
+.Sh ERRORS
+.Fn getpgrp
+always succeeds, however
+.Fn getpgid
+will succeed unless:
+.Bl -tag -width Er
+.It Bq Er EPERM
+if the current process and the process
+.Fa pid
+are not in the same session.
+.It Bq Er ESRCH
+if there is no process with a process ID equal to
+.Fa pid .
+.El
.Sh SEE ALSO
.Xr setpgid 2 ,
.Xr termios 4
diff --git a/lib/libc/sys/getsid.2 b/lib/libc/sys/getsid.2
index 6d0497876d6..31a66c93e5e 100644
--- a/lib/libc/sys/getsid.2
+++ b/lib/libc/sys/getsid.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getsid.2,v 1.7 2000/03/01 17:31:23 todd Exp $
+.\" $OpenBSD: getsid.2,v 1.8 2000/09/12 17:30:45 millert Exp $
.\"
.\" Copyright (c) 1997 Peter Wemm <peter@freebsd.org>
.\"
@@ -56,13 +56,14 @@ to indicate an error.
.Fn getsid
will succeed unless:
.Bl -tag -width Er
+.It Bq Er EPERM
+if the current process and the process
+.Fa pid
+are not in the same session.
.It Bq Er ESRCH
if there is no process with a process ID equal to
.Fa pid .
.El
-.Pp
-Note that an implementation may restrict this function call to
-processes within the same session ID as the calling process.
.Sh SEE ALSO
.Xr getpgid 2 ,
.Xr getpgrp 2 ,
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index ee580d7e3dc..cbb9f6e88cc 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_prot.c,v 1.12 1997/11/17 05:57:45 deraadt Exp $ */
+/* $OpenBSD: kern_prot.c,v 1.13 2000/09/12 17:30:45 millert Exp $ */
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
/*
@@ -100,42 +100,51 @@ sys_getpgrp(p, v, retval)
/*
* SysVR.4 compatible getpgid()
*/
-int
-sys_getpgid(p, v, retval)
- struct proc *p;
+pid_t
+sys_getpgid(curp, v, retval)
+ struct proc *curp;
void *v;
register_t *retval;
{
register struct sys_getpgid_args /* {
syscallarg(pid_t) pid;
} */ *uap = v;
+ struct proc *targp = curp;
- if (SCARG(uap, pid) == 0)
+ if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == curp->p_pid)
goto found;
- if ((p = pfind(SCARG(uap, pid))) == 0)
+ if ((targp = pfind(SCARG(uap, pid))) == NULL)
return (ESRCH);
+ if (targp->p_session != curp->p_session)
+ return (EPERM);
found:
- *retval = p->p_pgid;
- return 0;
+ *retval = targp->p_pgid;
+ return (0);
}
-int
-sys_getsid(p, v, retval)
- struct proc *p;
+pid_t
+sys_getsid(curp, v, retval)
+ struct proc *curp;
void *v;
register_t *retval;
{
register struct sys_getsid_args /* {
syscallarg(pid_t) pid;
} */ *uap = v;
+ struct proc *targp = curp;
- if (SCARG(uap, pid) == 0)
+ if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == curp->p_pid)
goto found;
- if ((p == pfind(SCARG(uap, pid))) == 0)
+ if ((targp = pfind(SCARG(uap, pid))) == NULL)
return (ESRCH);
+ if (targp->p_session != curp->p_session)
+ return (EPERM);
found:
- *retval = p->p_pgrp->pg_session->s_leader->p_pid;
- return 0;
+ /* Skip exiting processes */
+ if (targp->p_pgrp->pg_session->s_leader == NULL)
+ return (ESRCH);
+ *retval = targp->p_pgrp->pg_session->s_leader->p_pid;
+ return (0);
}
/* ARGSUSED */