summaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2010-07-26 01:56:28 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2010-07-26 01:56:28 +0000
commit12738501a521de949783a0ef772f333a85a28079 (patch)
treea8d79b5579bc5fb4f0fe053219d7da149a912112 /sys/compat
parent58397ea88d58979fc9e046dc9c64692785b924ae (diff)
Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not struct proc. This fixes a bunch of problem cases in rthreads. Based on earlier work by blambert and myself, but mostly written at c2k10. Tested by many: deraadt, sthen, krw, ray, and in snapshots
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/common/tty_43.c4
-rw-r--r--sys/compat/linux/linux_file.c13
-rw-r--r--sys/compat/linux/linux_misc.c10
-rw-r--r--sys/compat/svr4/svr4_fcntl.c6
-rw-r--r--sys/compat/svr4/svr4_misc.c39
5 files changed, 38 insertions, 34 deletions
diff --git a/sys/compat/common/tty_43.c b/sys/compat/common/tty_43.c
index 8c7595b548e..e2973d4ad4d 100644
--- a/sys/compat/common/tty_43.c
+++ b/sys/compat/common/tty_43.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty_43.c,v 1.9 2004/09/19 21:34:42 mickey Exp $ */
+/* $OpenBSD: tty_43.c,v 1.10 2010/07/26 01:56:27 guenther Exp $ */
/* $NetBSD: tty_43.c,v 1.5 1996/05/20 14:29:17 mark Exp $ */
/*-
@@ -243,7 +243,7 @@ ttcompat(tp, com, data, flag, p)
if (tp->t_session->s_leader == NULL)
return ENOTTY;
- *(int *) data = tp->t_session->s_leader->p_pid;
+ *(int *) data = tp->t_session->s_leader->ps_pid;
break;
default:
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index d717b8df49f..3cce3741841 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_file.c,v 1.23 2006/09/25 07:12:57 otto Exp $ */
+/* $OpenBSD: linux_file.c,v 1.24 2010/07/26 01:56:27 guenther Exp $ */
/* $NetBSD: linux_file.c,v 1.15 1996/05/20 01:59:09 fvdl Exp $ */
/*
@@ -190,7 +190,8 @@ linux_sys_open(p, v, retval)
* terminal yet, and the O_NOCTTY flag is not set, try to make
* this the controlling terminal.
*/
- if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
+ if (!(fl & O_NOCTTY) && SESS_LEADER(p->p_p) &&
+ !(p->p_p->ps_flags & PS_CONTROLT)) {
struct filedesc *fdp = p->p_fd;
struct file *fp;
@@ -417,13 +418,13 @@ linux_sys_fcntl(p, v, retval)
if ((long)arg <= 0) {
pgid = -(long)arg;
} else {
- struct proc *p1 = pfind((long)arg);
- if (p1 == 0)
+ struct process *pr = prfind((long)arg);
+ if (pr == 0)
return (ESRCH);
- pgid = (long)p1->p_pgrp->pg_id;
+ pgid = (long)pr->ps_pgrp->pg_id;
}
pgrp = pgfind(pgid);
- if (pgrp == NULL || pgrp->pg_session != p->p_session)
+ if (pgrp == NULL || pgrp->pg_session != p->p_p->ps_session)
return EPERM;
tp->t_pgrp = pgrp;
return 0;
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 5def1551993..cb7abec8993 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_misc.c,v 1.64 2010/06/30 21:54:35 guenther Exp $ */
+/* $OpenBSD: linux_misc.c,v 1.65 2010/07/26 01:56:27 guenther Exp $ */
/* $NetBSD: linux_misc.c,v 1.27 1996/05/20 01:59:21 fvdl Exp $ */
/*-
@@ -1223,16 +1223,16 @@ linux_sys_getpgid(p, v, retval)
struct linux_sys_getpgid_args /* {
syscallarg(int) pid;
} */ *uap = v;
- struct proc *targp;
+ struct process *targpr;
if (SCARG(uap, pid) != 0 && SCARG(uap, pid) != p->p_pid) {
- if ((targp = pfind(SCARG(uap, pid))) == 0)
+ if ((targpr = prfind(SCARG(uap, pid))) == 0)
return ESRCH;
}
else
- targp = p;
+ targpr = p->p_p;
- retval[0] = targp->p_pgid;
+ retval[0] = targpr->ps_pgid;
return 0;
}
diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c
index 02d10d8399a..eb4d927222f 100644
--- a/sys/compat/svr4/svr4_fcntl.c
+++ b/sys/compat/svr4/svr4_fcntl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_fcntl.c,v 1.22 2002/03/14 01:26:51 millert Exp $ */
+/* $OpenBSD: svr4_fcntl.c,v 1.23 2010/07/26 01:56:27 guenther Exp $ */
/* $NetBSD: svr4_fcntl.c,v 1.14 1995/10/14 20:24:24 christos Exp $ */
/*
@@ -338,8 +338,8 @@ svr4_sys_open(p, v, retval)
if (error)
return error;
- if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) &&
- !(p->p_flag & P_CONTROLT)) {
+ if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p->p_p) &&
+ !(p->p_p->ps_flags & PS_CONTROLT)) {
struct filedesc *fdp = p->p_fd;
struct file *fp;
diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c
index f2700bf2d1a..dd2130514a2 100644
--- a/sys/compat/svr4/svr4_misc.c
+++ b/sys/compat/svr4/svr4_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_misc.c,v 1.54 2010/05/25 16:39:15 thib Exp $ */
+/* $OpenBSD: svr4_misc.c,v 1.55 2010/07/26 01:56:27 guenther Exp $ */
/* $NetBSD: svr4_misc.c,v 1.42 1996/12/06 03:22:34 christos Exp $ */
/*
@@ -101,7 +101,7 @@ static void bsd_statfs_to_svr4_statvfs(const struct statfs *,
struct svr4_statvfs *);
static void bsd_statfs_to_svr4_statvfs64(const struct statfs *,
struct svr4_statvfs64 *);
-static struct proc *svr4_pfind(pid_t pid);
+static struct process *svr4_prfind(pid_t pid);
static int svr4_mknod(struct proc *, register_t *, char *,
svr4_mode_t, svr4_dev_t);
@@ -815,20 +815,20 @@ svr4_sys_ulimit(p, v, retval)
}
-static struct proc *
-svr4_pfind(pid)
- pid_t pid;
+static struct process *
+svr4_prfind(pid_t pid)
{
+ struct process *pr;
struct proc *p;
/* look in the live processes */
- if ((p = pfind(pid)) != NULL)
- return p;
+ if ((pr = prfind(pid)) != NULL)
+ return pr;
/* look in the zombies */
LIST_FOREACH(p, &zombproc, p_list)
if (p->p_pid == pid)
- return p;
+ return p->p_flag & P_THREAD ? NULL : p->p_p;
return NULL;
}
@@ -841,11 +841,12 @@ svr4_sys_pgrpsys(p, v, retval)
register_t *retval;
{
struct svr4_sys_pgrpsys_args *uap = v;
+ struct process *pr = p->p_p;
int error;
switch (SCARG(uap, cmd)) {
case 0: /* getpgrp() */
- *retval = p->p_pgrp->pg_id;
+ *retval = pr->ps_pgrp->pg_id;
return 0;
case 1: /* setpgrp() */
@@ -856,19 +857,19 @@ svr4_sys_pgrpsys(p, v, retval)
SCARG(&sa, pgid) = 0;
if ((error = sys_setpgid(p, &sa, retval)) != 0)
return error;
- *retval = p->p_pgrp->pg_id;
+ *retval = pr->ps_pgrp->pg_id;
return 0;
}
case 2: /* getsid(pid) */
if (SCARG(uap, pid) != 0 &&
- (p = svr4_pfind(SCARG(uap, pid))) == NULL)
+ (pr = svr4_prfind(SCARG(uap, pid))) == NULL)
return ESRCH;
/*
* we return the pid of the session leader for this
* process
*/
- *retval = (register_t) p->p_session->s_leader->p_pid;
+ *retval = (register_t)pr->ps_session->s_leader->ps_pid;
return 0;
case 3: /* setsid() */
@@ -877,10 +878,10 @@ svr4_sys_pgrpsys(p, v, retval)
case 4: /* getpgid(pid) */
if (SCARG(uap, pid) != 0 &&
- (p = svr4_pfind(SCARG(uap, pid))) == NULL)
+ (pr = svr4_prfind(SCARG(uap, pid))) == NULL)
return ESRCH;
- *retval = (int) p->p_pgrp->pg_id;
+ *retval = (int)pr->ps_pgrp->pg_id;
return 0;
case 5: /* setpgid(pid, pgid); */
@@ -1042,6 +1043,7 @@ svr4_sys_waitsys(q, v, retval)
struct svr4_sys_waitsys_args *uap = v;
int nfound;
int error;
+ struct process *pr;
struct proc *p;
switch (SCARG(uap, grp)) {
@@ -1049,7 +1051,7 @@ svr4_sys_waitsys(q, v, retval)
break;
case SVR4_P_PGID:
- SCARG(uap, id) = -q->p_pgid;
+ SCARG(uap, id) = -q->p_p->ps_pgid;
break;
case SVR4_P_ALL:
@@ -1065,12 +1067,13 @@ svr4_sys_waitsys(q, v, retval)
loop:
nfound = 0;
- LIST_FOREACH(p, &q->p_children, p_sibling) {
+ LIST_FOREACH(pr, &q->p_p->ps_children, ps_sibling) {
+ p = pr->ps_mainproc;
if (SCARG(uap, id) != WAIT_ANY &&
p->p_pid != SCARG(uap, id) &&
- p->p_pgid != -SCARG(uap, id)) {
+ pr->ps_pgid != -SCARG(uap, id)) {
DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
- p->p_pgid, SCARG(uap, id)));
+ pr->ps_pgid, SCARG(uap, id)));
continue;
}
nfound++;