From e6796b67d904cd5e64c1befaa6eb3200bb695a20 Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Tue, 4 Jul 2000 03:34:11 +0000 Subject: Move the truncation code out of vn_open and into the open system call after the acquisition of any advisory locks. This fix corrects a case in which a process tries to open a file with a non-blocking exclusive lock. Even if it fails to get the lock it would still truncate the file even though its open failed. With this change, the truncation is done only after the lock is successfully acquired. Obtained from: BSD/OS --- sys/dev/ccd/ccd.c | 5 +++-- sys/dev/vn/vn.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/ccd/ccd.c b/sys/dev/ccd/ccd.c index 3f62c1ad51388..5a478f71abec2 100644 --- a/sys/dev/ccd/ccd.c +++ b/sys/dev/ccd/ccd.c @@ -1538,10 +1538,11 @@ ccdlookup(path, p, vpp) { struct nameidata nd; struct vnode *vp; - int error; + int error, flags; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p); - if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) { + flags = FREAD | FWRITE; + if ((error = vn_open(&nd, &flags, 0)) != 0) { #ifdef DEBUG if (ccddebug & CCDB_FOLLOW|CCDB_INIT) printf("ccdlookup: vn_open error = %d\n", error); diff --git a/sys/dev/vn/vn.c b/sys/dev/vn/vn.c index 29f4e7a544534..88e3801fdd95b 100644 --- a/sys/dev/vn/vn.c +++ b/sys/dev/vn/vn.c @@ -539,13 +539,13 @@ vniocattach_file(vn, vio, dev, flag, p) flags = FREAD|FWRITE; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, vio->vn_file, p); - error = vn_open(&nd, flags, 0); + error = vn_open(&nd, &flags, 0); if (error) { if (error != EACCES && error != EPERM && error != EROFS) return (error); flags &= ~FWRITE; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, vio->vn_file, p); - error = vn_open(&nd, flags, 0); + error = vn_open(&nd, &flags, 0); if (error) return (error); } -- cgit v1.3