Date: 08 Jul 2000 12:31:06 +0200 From: Dag-Erling Smorgrav <des@flood.ping.uio.no> To: Kirk McKusick <mckusick@FreeBSD.org> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, eivind@yes.no, sthaug@nethelp.no Subject: Re: cvs commit: src/sys/dev/ccd ccd.c src/sys/dev/vn vn.c src/sys/kern kern_acct.c kern_ktrace.c kern_linker.c kern_sig.c link_aout.c link_elf.c vfs_syscalls.c vfs_vnops.c src/sys/sys vnode.h src/sys/ufs/ufs ufs_extattr.c ufs_quota.c Message-ID: <xzpbt08ud5h.fsf@flood.ping.uio.no> In-Reply-To: Kirk McKusick's message of "Mon, 3 Jul 2000 20:34:11 -0700 (PDT)" References: <200007040334.UAA00954@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Kirk McKusick <mckusick@FreeBSD.org> writes: > Log: > 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. Does this also fix the race condition where two processes doing open(fn, O_RDWR|O_CREAT|O_TRUNC|O_EXLOCK, mode) can end up with one file each instead of one blocking the other? This has caused me some grief in the following scenario: fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC|O_EXLOCK, 0600); for (i = 0; i < bignum; ++i) write(fd, stuff[i], strlen(stuff[i])); rename(tmpfile, realfile); close(fd); If two processes are doing this at the same time, the first one's tmpfile is replaced by the second one's tmpfile, so that when the first process finishes writing and renames tmpfile to realfile, the second process' tmpfile goes live before it's done writing. If realfile is e.g. /var/qmail/control/rcpthosts on a mail server with lots of virtual domains, this opens a short window during which qmail will refuse mail for some domains. DES -- Dag-Erling Smorgrav - des@flood.ping.uio.no To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpbt08ud5h.fsf>