From owner-freebsd-stable@FreeBSD.ORG Wed Nov 26 19:44:47 2003 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 50AD616A4CE for ; Wed, 26 Nov 2003 19:44:47 -0800 (PST) Received: from zardoc.esmtp.org (adsl-63-195-85-27.dsl.snfc21.pacbell.net [63.195.85.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2F7F443F85 for ; Wed, 26 Nov 2003 19:44:46 -0800 (PST) (envelope-from ca+envelope@esmtp.org) Received: from zardoc.esmtp.org ([127.0.0.1]) by zardoc.esmtp.org (sendmail 9.0.0.PreAlpha9) with ESMTP id S000000003FA45F2E01; Wed, 26 Nov 2003 19:45:54 -0800 Received: (from ca@localhost)hAR3jsDn028474; Wed, 26 Nov 2003 19:45:54 -0800 (PST) Date: Wed, 26 Nov 2003 19:45:54 -0800 From: Claus Assmann To: freebsd-stable@freebsd.org Message-ID: <20031127034554.GA19264@zardoc.esmtp.org> Mail-Followup-To: freebsd-stable@freebsd.org References: <004f01c3b427$eaea8c70$41c3c3cf@office.sihope.com> <008601c3b455$379b72a0$41c3c3cf@office.sihope.com> <00a401c3b46a$78cd7650$41c3c3cf@office.sihope.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <00a401c3b46a$78cd7650$41c3c3cf@office.sihope.com> User-Agent: Mutt/1.5.4i Subject: Re: NFS/Sendmail issue since upgrading to 4.9-STABLE X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Nov 2003 03:44:47 -0000 On Wed, Nov 26, 2003, Adam Maloney wrote: > This custom application reads a directory list and for each qf file, > attempts a LOCK_EX. For the past 2 years this has appeared to work fine > with Sendmail - if Sendmail is still working on the qf file, we aren't able > to get an exclusive lock, so we go on to the next file, etc. (Maybe Claus > can confirm some of this behavior?) > > It appears that Sendmail changed from 8.12.9 (FreeBSD 4.8R) to 8.12.10 > (FreeBSD 4.9-STA). What we believe is happening is that the qf file is > being created, and our application is getting the exclusive lock before > Sendmail. This makes Sendmail spit out the "resource temporarily > unavailable" error, since it can't lock the file, and it leaves our > application with an empty qf file that we are trying to process. Yes, there's a race condition. 8.12.10 changed the behavior to avoid overwriting an existing qf file: Better error handling in case of (very unlikely) queue-id conflicts. tfd = open(tf, O_CREAT|O_WRONLY|O_EXCL, FileMode); if (tfd < 0 || !lockfile(tfd, tf, NULL, LOCK_EX|LOCK_NB) || (tfp = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT, So if your application accesses the qf file between open() and lockfile() sendmail will complain and exit() without trying again. Older versions would try again and eventually overwrite the file... Fix 1: don't mess with qf files. Fix 2: check the size before accessing a qf file: don't touch (open/lock) empty files.