Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOvPU-0007i3-Ay for pgsql-bugs@postgresql.org; Thu, 18 Oct 2012 19:05:36 +0000 Received: from placid2.grammatech.com ([209.150.224.73] helo=placid.grammatech.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOvPN-0006Jd-Gl for pgsql-bugs@postgresql.org; Thu, 18 Oct 2012 19:05:35 +0000 Received: from placid.grammatech.com (localhost [127.0.0.1]) by placid.grammatech.com (Postfix) with ESMTP id EDFD021E1E1; Thu, 18 Oct 2012 15:05:26 -0400 (EDT) Received: from [10.233.219.191] (firewall.grammatech.com [209.150.224.67]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by placid.grammatech.com (Postfix) with ESMTPSA id E0D6221E1E0; Thu, 18 Oct 2012 15:05:26 -0400 (EDT) Message-ID: <508052F6.20803@grammatech.com> Date: Thu, 18 Oct 2012 15:05:26 -0400 From: Dave Vitek User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121005 Thunderbird/16.0 MIME-Version: 1.0 To: Heikki Linnakangas CC: Tom Lane , Pg Bugs Subject: Re: Fwd: race in pg_ctl start -w References: <5076F626.2090404@grammatech.com> <5076FF23.6020704@iki.fi> <22107.1349976592@sss.pgh.pa.us> <50771713.8000908@vmware.com> <25454.1349984162@sss.pgh.pa.us> <507BC402.40807@vmware.com> In-Reply-To: <507BC402.40807@vmware.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AV-Checked: ClamAV using ClamSMTP X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201210/183 X-Sequence-Number: 34483 On 10/15/2012 4:06 AM, Heikki Linnakangas wrote: > On 11.10.2012 22:36, Tom Lane wrote: >> Heikki Linnakangas writes: >>> Hmm, starting with 9.3, postmaster can not only create and append to >>> the >>> end of file, it can also inject a line in the middle, shifting the >>> following lines forwards. In theory, if a new line is injected into the >>> middle of the file between fgets() calls, readfile() could read part of >>> the same line twice. Not sure what consequences that could have; pg_ctl >>> might try to connect to wrong address or socket directory. >> >> Hm. IIRC, the postmaster is careful to write the whole thing in a >> single write() call, which in principle is atomic. Perhaps you're >> right that we'd better have pg_ctl read it in a single read() to >> ensure that it sees a consistent file state. Otherwise we're making >> assumptions about what sort of buffering underlies the stdio functions. > > Ok, changed it to slurp the whole file to memory with one read() call. > > Dave, did this silence the static analysis tool you used? > > - Heikki Heikki, It's happy about the overruns. It did flag an issue where the file descriptor can leak when the various early returns get taken. - Dave