Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Make flock(2) more robust to invalid operation, such as
details: https://anonhg.NetBSD.org/src/rev/d080f933e9b6
branches: trunk
changeset: 748593:d080f933e9b6
user: njoly <njoly%NetBSD.org@localhost>
date: Wed Oct 28 18:24:44 2009 +0000
description:
Make flock(2) more robust to invalid operation, such as
(LOCK_EX|LOCK_SH).
diffstat:
lib/libc/sys/flock.2 | 6 +++---
sys/kern/sys_descrip.c | 18 +++++++++++-------
2 files changed, 14 insertions(+), 10 deletions(-)
diffs (76 lines):
diff -r a4f852cecf88 -r d080f933e9b6 lib/libc/sys/flock.2
--- a/lib/libc/sys/flock.2 Wed Oct 28 18:20:41 2009 +0000
+++ b/lib/libc/sys/flock.2 Wed Oct 28 18:24:44 2009 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: flock.2,v 1.19 2004/05/13 10:20:58 wiz Exp $
+.\" $NetBSD: flock.2,v 1.20 2009/10/28 18:24:44 njoly Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)flock.2 8.2 (Berkeley) 12/11/93
.\"
-.Dd December 11, 1993
+.Dd October 26, 2009
.Dt FLOCK 2
.Os
.Sh NAME
@@ -136,7 +136,7 @@
.It Bq Er EINVAL
The argument
.Fa operation
-does not include one of
+does not include exactly one of
.Dv LOCK_EX ,
.Dv LOCK_SH
or
diff -r a4f852cecf88 -r d080f933e9b6 sys/kern/sys_descrip.c
--- a/sys/kern/sys_descrip.c Wed Oct 28 18:20:41 2009 +0000
+++ b/sys/kern/sys_descrip.c Wed Oct 28 18:24:44 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_descrip.c,v 1.16 2009/06/10 23:48:10 yamt Exp $ */
+/* $NetBSD: sys_descrip.c,v 1.17 2009/10/28 18:24:44 njoly Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.16 2009/06/10 23:48:10 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.17 2009/10/28 18:24:44 njoly Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -585,21 +585,25 @@
lf.l_whence = SEEK_SET;
lf.l_start = 0;
lf.l_len = 0;
- if (how & LOCK_UN) {
+
+ switch (how & ~LOCK_NB) {
+ case LOCK_UN:
lf.l_type = F_UNLCK;
atomic_and_uint(&fp->f_flag, ~FHASLOCK);
error = VOP_ADVLOCK(vp, fp, F_UNLCK, &lf, F_FLOCK);
fd_putfile(fd);
return error;
- }
- if (how & LOCK_EX) {
+ case LOCK_EX:
lf.l_type = F_WRLCK;
- } else if (how & LOCK_SH) {
+ break;
+ case LOCK_SH:
lf.l_type = F_RDLCK;
- } else {
+ break;
+ default:
fd_putfile(fd);
return EINVAL;
}
+
atomic_or_uint(&fp->f_flag, FHASLOCK);
p = curproc;
if (how & LOCK_NB) {
Home |
Main Index |
Thread Index |
Old Index