Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Jun 2021 00:39:27 -0700
From:      "Ronald F. Guilmette" <rfg@tristatelogic.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Is a successful call to write(2) atomic?
Message-ID:  <27900.1623829167@segfault.tristatelogic.com>
In-Reply-To: <20210616072633.e4bd29839249465e385bbf6f@sohara.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20210616072633.e4bd29839249465e385bbf6f@sohara.org>, 
Steve O'Hara-Smith <steve@sohara.org> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?27900.1623829167>