From owner-freebsd-questions@freebsd.org Wed Jun 16 07:39:29 2021 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A55F965C8A6 for ; Wed, 16 Jun 2021 07:39:29 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id 4G4cX062brz4qkd for ; Wed, 16 Jun 2021 07:39:28 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: by segfault.tristatelogic.com (Postfix, from userid 1237) id B1F814E680; Wed, 16 Jun 2021 00:39:27 -0700 (PDT) From: "Ronald F. Guilmette" To: freebsd-questions@freebsd.org Subject: Re: Is a successful call to write(2) atomic? In-Reply-To: <20210616072633.e4bd29839249465e385bbf6f@sohara.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27899.1623829167.1@segfault.tristatelogic.com> Date: Wed, 16 Jun 2021 00:39:27 -0700 Message-ID: <27900.1623829167@segfault.tristatelogic.com> X-Rspamd-Queue-Id: 4G4cX062brz4qkd X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of rfg@tristatelogic.com designates 69.62.255.118 as permitted sender) smtp.mailfrom=rfg@tristatelogic.com X-Spamd-Result: default: False [-0.29 / 15.00]; ARC_NA(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[69.62.255.118:from]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DMARC_NA(0.00)[tristatelogic.com]; NEURAL_SPAM_MEDIUM(1.00)[1.000]; RCPT_COUNT_ONE(0.00)[1]; SPAMHAUS_ZRD(0.00)[69.62.255.118:from:127.0.2.255]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.99)[-0.988]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:14051, ipnet:69.62.128.0/17, country:US]; SUBJECT_ENDS_QUESTION(1.00)[]; MAILMAN_DEST(0.00)[freebsd-questions] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jun 2021 07:39:29 -0000 In message <20210616072633.e4bd29839249465e385bbf6f@sohara.org>, Steve O'Hara-Smith wrote: > IOW if one process writes ABC and another writes DEF both at the >end of file you might get ABCDEF but you won't get ABDCEF you might also get >ABDEF as D overwrites C... Yup. Some of the "garbled" lines I have been getting look suspiciously like the "ABDEF" in your example. > John's code will work (it is the standard solution) - provided >*every* writer uses it - without the O_APPEND you would need to put a seek >to EOF inside the locked section which is the pattern I most often wind up >with. So the O_APPEND by itself isn't enough to fix the problem? I still have to wrap the calls to write() inside some sort of locking code? I'll try both... O_APPEND, with and without locking... but it kind of seems to me that if O_APPEND, by itself, were actually doing what the man page says it does, then that alone ought to be enough to prevent garbling of the output lines. Regards, rfg