summaryrefslogtreecommitdiff
path: root/sys/kern/vfs_lockf.c
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2008-09-19 12:24:56 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2008-09-19 12:24:56 +0000
commit86cbc85c96d6879d731f496960e2c88140ba9456 (patch)
treebb936283e7310573f1785de74e61d1899d2f375e /sys/kern/vfs_lockf.c
parent50fd91d29c98be39101df26bdc20cf29a7a93da8 (diff)
Fix a bunch of problems and races with posix file locking.
- file descriptor table becomes the owner of the lock instead of the proc. - When grabbing the lock, we check if the fd hasn't changed under our feet, this is more or less impossible to solve without a hack like this. I've banged my head against the wall, I figured out a solution, but implementing it correctly would cost me 12 gray hairs. Screw it, this is ugly, but it works. - Wait until usecount drains before releasing the posix lock in closef. - Add missing FREF/FRELE to sys_flock - keep the pid in the flock struct instead of abusing the fact that we used to use the proc as the lock owner. Pointed out by and discussed with Al Viro, big thanks. miod@ ok
Diffstat (limited to 'sys/kern/vfs_lockf.c')
-rw-r--r--sys/kern/vfs_lockf.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/sys/kern/vfs_lockf.c b/sys/kern/vfs_lockf.c
index f628c6a1608..9afa0c0a367 100644
--- a/sys/kern/vfs_lockf.c
+++ b/sys/kern/vfs_lockf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_lockf.c,v 1.12 2005/11/20 21:55:15 pedro Exp $ */
+/* $OpenBSD: vfs_lockf.c,v 1.13 2008/09/19 12:24:55 art Exp $ */
/* $NetBSD: vfs_lockf.c,v 1.7 1996/02/04 02:18:21 christos Exp $ */
/*
@@ -192,6 +192,7 @@ lf_advlock(struct lockf **head, off_t size, caddr_t id, int op,
lock->lf_next = NULL;
TAILQ_INIT(&lock->lf_blkhd);
lock->lf_flags = flags;
+ lock->lf_pid = (flags & F_POSIX) ? curproc->p_pid : -1;
/*
* Do the requested operation.
*/
@@ -544,10 +545,7 @@ lf_getlock(struct lockf *lock, struct flock *fl)
fl->l_len = 0;
else
fl->l_len = block->lf_end - block->lf_start + 1;
- if (block->lf_flags & F_POSIX)
- fl->l_pid = ((struct proc *)(block->lf_id))->p_pid;
- else
- fl->l_pid = -1;
+ fl->l_pid = block->lf_pid;
} else {
fl->l_type = F_UNLCK;
}