summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorAleksander Piotrowski <alek@cvs.openbsd.org>2006-05-23 22:28:23 +0000
committerAleksander Piotrowski <alek@cvs.openbsd.org>2006-05-23 22:28:23 +0000
commit602b6be4d916dd9861bd6bf6d618fde5519ddfb8 (patch)
tree19276426c9867d071696c830904ee3be9a380ce6 /sys/dev
parentd9045fd59df5bb83a9e430b4bb2b21f89b7561e2 (diff)
Replace lockmgr with rwlock; 'i think so' tedu@, ok sturm@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/systrace.c68
-rw-r--r--sys/dev/systrace.h5
2 files changed, 37 insertions, 36 deletions
diff --git a/sys/dev/systrace.c b/sys/dev/systrace.c
index 8670f716d0f..bdf849e455d 100644
--- a/sys/dev/systrace.c
+++ b/sys/dev/systrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: systrace.c,v 1.40 2005/12/11 21:30:30 miod Exp $ */
+/* $OpenBSD: systrace.c,v 1.41 2006/05/23 22:28:22 alek Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -42,7 +42,7 @@
#include <sys/filedesc.h>
#include <sys/filio.h>
#include <sys/signalvar.h>
-#include <sys/lock.h>
+#include <sys/rwlock.h>
#include <sys/pool.h>
#include <sys/mount.h>
#include <sys/namei.h>
@@ -133,18 +133,18 @@ struct str_process {
int injectind;
};
-struct lock systrace_lck;
+struct rwlock systrace_lck;
static __inline void
systrace_lock(void)
{
- lockmgr(&systrace_lck, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&systrace_lck);
}
static __inline void
systrace_unlock(void)
{
- lockmgr(&systrace_lck, LK_RELEASE, NULL);
+ rw_exit_write(&systrace_lck);
}
/* Needs to be called with fst locked */
@@ -215,7 +215,7 @@ systracef_read(fp, poff, uio, cred)
again:
systrace_lock();
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
if ((process = TAILQ_FIRST(&fst->messages)) != NULL) {
error = uiomove((caddr_t)&process->msg,
@@ -235,7 +235,7 @@ systracef_read(fp, poff, uio, cred)
if (fp->f_flag & FNONBLOCK)
error = EAGAIN;
else {
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
error = tsleep(fst, PWAIT|PCATCH, "systrrd", 0);
if (error)
goto out;
@@ -244,7 +244,7 @@ systracef_read(fp, poff, uio, cred)
}
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
out:
return (error);
}
@@ -332,7 +332,7 @@ systracef_ioctl(fp, cmd, data, p)
return (ret);
systrace_lock();
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
if (pid) {
strp = systrace_findpid(fst, pid);
@@ -404,7 +404,7 @@ systracef_ioctl(fp, cmd, data, p)
}
unlock:
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
return (ret);
}
@@ -422,13 +422,13 @@ systracef_poll(fp, events, p)
return (0);
systrace_lock();
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
if (!TAILQ_EMPTY(&fst->messages))
revents = events & (POLLIN | POLLRDNORM);
else
selrecord(p, &fst->si);
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
return (revents);
}
@@ -463,7 +463,7 @@ systracef_close(fp, p)
struct str_policy *strpol;
systrace_lock();
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
/* Untrace all processes */
@@ -492,7 +492,7 @@ systracef_close(fp, p)
vrele(fst->fd_cdir);
if (fst->fd_rdir)
vrele(fst->fd_rdir);
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
FREE(fp->f_data, M_XDATA);
fp->f_data = NULL;
@@ -507,7 +507,7 @@ systraceattach(int n)
"strprocpl", NULL);
pool_init(&systr_policy_pl, sizeof(struct str_policy), 0, 0, 0,
"strpolpl", NULL);
- lockinit(&systrace_lck, PLOCK, "systrace", 0, 0);
+ rw_init(&systrace_lck, "systrace");
}
int
@@ -566,7 +566,7 @@ systraceioctl(dev, cmd, data, flag, p)
M_XDATA, M_WAITOK);
memset(fst, 0, sizeof(struct fsystrace));
- lockinit(&fst->lock, PLOCK, "systrace", 0, 0);
+ rw_init(&fst->lock, "systrace");
TAILQ_INIT(&fst->processes);
TAILQ_INIT(&fst->messages);
TAILQ_INIT(&fst->policies);
@@ -638,14 +638,14 @@ systrace_exit(struct proc *proc)
strp = proc->p_systrace;
if (strp != NULL) {
fst = strp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
/* Insert Exit message */
systrace_msg_child(fst, strp, -1);
systrace_detach(strp);
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
} else
systrace_unlock();
CLR(proc->p_flag, P_SYSTRACE);
@@ -665,7 +665,7 @@ systrace_fork(struct proc *oldproc, struct proc *p)
}
fst = oldstrp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
if (systrace_insert_process(fst, p))
@@ -680,7 +680,7 @@ systrace_fork(struct proc *oldproc, struct proc *p)
/* Insert fork message */
systrace_msg_child(fst, oldstrp, p->p_pid);
out:
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
}
#define REACQUIRE_LOCK do { \
@@ -691,7 +691,7 @@ systrace_fork(struct proc *oldproc, struct proc *p)
return (error); \
} \
fst = strp->parent; \
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL); \
+ rw_enter_write(&fst->lock); \
systrace_unlock(); \
} while (0)
@@ -724,7 +724,7 @@ systrace_redirect(int code, struct proc *p, void *v, register_t *retval)
fst = strp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
/*
@@ -768,7 +768,7 @@ systrace_redirect(int code, struct proc *p, void *v, register_t *retval)
error = EPERM;
}
systrace_replacefree(strp);
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
if (policy == SYSTR_POLICY_PERMIT)
error = (*callp->sy_call)(p, v, retval);
return (error);
@@ -797,7 +797,7 @@ systrace_redirect(int code, struct proc *p, void *v, register_t *retval)
}
fst = strp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
if (strp->answer == SYSTR_POLICY_NEVER) {
@@ -832,7 +832,7 @@ systrace_redirect(int code, struct proc *p, void *v, register_t *retval)
} else
CLR(strp->flags, STR_PROC_SETEUID|STR_PROC_SETEGID);
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
error = (*callp->sy_call)(p, v, retval);
@@ -875,7 +875,7 @@ systrace_redirect(int code, struct proc *p, void *v, register_t *retval)
/* Acquire lock */
fst = strp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
if (p->p_emul != oldemul) {
@@ -907,7 +907,7 @@ systrace_redirect(int code, struct proc *p, void *v, register_t *retval)
}
out_unlock:
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
out:
return (error);
}
@@ -1320,7 +1320,7 @@ systrace_execve1(char *path, struct proc *p)
msg_execve = &strp->msg.msg_data.msg_execve;
fst = strp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
/*
@@ -1331,7 +1331,7 @@ systrace_execve1(char *path, struct proc *p)
if (fst->issuser ||
fst->p_ruid != p->p_cred->p_ruid ||
fst->p_rgid != p->p_cred->p_rgid) {
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
return;
}
strlcpy(msg_execve->path, path, MAXPATHLEN);
@@ -1474,7 +1474,7 @@ systrace_scriptname(struct proc *p, char *dst)
strp = p->p_systrace;
fst = strp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
if (!fst->issuser && (ISSET(p->p_flag, P_SUGID) ||
@@ -1497,7 +1497,7 @@ systrace_scriptname(struct proc *p, char *dst)
out:
strp->scriptname[0] = '\0';
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
return (error);
}
@@ -1515,7 +1515,7 @@ systrace_namei(struct nameidata *ndp)
strp = cnp->cn_proc->p_systrace;
if (strp != NULL) {
fst = strp->parent;
- lockmgr(&fst->lock, LK_EXCLUSIVE, NULL);
+ rw_enter_write(&fst->lock);
systrace_unlock();
for (i = 0; i < strp->nfname; i++)
@@ -1528,7 +1528,7 @@ systrace_namei(struct nameidata *ndp)
strcmp(cnp->cn_pnbuf, strp->scriptname) == 0)
hamper = 1;
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
} else
systrace_unlock();
@@ -1770,7 +1770,7 @@ systrace_make_msg(struct str_process *strp, int type)
systrace_wakeup(fst);
/* Release the lock - XXX */
- lockmgr(&fst->lock, LK_RELEASE, NULL);
+ rw_exit_write(&fst->lock);
while (1) {
st = tsleep(strp, pri, "systrmsg", 0);
diff --git a/sys/dev/systrace.h b/sys/dev/systrace.h
index 7b063e9fa9e..741ee0106c9 100644
--- a/sys/dev/systrace.h
+++ b/sys/dev/systrace.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: systrace.h,v 1.18 2004/11/07 20:39:31 marius Exp $ */
+/* $OpenBSD: systrace.h,v 1.19 2006/05/23 22:28:22 alek Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -33,6 +33,7 @@
#define _SYSTRACE_H_
#include <sys/ioccom.h>
+#include <sys/rwlock.h>
#define SYSTR_EMULEN 8 /* sync with sys proc */
@@ -192,7 +193,7 @@ struct systrace_inject {
struct str_process;
struct fsystrace {
- struct lock lock;
+ struct rwlock lock;
struct selinfo si;
TAILQ_HEAD(strprocessq, str_process) processes;